Actively maintained. Last release 11 days ago, commits in 11 of the last 26 weeks. A safe choice.
pip install cohereCohere Python SDK

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.
Documentation
Cohere documentation and API reference is available here.
Installation
pip install cohere
Usage
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_KEYto avoid writing your api key within your code, e.g. addexport CO_API_KEY=theapikeyforyouraccountin your ~/.zshrc or ~/.bashrc, open a new terminal, then code callingcohere.Client()will read this key.
Streaming
The SDK supports streaming endpoints. To take advantage of this feature for chat,
use chat_stream.
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:
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)