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 Oracle Cloud Infrastructure (OCI) Generative AI client support (#718)
* feat: Add Oracle Cloud Infrastructure (OCI) Generative AI client support
Adds OciClient (V1 API) and OciClientV2 (V2 API) for the OCI Generative
AI service, following the BedrockClient pattern with httpx event hooks.
Authentication: config file, custom profiles, session tokens, direct
credentials, instance principal, resource principal.
API coverage: embed (all models), chat with streaming (OciClient for
Command R family, OciClientV2 for Command A). Lazy-loads oci SDK as an
optional dependency; install with `pip install cohere[oci]`.
* fix: address review feedback — remove stale model names and fix test profile
- README: remove specific model names from Supported APIs and Model
Availability sections (per mkozakov review — will go out of date)
- tests: default OCI_PROFILE to DEFAULT instead of API_KEY_AUTH
* fix: remove dead chat_stream endpoint and body-based stream detection
The "stream" in endpoint check was dead code — both V1 and V2 SDK always
route through endpoint "chat" (v1/chat and v2/chat paths). Streaming is
reliably signalled via body["stream"], which the SDK always sets.
- Drop "stream" in endpoint guard on is_stream and isStream detection
- Remove "chat_stream" from action_map, transform, and response branches
- Update unit tests to use "chat" endpoint (the only real one)
* fix: don't trigger content-type transition on finish-only stream events
_current_content_type now returns None for events with no message content
(e.g. {"finishReason": "COMPLETE"}). The transition branch in
_transform_v2_event is skipped when event_content_type is None, so a
finish-only event after a thinking block no longer opens a spurious empty
text block before emitting content-end.
* test: add integration tests for light models, command-r-plus, multi-turn, and system message
* fix: use 'or []' to guard against explicit content=None in V2 messages
* Address cursor review: raise on unsupported endpoint, refresh session token per-request
- transform_request_to_oci now raises ValueError for endpoints other than
'embed' and 'chat' instead of silently returning the untransformed body
- Session token auth uses a refreshing wrapper that re-reads the token file
before each signing call, so OCI CLI token refreshes are picked up without
restarting the client
- Add test_unsupported_endpoint_raises to cover the new explicit error
- Update test_session_auth_prefers_security_token_signer to expect multi-call
behaviour from the refreshing signer
* Add test proving session token is re-read on subsequent requests
test_session_token_refreshed_on_subsequent_requests writes a real token file,
makes two requests with the file updated between them, and asserts that the
second signing call uses the new token — verifying the refreshing signer works
end-to-end.
oci_profile="MY_SESSION_PROFILE", # Profile with security_token_file
114
+
oci_region="us-chicago-1",
115
+
oci_compartment_id="ocid1.compartment.oc1...",
116
+
)
117
+
```
118
+
119
+
**4. Direct Credentials**
120
+
```Python
121
+
co = cohere.OciClient(
122
+
oci_user_id="ocid1.user.oc1...",
123
+
oci_fingerprint="xx:xx:xx:...",
124
+
oci_tenancy_id="ocid1.tenancy.oc1...",
125
+
oci_private_key_path="~/.oci/key.pem",
126
+
oci_region="us-chicago-1",
127
+
oci_compartment_id="ocid1.compartment.oc1...",
128
+
)
129
+
```
130
+
131
+
**5. Instance Principal (for OCI Compute instances)**
132
+
```Python
133
+
co = cohere.OciClient(
134
+
auth_type="instance_principal",
135
+
oci_region="us-chicago-1",
136
+
oci_compartment_id="ocid1.compartment.oc1...",
137
+
)
138
+
```
139
+
140
+
### Supported OCI APIs
141
+
142
+
The OCI client supports the following Cohere APIs:
143
+
-**Embed**: Full support for all embedding models
144
+
-**Chat**: Full support with both V1 (`OciClient`) and V2 (`OciClientV2`) APIs
145
+
- Streaming available via `chat_stream()`
146
+
- Supports Command-R and Command-A model families
147
+
148
+
### OCI Model Availability and Limitations
149
+
150
+
**Available on OCI On-Demand Inference:**
151
+
- ✅ **Embed models**: available on OCI Generative AI
152
+
- ✅ **Chat models**: available via `OciClient` (V1) and `OciClientV2` (V2)
153
+
154
+
**Not Available on OCI On-Demand Inference:**
155
+
- ❌ **Generate API**: OCI TEXT_GENERATION models are base models that require fine-tuning before deployment
156
+
- ❌ **Rerank API**: OCI TEXT_RERANK models are base models that require fine-tuning before deployment
157
+
- ❌ **Multiple Embedding Types**: OCI on-demand models only support single embedding type per request (cannot request both `float` and `int8` simultaneously)
158
+
159
+
**Note**: To use Generate or Rerank models on OCI, you need to:
160
+
1. Fine-tune the base model using OCI's fine-tuning service
161
+
2. Deploy the fine-tuned model to a dedicated endpoint
162
+
3. Update your code to use the deployed model endpoint
163
+
164
+
For the latest model availability, see the [OCI Generative AI documentation](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm).
165
+
61
166
## Contributing
62
167
63
168
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