Cohere on Oracle Cloud Infrastructure (OCI)
Cohere on Oracle Cloud Infrastructure (OCI)
Cohere on Oracle Cloud Infrastructure (OCI)
The Cohere Python SDK natively supports Oracle Cloud Infrastructure (OCI) Generative AI service. With pip install cohere[oci], you get OciClient and OciClientV2 classes that behave identically to the Cohere-hosted Client and ClientV2 — same methods, same response types, same streaming format. Switching from Cohere’s hosted API to OCI Generative AI means changing one constructor.
Under the hood, the SDK handles URL rewriting, request and response format translation, OCI cryptographic request signing, and streaming event transformation. Your application code never sees the OCI-specific details.
The SDK supports all Cohere models available on OCI Generative AI, including the Command A family (via OciClientV2), the Command R family (via OciClient), Embed models, and Rerank models. For the current list of available models and their IDs, see the OCI Generative AI pretrained models documentation.
This installs the Cohere SDK along with the OCI SDK dependency required for authentication and request signing.
The SDK transforms OCI’s streaming format to match Cohere’s standard streaming events. V2 uses message-start, content-delta, content-end, message-end; V1 uses stream-start, text-generation, stream-end.
The SDK supports five authentication methods, covering every deployment scenario from local development to serverless production.
Uses ~/.oci/config with the DEFAULT profile. No additional parameters needed beyond region and compartment.
Use a specific profile from your OCI config file.
Works with OCI CLI session tokens. The SDK automatically re-reads the token file on each request, so oci session refresh is picked up without restarting the client.
Pass OCI credentials directly without a config file. Useful for CI/CD pipelines or containerized deployments.
For applications running on OCI Compute instances. No credentials needed — the instance’s identity is used automatically.
For OCI Functions (serverless). Zero credentials in the deployment — the function inherits the compartment’s security posture.
The SDK provides two client classes that map to the two OCI Generative AI API formats:
Command A supports native tool use on OCI Generative AI. Define tools and the model will return tool_calls with structured arguments.
Command A Vision can reason over images alongside text. Pass images as base64 data URIs or URLs in the message content.
Embed v4 is Cohere’s latest embedding model with 1536 dimensions, available alongside the Embed v3 family.
The following example demonstrates a complete application flow on OCI Generative AI: embedding documents for a knowledge base, retrieving relevant context, using tool calling for live data, processing images with vision, and streaming a final response.
You can also work with Cohere models on OCI through the OCI Console, the OCI CLI, or the OCI API directly.