Discover / RAG & Knowledge
Cohere Python SDK
by cohere-aiPython
Official Python library for Cohere embeddings and language models.
Maturity: stable because 6y old, 7.0.8 released 11d ago. Derived from release and commit history, not a rating.
- Stars
- 396
- Forks
- 91
- Downloads / mo
- —
- Last commit
- 2026-07-23
- License
- MIT
- Open issues
- 14
Market and trust evidence
Edition not yet matchedNo exact skills.sh identity match is available for this repository. Repository adoption and freshness remain visible above; install momentum is not inferred.
Trust analysis is a screening signal, not a security warranty. Read the ranking and trust methodology.
In practice
Written by AI from this repository’s README · high confidenceProvides typed Python clients to interact with Cohere's embedding and text generation endpoints.
Use it when
Use when integrating Cohere's language models into a Python application or deploying on OCI.
Not the right pick when
The SDK is generated programmatically, making custom direct contributions difficult.
Capabilities
- Streaming support
- Oracle Cloud Infrastructure authentication
- Embeddings and Chat endpoints
Cost: Needs a paid API or account
Video walkthroughs
How to make AI Content Generator in Python with Cohere AI - Ultimate Beginners Guide
GEN AI PROJECT 2024 FOR ALL USING COHERE, STREAMLIT & PYTHON CHATBOT | KAUSTUBH SHARMA
Third-party YouTube uploads matched to this tool by title, channel and repository name on 2026-08-03. Not made, reviewed or endorsed by SkillPilot. View counts and publish months are as of the match date and the month is approximate. Nothing loads from YouTube until you press play.
What the repository ships
Detected from the actual files in the repository root.
Latest release 7.0.8
Published 2026-07-23
What's Changed
- httpx-aiohttp version requirement from "0.1.8" to "^0.1.8"
Full Changelog: https://github.com/cohere-ai/cohere-python/compare/7.07...7.0.8
Tags
README
Cohere Python SDK
image
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 calling
cohere.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)
OCI Authentication Methods
1. Config File (Default)
co = cohere.OciClient(
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
# Uses ~/.oci/config with DEFAULT profile
)
2. Custom Profile
co = cohere.OciClient(
oci_profile="MY_PROFILE",
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)
3. Session-based Authentication (Security Token)
# 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
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)
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) andOciClientV2(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
floatandint8simultaneously)
Note: To use Generate or Rerank models on OCI, you need to:
- Fine-tune the base model using OCI's fine-tuning service
- Deploy the fine-tuned model to a dedicated endpoint
- Update your code to use the deployed model endpoint
For the latest model availability, see the OCI Generative AI documentation.
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 overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!