Description
# Cohere Python SDK  [](https://pypi.org/project/cohere/)  [](https://github.com/fern-api/fern) The Cohere Python SDK allows access to Cohere models across many different platforms: the cohere platform, AWS (Bedrock, Sagemaker), Azure, GCP and Oracle OCI. For a full list of support and snippets, please take a look at the [SDK support docs page](https://docs.cohere.com/docs/cohere-works-everywhere). ## Documentation Cohere documentation and API reference is available [here](https://docs.cohere.com/). ## Installation ``` pip install cohere ``` ## Usage ```Python import cohere co = cohere.ClientV2() response = co.chat( model="command-r-plus-08-2024", messages=[{"role": "user", "content": "hello world!"}], ) print(response) ``` > [!TIP] > You can set a system environment variable `CO_API_KEY` to avoid writing your api key within your code, e.g. add `export CO_API_KEY=theapikeyforyouraccount` > in your ~/.zshrc or ~/.bashrc, open a new terminal, then code calling `cohere.Client()` will read this key. ## Streaming The SDK supports streaming endpoints. To take advantage of this feature for chat, use `chat_stream`. ```Python import cohere co = cohere.ClientV2() response = co.chat_stream( model="command-r-plus-08-2024", messages=[{"role": "user", "content": "hello world!"}], ) for event in response: if event.type == "content-delta": 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 - **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**: available on OCI Generative AI - ✅ **Chat models**: available via `OciClient` (V1) and `OciClientV2` (V2) **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 overwritte
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 6.1.0 | Imported from PyPI (6.1.0) | Low | 4/21/2026 |
| 6.0.0 | ## What's Changed * :herb: Fern Regeneration -- April 8, 2026 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/751 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.21.2...6.0.0 | Medium | 4/8/2026 |
| 5.21.2 | ## What's Changed * :herb: Fern Regeneration -- March 30, 2026 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/747 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.21.1...5.21.2 | Medium | 3/31/2026 |
| 5.21.1 | Release 5.21.1 | Medium | 3/26/2026 |
| 5.21.0 | Adds Audio Transcriptions endpoint to the SDK | Medium | 3/26/2026 |
| 5.20.7 | ## What's Changed * :herb: Fern Regeneration -- February 25, 2026 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/731 * Fix "[Done]" SSE terminator causing nuisance "Failed to parse SSE data" warning logs **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.6...5.20.7 | Low | 2/25/2026 |
| 5.20.6 | ## What's Changed * fix: resolve AWS client SigV4 signing, forced SageMaker dep, and missing embed params by @fern-support in https://github.com/cohere-ai/cohere-python/pull/728 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.5...5.20.6 | Low | 2/18/2026 |
| 5.20.5 | ## What's Changed * Fix generate_stream error in ClientV2 by @fern-support in https://github.com/cohere-ai/cohere-python/pull/725 * :herb: Fern Regeneration -- February 11, 2026 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/727 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.4...5.20.5 | Low | 2/11/2026 |
| 5.20.4 | ## What's Changed * fix: resync toml ver with release ver by @jasonozuzu-cohere in https://github.com/cohere-ai/cohere-python/pull/722 ## New Contributors * @jasonozuzu-cohere made their first contribution in https://github.com/cohere-ai/cohere-python/pull/722 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.3...5.20.4 | Low | 2/5/2026 |
| 5.20.3 | ## What's Changed * :herb: Fern Regeneration -- January 23, 2026 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/716 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.2...5.20.3 | Low | 1/23/2026 |
| 5.20.2 | ## What's Changed * fix: replace deprecated rerank v2 with rerank v3.5 in tests by @walterbm-cohere in https://github.com/cohere-ai/cohere-python/pull/710 * :herb: Fern Regeneration -- December 18, 2025 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/712 ## New Contributors * @walterbm-cohere made their first contribution in https://github.com/cohere-ai/cohere-python/pull/710 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.1...5.20.2 | Low | 12/18/2025 |
| 5.20.1 | ## What's Changed * :herb: Fern Regeneration -- November 10, 2025 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/709 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.20.0...5.20.1 | Low | 11/25/2025 |
| 5.20.0 | Add `priority` parameter to chat, embed and rerank **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.19.0...5.20.0 | Low | 10/24/2025 |
| 5.19.0 | Adds experimental support for Batches API | Low | 10/16/2025 |
| 5.18.0 | Fixes the issue with the `thinking` object described in https://github.com/cohere-ai/cohere-python/issues/692 | Low | 9/12/2025 |
| 5.17.0 | ## What's Changed * :herb: Fern Regeneration -- August 12, 2025 by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/688 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.16.3...5.17.0 | Low | 8/13/2025 |
| 5.16.3 | Release 5.16.3 | Low | 8/8/2025 |
| 5.16.2 | Release 5.16.2 | Low | 8/4/2025 |
| 5.16.1 | ## What's Changed * :herb: Fern Regeneration -- July 9, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/679 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.16.0...5.16.1 | Low | 7/9/2025 |
| 5.16.0 | ## What's Changed * :herb: Fern Regeneration -- May 30, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/666 * :herb: Fern Regeneration -- July 9, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/678 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.15.0...5.16.0 | Low | 7/9/2025 |
| 5.15.0 | ## What's Changed * :herb: Fern Regeneration -- April 15, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/660 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.14.2...5.15.0 | Low | 4/15/2025 |
| 5.14.2 | ## What's Changed * :herb: Fern Regeneration -- April 2, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/657 * Fix tests by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/658 * Revert "Fix tests" by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/659 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.14.1...5.14.2 | Low | 4/2/2025 |
| 5.14.1 | ## What's Changed * :herb: Fern Regeneration -- March 28, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/656 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.14.0...5.14.1 | Low | 3/28/2025 |
| 5.14.0 | ## What's Changed * :herb: Fern Regeneration -- February 28, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/654 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.12...5.14.0 | Low | 2/28/2025 |
| 5.13.12 | ## What's Changed * Fix v2 constructor types by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/647 * :herb: Fern Regeneration -- February 6, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/648 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.11...5.13.12 | Low | 2/6/2025 |
| 5.13.11 | ## What's Changed * Return base_url when it is not None by @jasonpraful in https://github.com/cohere-ai/cohere-python/pull/643 * :herb: Fern Regeneration -- January 21, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/644 ## New Contributors * @jasonpraful made their first contribution in https://github.com/cohere-ai/cohere-python/pull/643 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.10...5.13.11 | Low | 1/21/2025 |
| 5.13.10 | ## What's Changed * Make base_url fix stricter by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/641 * :herb: Fern Regeneration -- January 21, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/642 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.9...5.13.10 | Low | 1/21/2025 |
| 5.13.9 | ## What's Changed * :herb: Fern Regeneration -- January 20, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/637 * Skip embed job tests by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/640 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.8...5.13.9 | Low | 1/21/2025 |
| 5.13.8 | ## What's Changed * :herb: Fern Regeneration -- January 13, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/633 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.7...5.13.8 | Low | 1/14/2025 |
| 5.13.7 | ## What's Changed * :herb: Fern Regeneration -- January 7, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/629 * :herb: Fern Regeneration -- January 10, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/631 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.6...5.13.7 | Low | 1/13/2025 |
| 5.13.6 | ## What's Changed * :herb: Fern Regeneration -- January 6, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/627 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.5...5.13.6 | Low | 1/7/2025 |
| 5.13.5 | ## What's Changed * :herb: Fern Regeneration -- January 3, 2025 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/626 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.4...5.13.5 | Low | 1/3/2025 |
| 5.13.4 | ## What's Changed * Update lock file to fix hash by @andrewbcohere in https://github.com/cohere-ai/cohere-python/pull/621 * :herb: Fern Regeneration -- December 20, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/624 ## New Contributors * @andrewbcohere made their first contribution in https://github.com/cohere-ai/cohere-python/pull/621 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.3...5.13.4 | Low | 12/20/2024 |
| 5.13.3 | ## What's Changed * Throw when trying to rerank with v1 by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/616 * bump numpy by @mkozakov in https://github.com/cohere-ai/cohere-python/pull/618 * :herb: Fern Regeneration -- December 5, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/620 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.2...5.13.3 | Low | 12/5/2024 |
| 5.13.2 | ## What's Changed * :herb: Fern Regeneration -- December 4, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/615 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.1...5.13.2 | Low | 12/4/2024 |
| 5.13.1 | ## What's Changed * Rerank 3.5 fixes by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/611 * :herb: Fern Regeneration -- December 3, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/612 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.13.0...5.13.1 | Low | 12/3/2024 |
| 5.13.0 | ## What's Changed * Add bedrock test and v2 clis by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/609 * :herb: Fern Regeneration -- December 2, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/610 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.12.0...5.13.0 | Low | 12/2/2024 |
| 5.12.0 | ## What's Changed * create endpoint with InferenceAmiVersion by @CoderHam in https://github.com/cohere-ai/cohere-python/pull/602 * :herb: Fern Regeneration -- November 27, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/608 ## New Contributors * @CoderHam made their first contribution in https://github.com/cohere-ai/cohere-python/pull/602 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.11.4...5.12.0 | Low | 11/27/2024 |
| 5.11.4 | ## What's Changed * Even lazier imports by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/598 * :herb: Fern Regeneration -- November 15, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/601 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.11.3...5.11.4 | Low | 11/15/2024 |
| 5.11.3 | ## What's Changed * Fix sagemaker client by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/596 * :herb: Fern Regeneration -- October 30, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/597 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.11.2...5.11.3 | Low | 11/1/2024 |
| 5.11.2 | ## What's Changed * :herb: Fern Regeneration -- October 28, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/595 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.11.1...5.11.2 | Low | 10/28/2024 |
| 5.11.1 | ## What's Changed * :herb: Fern Regeneration -- October 18, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/594 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.11.0...5.11.1 | Low | 10/18/2024 |
| 5.11.0 | ## What's Changed * Sagemaker finetuning by @billytrend-cohere in https://github.com/cohere-ai/cohere-python/pull/588 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.10.0...5.11.0 | Low | 9/30/2024 |
| 5.11.0a0 | **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.10.0...5.11.0a0 | Low | 9/30/2024 |
| 5.10.0 | ## What's Changed * :herb: Fern Regeneration -- September 25, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/587 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.9.4...5.10.0 | Low | 9/25/2024 |
| 5.9.4 | ## What's Changed * :herb: Fern Regeneration -- September 19, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/586 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.9.3...5.9.4 | Low | 9/19/2024 |
| 5.9.3 | ## What's Changed * :herb: Fern Regeneration -- September 19, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/583 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.9.2...5.9.3 | Low | 9/19/2024 |
| 5.9.2 | ## What's Changed * :herb: Fern Regeneration -- September 13, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/576 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.9.1...5.9.2 | Low | 9/13/2024 |
| 5.9.1 | ## What's Changed * :herb: Fern Regeneration -- September 4, 2024 by @fern-api in https://github.com/cohere-ai/cohere-python/pull/569 **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.9.0...5.9.1 | Low | 9/5/2024 |
| 5.9.0 | Release 5.9.0 | Low | 8/30/2024 |
