Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a332cf8
SDK regeneration
fern-api[bot] Feb 23, 2024
4f5ec4e
feat: Add comprehensive Oracle Cloud Infrastructure (OCI) client support
fede-kamel Jan 26, 2026
ad2bad1
fix: Correct OCI client request signing and response transformation
fede-kamel Jan 26, 2026
d4ff382
feat: Add V2 API support for OCI with Command A models
fede-kamel Jan 26, 2026
8b9b9f9
style: Fix ruff linting issues in OCI client
fede-kamel Jan 26, 2026
fdebc00
chore: Remove temporary development summary files
fede-kamel Jan 26, 2026
aa991db
fix: Address OCI pip extras installation and streaming [DONE] signal …
fede-kamel Jan 26, 2026
56f734d
feat: Add OCI session-based (security token) authentication support
fede-kamel Jan 26, 2026
b94ffdf
docs: Add session-based authentication to OCI documentation
fede-kamel Jan 26, 2026
83e2375
fix: Replace httpx.Headers object instead of updating it for OCI sign…
fede-kamel Jan 26, 2026
d7c7ef6
Fix OCI client V2 support and address copilot issues
fede-kamel Jan 26, 2026
8a59c03
docs: Add OCI model availability limitations and improve docstrings
fede-kamel Jan 26, 2026
39cd175
fix: Address PR feedback - V2 detection and security token path expan…
fede-kamel Jan 26, 2026
3d680df
fix: Address PR feedback for OCI client
fede-kamel Jan 26, 2026
9168b77
feat: Add thinking parameter support for Command A Reasoning models
fede-kamel Feb 4, 2026
c60627f
Address cursor[bot] review feedback for OCI client
fede-kamel Feb 6, 2026
4ea9dd6
Fix token_budget casing and add toolCalls conversion
fede-kamel Feb 6, 2026
49f92cc
Merge branch 'main' into feat/oci-client
fede-kamel Feb 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,111 @@ for event in response:
print(event.delta.message.content.text, end="")
```

## Oracle Cloud Infrastructure (OCI)

The SDK supports Oracle Cloud Infrastructure (OCI) Generative AI service. First, install the OCI SDK:

```
pip install 'cohere[oci]'
```

Then use the `OciClient` or `OciClientV2`:

```Python
import cohere

# Using OCI config file authentication (default: ~/.oci/config)
co = cohere.OciClient(
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)

response = co.embed(
model="embed-english-v3.0",
texts=["Hello world"],
input_type="search_document",
)

print(response.embeddings)
```

### OCI Authentication Methods

**1. Config File (Default)**
```Python
co = cohere.OciClient(
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
# Uses ~/.oci/config with DEFAULT profile
)
```

**2. Custom Profile**
```Python
co = cohere.OciClient(
oci_profile="MY_PROFILE",
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)
```

**3. Session-based Authentication (Security Token)**
```Python
# Works with OCI CLI session tokens
co = cohere.OciClient(
oci_profile="MY_SESSION_PROFILE", # Profile with security_token_file
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)
```

**4. Direct Credentials**
```Python
co = cohere.OciClient(
oci_user_id="ocid1.user.oc1...",
oci_fingerprint="xx:xx:xx:...",
oci_tenancy_id="ocid1.tenancy.oc1...",
oci_private_key_path="~/.oci/key.pem",
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)
```

**5. Instance Principal (for OCI Compute instances)**
```Python
co = cohere.OciClient(
auth_type="instance_principal",
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)
```

### Supported OCI APIs

The OCI client supports the following Cohere APIs:
- **Embed**: Full support for all embedding models (embed-english-v3.0, embed-light-v3.0, embed-multilingual-v3.0)
- **Chat**: Full support with both V1 (`OciClient`) and V2 (`OciClientV2`) APIs
- Streaming available via `chat_stream()`
- Supports Command-R and Command-A model families

### OCI Model Availability and Limitations

**Available on OCI On-Demand Inference:**
- ✅ **Embed models**: embed-english-v3.0, embed-light-v3.0, embed-multilingual-v3.0
- ✅ **Chat models**: command-r-08-2024, command-r-plus, command-a-03-2025

**Not Available on OCI On-Demand Inference:**
- ❌ **Generate API**: OCI TEXT_GENERATION models are base models that require fine-tuning before deployment
- ❌ **Rerank API**: OCI TEXT_RERANK models are base models that require fine-tuning before deployment
- ❌ **Multiple Embedding Types**: OCI on-demand models only support single embedding type per request (cannot request both `float` and `int8` simultaneously)

**Note**: To use Generate or Rerank models on OCI, you need to:
1. Fine-tune the base model using OCI's fine-tuning service
2. Deploy the fine-tuned model to a dedicated endpoint
3. Update your code to use the deployed model endpoint

For the latest model availability, see the [OCI Generative AI documentation](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm).

## Contributing

While we value open-source contributions to this SDK, the code is generated programmatically. Additions made directly would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ requests = "^2.0.0"
tokenizers = ">=0.15,<1"
types-requests = "^2.0.0"
typing_extensions = ">= 4.0.0"
oci = { version = "^2.165.0", optional = true }

[tool.poetry.extras]
oci = ["oci"]

[tool.poetry.group.dev.dependencies]
mypy = "==1.13.0"
Expand Down
4 changes: 4 additions & 0 deletions src/cohere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@
"NotFoundError": ".errors",
"NotImplementedError": ".errors",
"OAuthAuthorizeResponse": ".types",
"OciClient": ".oci_client",
"OciClientV2": ".oci_client",
"ParseInfo": ".types",
"RerankDocument": ".types",
"RerankRequestDocumentsItem": ".types",
Expand Down Expand Up @@ -848,6 +850,8 @@ def __dir__():
"NotFoundError",
"NotImplementedError",
"OAuthAuthorizeResponse",
"OciClient",
"OciClientV2",
"ParseInfo",
"RerankDocument",
"RerankRequestDocumentsItem",
Expand Down
30 changes: 30 additions & 0 deletions src/cohere/manually_maintained/lazy_oci_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Lazy loading for optional OCI SDK dependency."""

from typing import Any

OCI_INSTALLATION_MESSAGE = """
The OCI SDK is required to use OciClient or OciClientV2.

Install it with:
pip install oci

Or with the optional dependency group:
pip install cohere[oci]
"""


def lazy_oci() -> Any:
"""
Lazily import the OCI SDK.

Returns:
The oci module

Raises:
ImportError: If the OCI SDK is not installed
"""
try:
import oci
return oci
except ImportError:
raise ImportError(OCI_INSTALLATION_MESSAGE)
Loading