
To verify that your Oracle Cloud Infrastructure (OCI) environment is correctly configured to use Generative AI services, it is essential to test API access, model permissions, and request formatting. The Python snippet below provides a minimal working example that sends a prompt to the cohere.command-text-v14 model using Oracle’s generateText endpoint. This test isolates the most common failure points—such as invalid compartment access, unsupported models, or malformed requests—and allows you to confirm that your OCI SDK and credentials are functioning correctly. If the script returns a generated response, you can integrate LLM capabilities into your applications. If it returns a 400 error, you will know it is time to check access permissions or request model enablement through Oracle Support.
import oci
from oci.generative_ai_inference import GenerativeAiInferenceClient
from oci.generative_ai_inference.models import GenerateTextDetails, OnDemandServingMode
# Load your default OCI config (ensure ~/.oci/config is set up)
config = oci.config.from_file()
# Initialize client
client = GenerativeAiInferenceClient(config)
# Replace this with your valid compartment OCID
compartment_id = "<YOUR_COMPARTMENT_OCID>" # <-- REQUIRED
# Model ID: Must be one your tenancy has access to
model_id = "cohere.command-text-v14"
# Prompt to test
prompt = "Summarize the importance of data privacy in cybersecurity."
# Create the request payload
details = GenerateTextDetails(
compartment_id=compartment_id,
serving_mode=OnDemandServingMode(
serving_type="ON_DEMAND",
model_id=model_id
),
inference_request={
"input": prompt # Correct format for cohere.command-text-v14
}
)
# Make the request and print the response
try:
result = client.generate_text(generate_text_details=details)
print("Generated text:")
print(result.generated_text)
except Exception as e:
print(" Oracle LLM Error:")
print(e)
How to use:
- Replace
"<YOUR_COMPARTMENT_OCID>"with your actual Compartment OCID string. - Save the script as
oracle_llm_test.py. - Run from terminal:
python oracle_llm_test.py


*The views expressed here are my own and do not represent those of my employer.*
Hello, I’m Bruno — a dual citizen of Brazil and Sweden. I bring a global perspective shaped by experiences in both South America and Europe, with a strong focus on collaboration and innovation across cultures. I am a Computer Scientist, PhD Candidate in Information and Communication Technologies, focusing on Data Science and Artificial Intelligence, and hold dual Master’s degrees in Data Science and Cybersecurity. With over fifteen years of international experience spanning Brazil, Hungary, and Sweden, I have collaborated with global organizations such as IBM, Playtech, and Oracle, as well as contributed remotely to projects across multiple regions. My professional interests include Databases, Cybersecurity, Cloud Computing, Data Science, Data Engineering, Big Data, Artificial Intelligence, Programming, and Software Engineering, all driven by a deep passion for transforming data into strategic business value.