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.
Available Models
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.
Installation
This installs the Cohere SDK along with the OCI SDK dependency required for authentication and request signing.
Quick Start
Chat with Command A (V2 API)
Chat with Command R (V1 API)
Embeddings
Streaming (V2)
Streaming (V1)
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.
Authentication
The SDK supports five authentication methods, covering every deployment scenario from local development to serverless production.
1. Config File (Default)
Uses ~/.oci/config with the DEFAULT profile. No additional parameters needed beyond region and compartment.
2. Custom Profile
Use a specific profile from your OCI config file.
3. Session-based Authentication
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.
4. Direct Credentials
Pass OCI credentials directly without a config file. Useful for CI/CD pipelines or containerized deployments.
5. Instance Principal
For applications running on OCI Compute instances. No credentials needed — the instance’s identity is used automatically.
6. Resource Principal
For OCI Functions (serverless). Zero credentials in the deployment — the function inherits the compartment’s security posture.
V1 vs V2 API
The SDK provides two client classes that map to the two OCI Generative AI API formats:
Tool Use (V2)
Command A supports native tool use on OCI Generative AI. Define tools and the model will return tool_calls with structured arguments.
Vision (V2)
Command A Vision can reason over images alongside text. Pass images as base64 data URIs or URLs in the message content.
Embed v4
Embed v4 is Cohere’s latest embedding model with 1536 dimensions, available alongside the Embed v3 family.
Supported Features
End-to-End Example
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.
Additional Resources
You can also work with Cohere models on OCI through the OCI Console, the OCI CLI, or the OCI API directly.