Registry / llm-agents / cohere

cohere

JSON →
library5.20.4pypypi✓ verified 51d ago

Official Python SDK for Cohere API. Has two coexisting client classes: Client (v1, legacy) and ClientV2 (v2, current). Most LLM-generated code uses v1 patterns. The Generate endpoint is deprecated. model is now required in all v2 calls.

llm-agentsai-mlhttp-networking
pip install cohere
Install & Compatibility
Where this runs
tested against v7.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
3/5 runs
3/5 runs
py 3.11
3/5 runs
3/5 runs
py 3.12
3/5 runs
3/5 runs
py 3.13
3/5 runs
3/5 runs
py 3.9
3/5 runs
3/5 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ClientV2
from cohere import ClientV2
import cohere; co = cohere.ClientV2()

Minimal chat completion using v2 client

import cohere co = cohere.ClientV2() # reads CO_API_KEY env var response = co.chat( model='command-a-03-2025', messages=[{'role': 'user', 'content': 'Hello'}] ) print(response.message.content[0].text)
Debug
Known issues
breakingGenerate endpoint (co.generate()) deprecated as of Aug 26, 2025. Calls will fail after sunset.
fix
Migrate to co.chat() with ClientV2. See https://docs.cohere.com/v1/docs/migrating-from-cogenerate-to-cochat
affects: all v1
breakingmodel is a required parameter in all v2 API calls. Omitting it raises an error. v1 had a default model fallback.
fix
Always pass model= explicitly. Current recommended: command-a-03-2025
affects: v2 (ClientV2)
breakingpreamble parameter removed in v2. System instructions must be passed as a system role message.
fix
Replace preamble='...' with messages=[{'role': 'system', 'content': '...'}, ...]
affects: v1 → v2 migration
breakingconversation_id removed in v2. Cohere no longer manages chat history server-side.
fix
Manage conversation history client-side by passing full messages array each turn
affects: v1 → v2 migration
breakingconnectors (built-in RAG) removed in v2. Web search now requires passing a web search tool explicitly.
fix
Implement web search as a tool_use pattern. See v2 migration guide.
affects: v1 → v2 migration
breakingrerank v2 deprecated. Use rerank v3.5.
fix
Update rerank calls to use v3.5 endpoint. Check SDK release notes for exact method changes.
affects: current
gotchaResponse text access changed between v1 and v2. v1: response.text. v2: response.message.content[0].text. Mixing clients and response patterns is the most common error.
fix
Check which client you instantiated (Client vs ClientV2) and use the matching response access pattern.
affects: all
gotchanum_generations, stop_sequences, logit_bias, and truncate parameters from Generate are not supported in Chat. No direct equivalent for num_generations.
fix
For num_generations=n, call co.chat() n times. Trim outputs on your side instead of stop_sequences.
affects: all v2
gotchaCO_API_KEY is the expected environment variable name for ClientV2. Not COHERE_API_KEY. Failing to set CO_API_KEY or using the wrong variable name can lead to explicit instantiation errors or authentication failures.
fix
Set export CO_API_KEY=your_key. ClientV2() reads this automatically.
affects: all
Upgrade
Version history
7.0.3latest on PyPI
Audit
Dependencies
cohere>=5.0.0requiredv5 was a full rewrite. Anything below 5.x is incompatible with current API.
Agent activity
81 hits · last 30 days
node
12
seranking-bot
4
amazonbot
3
ahrefsbot
2
bytedance
1
Resources