freshcrate

cohere

No description

Description

# Cohere Python SDK ![](banner.png) [![version badge](https://img.shields.io/pypi/v/cohere)](https://pypi.org/project/cohere/) ![license badge](https://img.shields.io/github/license/cohere-ai/cohere-python) [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](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

VersionChangesUrgencyDate
6.1.0Imported from PyPI (6.1.0)Low4/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.0Medium4/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.2Medium3/31/2026
5.21.1Release 5.21.1Medium3/26/2026
5.21.0Adds Audio Transcriptions endpoint to the SDKMedium3/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.7Low2/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.6Low2/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.5Low2/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.4Low2/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.3Low1/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.2Low12/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.1Low11/25/2025
5.20.0Add `priority` parameter to chat, embed and rerank **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.19.0...5.20.0Low10/24/2025
5.19.0Adds experimental support for Batches APILow10/16/2025
5.18.0Fixes the issue with the `thinking` object described in https://github.com/cohere-ai/cohere-python/issues/692 Low9/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.0Low8/13/2025
5.16.3Release 5.16.3Low8/8/2025
5.16.2Release 5.16.2Low8/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.1Low7/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.0Low7/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.0Low4/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.2Low4/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.1Low3/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.0Low2/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.12Low2/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.11Low1/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.10Low1/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.9Low1/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.8Low1/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.7Low1/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.6Low1/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.5Low1/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.4Low12/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.3Low12/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.2Low12/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.1Low12/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.0Low12/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.0Low11/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.4Low11/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.3Low11/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.2Low10/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.1Low10/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.0Low9/30/2024
5.11.0a0**Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/5.10.0...5.11.0a0Low9/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.0Low9/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.4Low9/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.3Low9/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.2Low9/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.1Low9/5/2024
5.9.0Release 5.9.0Low8/30/2024

Dependencies & License Audit

Loading dependencies...

Similar Packages

azure-coreMicrosoft Azure Core Library for Pythonazure-template_0.1.0b6187637
azure-mgmt-coreMicrosoft Azure Management Core Library for Pythonazure-template_0.1.0b6187637
azure-monitor-opentelemetry-exporterMicrosoft Azure Monitor Opentelemetry Exporter Client Library for Pythonazure-template_0.1.0b6187637
azure-servicebusMicrosoft Azure Service Bus Client Library for Pythonazure-template_0.1.0b6187637
azure-monitor-opentelemetryMicrosoft Azure Monitor Opentelemetry Distro Client Library for Pythonazure-template_0.1.0b6187637