You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add comprehensive Oracle Cloud Infrastructure (OCI) client support
Implements full OCI Generative AI integration following the proven AWS client architecture pattern.
Features:
- OciClient (v1) and OciClientV2 (v2) for complete API coverage
- All authentication methods: config file, direct credentials, instance principal, resource principal
- Complete API support: embed, chat, generate, rerank (including streaming variants)
- Automatic model name normalization (adds 'cohere.' prefix if needed)
- Request/response transformation between Cohere and OCI formats
- Comprehensive integration tests with multiple test suites
- Full documentation with usage examples
Implementation Details:
- Uses httpx event hooks for clean request/response interception
- Lazy loading of OCI SDK as optional dependency
- Follows BedrockClient architecture pattern for consistency
- Supports all OCI regions and compartment-based access control
Testing:
- 40+ integration tests across 5 test suites
- Tests all authentication methods
- Validates all APIs (embed, chat, generate, rerank, streaming)
- Tests multiple Cohere models (embed-v3, light-v3, multilingual-v3, command-r-plus, rerank-v3)
- Error handling and edge case coverage
Documentation:
- Comprehensive docstrings with usage examples
- README section with authentication examples
- Installation instructions for OCI optional dependency
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,85 @@ for event in response:
58
58
print(event.delta.message.content.text, end="")
59
59
```
60
60
61
+
## Oracle Cloud Infrastructure (OCI)
62
+
63
+
The SDK supports Oracle Cloud Infrastructure (OCI) Generative AI service. First, install the OCI SDK:
64
+
65
+
```
66
+
pip install 'cohere[oci]'
67
+
```
68
+
69
+
Then use the `OciClient` or `OciClientV2`:
70
+
71
+
```Python
72
+
import cohere
73
+
74
+
# Using OCI config file authentication (default: ~/.oci/config)
75
+
co = cohere.OciClient(
76
+
oci_region="us-chicago-1",
77
+
oci_compartment_id="ocid1.compartment.oc1...",
78
+
)
79
+
80
+
response = co.embed(
81
+
model="embed-english-v3.0",
82
+
texts=["Hello world"],
83
+
input_type="search_document",
84
+
)
85
+
86
+
print(response.embeddings)
87
+
```
88
+
89
+
### OCI Authentication Methods
90
+
91
+
**1. Config File (Default)**
92
+
```Python
93
+
co = cohere.OciClient(
94
+
oci_region="us-chicago-1",
95
+
oci_compartment_id="ocid1.compartment.oc1...",
96
+
# Uses ~/.oci/config with DEFAULT profile
97
+
)
98
+
```
99
+
100
+
**2. Custom Profile**
101
+
```Python
102
+
co = cohere.OciClient(
103
+
oci_profile="MY_PROFILE",
104
+
oci_region="us-chicago-1",
105
+
oci_compartment_id="ocid1.compartment.oc1...",
106
+
)
107
+
```
108
+
109
+
**3. Direct Credentials**
110
+
```Python
111
+
co = cohere.OciClient(
112
+
oci_user_id="ocid1.user.oc1...",
113
+
oci_fingerprint="xx:xx:xx:...",
114
+
oci_tenancy_id="ocid1.tenancy.oc1...",
115
+
oci_private_key_path="~/.oci/key.pem",
116
+
oci_region="us-chicago-1",
117
+
oci_compartment_id="ocid1.compartment.oc1...",
118
+
)
119
+
```
120
+
121
+
**4. Instance Principal (for OCI Compute instances)**
122
+
```Python
123
+
co = cohere.OciClient(
124
+
auth_type="instance_principal",
125
+
oci_region="us-chicago-1",
126
+
oci_compartment_id="ocid1.compartment.oc1...",
127
+
)
128
+
```
129
+
130
+
### Supported OCI APIs
131
+
132
+
The OCI client supports all Cohere APIs:
133
+
- Embed (with multiple embedding types)
134
+
- Chat (with streaming via `chat_stream`)
135
+
- Generate (with streaming via `generate_stream`)
136
+
- Rerank
137
+
138
+
See the [OCI client documentation](https://docs.cohere.com/docs/cohere-works-everywhere) for more details.
139
+
61
140
## Contributing
62
141
63
142
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!
0 commit comments