# cohere

> No description

- **URL**: https://www.freshcrate.ai/projects/cohere
- **Author**: pypi
- **Category**: Developer Tools
- **Latest version**: `7.0.3` (2026-06-01)
- **License**: MIT
- **Source**: https://github.com/cohere-ai/cohere-python
- **Homepage**: https://pypi.org/project/cohere/
- **Language**: Python
- **GitHub**: 385 stars, 85 forks
- **Registry**: pypi (`cohere`)
- **Tags**: `pypi`

## 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

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `7.0.3` | 2026-06-01 | High | ## What's Changed * fix(utils): guard against None in sum_fields_if_not_none by @devteamaegis in https://github.com/cohere-ai/cohere-python/pull/773 * fix(utils): guard against None fields in merge_embed_responses by @devteamaegis in https://github.com/cohere-ai/cohere-python/pull/771 * SDK regeneration by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/776  ## New Contributors * @devteamaegis made their first contribution in https://github.com/cohere-ai/cohere-python/pul |
| `7.0.2` | 2026-05-29 | High | ## What's Changed * Performance improvements * SDK regeneration by @fern-api[bot] in https://github.com/cohere-ai/cohere-python/pull/768   **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/7.0.1...7.0.2 |
| `7.0.0` | 2026-05-22 | High | ## What's Changed * [BREAKING] Raised the minimum required Python version from ^3.8 to ^3.10   **Full Changelog**: https://github.com/cohere-ai/cohere-python/compare/6.1.0...7.0.0 |
| `6.1.0` | 2026-04-21 | Low | Imported from PyPI (6.1.0) |
| `6.0.0` | 2026-04-08 | Medium | ## 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 |
| `5.21.2` | 2026-03-31 | Medium | ## 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 |
| `5.21.1` | 2026-03-26 | Medium | Release 5.21.1 |
| `5.21.0` | 2026-03-26 | Medium | Adds Audio Transcriptions endpoint to the SDK |
| `5.20.7` | 2026-02-25 | Low | ## 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 |
| `5.20.6` | 2026-02-18 | Low | ## 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 |

## Dependency audit

- **Score**: 77/100
- **Total deps**: 8
- **Resolved**: 3
- **Unresolved**: 5
- **License conflicts**: 0
- **Warnings**: 5
- **Scanned**: 2026-06-01

## Citation

- HTML: https://www.freshcrate.ai/projects/cohere
- Markdown: https://www.freshcrate.ai/projects/cohere.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/cohere/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
