feat: Add Oracle Cloud Infrastructure (OCI) Generative AI client support - #718
Conversation
0e341c1 to
fdebc00
Compare
a284ea8 to
d7c7ef6
Compare
|
@walterbm-cohere @daniel-cohere @billytrend-cohere Hey maintainers, Friendly bump on this PR - would appreciate your feedback when you have a chance. Happy to address any concerns or make changes as needed. Thanks. |
49f92cc to
8b9c63d
Compare
|
Addressed Bugbot feedback:
|
3bf4c54 to
b78c63e
Compare
|
@sanderland Thanks for the approvals on this PR and the others (#717, #698, #697)! What are the next steps to get these merged? |
|
@sanderland quick ping on this one since you approved earlier - could you please take a final look when you have a moment? Thanks! |
1119be8 to
12938af
Compare
fb5c414 to
b3fcdee
Compare
|
@billytrend-cohere @walterbm-cohere @daniel-cohere @sanderland This PR is the canonical Oracle proposal for OCI support in What is in scope on this branch:
Current verification on this branch:
Please treat |
Final test run — 47/47 passedAll tests passing against the live OCI GenAI inference layer ( V1 (OciClient) — Command R family, COHERE apiFormat
V2 (OciClientV2) — Command A family, COHEREV2 apiFormat
Validation tests
Fern safety
|
|
@mkozakov Quick summary of where everything stands — all work is done and tested on our side. 3 PRs, all ready for review:
All code is Fern-safe — zero auto-generated files modified across any of these PRs. Let me know if anything needs adjustment. |
|
Hey @fede-kamel finally had a chance to review. In general this looks good, but not sure why this PR touches the AWS client / removes tests? |
d48cca4 to
d520316
Compare
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]`.
…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
a6a996d to
636e76e
Compare
|
Hey @mkozakov — yes, all addressed! Here's the summary: AWS client / removed tests: Good catch. An earlier iteration of this branch touched the AWS client and removed the AWS unit tests as a side effect. That's all been fully reverted — All 3 inline comments from your review are addressed:
Branch has been squashed to 2 clean commits:
Tests: 47/47 passing against live OCI GenAI ( |
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)
_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.
…urn, and system message
… 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
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.
Confirmed from the OCI side — just tested both V1 and V2 responses against the live OCI GenAI inference service: V2 (Command A, V1 (Command R, So the synthetic |
#712) Add OCI client exports so they survive Fern regeneration of __init__.py. Follows the same pattern as BedrockClient/SagemakerClient. Related: cohere-ai/cohere-python#718

Overview
I noticed that the Cohere Python SDK has excellent integration with AWS Bedrock through the
BedrockClientimplementation. I wanted to contribute a similar integration for Oracle Cloud Infrastructure (OCI) Generative AI service to provide our customers with the same seamless experience.Motivation
Oracle Cloud Infrastructure offers Cohere's models through our Generative AI service, and many of our enterprise customers use both platforms. This integration follows the same architectural pattern as the existing Bedrock client, ensuring consistency and maintainability.
Implementation
This PR adds comprehensive OCI support with:
Features
~/.oci/config)Architecture
Testing
Documentation
Files Changed
src/cohere/oci_client.py(910 lines) - Main OCI client implementationsrc/cohere/manually_maintained/lazy_oci_deps.py(30 lines) - Lazy OCI SDK loadingtests/test_oci_client.py(393 lines) - Comprehensive integration testsREADME.md- OCI usage documentationpyproject.toml- Optional OCI dependencysrc/cohere/__init__.py- Export OciClient and OciClientV2Test Results
Skipped tests are for OCI service limitations (base models not callable via on-demand inference).
Breaking Changes
None. This is a purely additive feature.
Checklist
Note
Medium Risk
Adds a large new OCI integration layer that rewrites and signs outbound requests and transforms streaming/non-streaming responses, which could introduce subtle compatibility or parsing bugs despite being additive.
Overview
Adds first-class Oracle Cloud Infrastructure support via new
OciClient(v1) andOciClientV2(v2) that route Cohereembed/chat(+chat_stream) calls through OCI’s Generative AI inference endpoints using httpx event hooks.Implements OCI auth and request signing (config-file profiles, direct credentials, instance/resource principals, and session-token refresh), plus bidirectional payload/stream event translation between Cohere and OCI formats (including model-name normalization and v2 content-block lifecycle handling).
Exposes the new clients from
cohere.__init__, adds optionalocidependency/extras inpyproject.toml, documents usage inREADME.md, and introduces a comprehensivetests/test_oci_client.pysuite covering auth, transformations, and live integration (gated by env vars).Reviewed by Cursor Bugbot for commit a06825a. Bugbot is set up for automated code reviews on this repo. Configure here.