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.
pip install cohereVerified import paths — ran on the pinned version, not inferred.
Minimal chat completion using v2 client
Migrate to co.chat() with ClientV2. See https://docs.cohere.com/v1/docs/migrating-from-cogenerate-to-cochat
Always pass model= explicitly. Current recommended: command-a-03-2025
Replace preamble='...' with messages=[{'role': 'system', 'content': '...'}, ...]Manage conversation history client-side by passing full messages array each turn
Implement web search as a tool_use pattern. See v2 migration guide.
Update rerank calls to use v3.5 endpoint. Check SDK release notes for exact method changes.
Check which client you instantiated (Client vs ClientV2) and use the matching response access pattern.
For num_generations=n, call co.chat() n times. Trim outputs on your side instead of stop_sequences.
Set export CO_API_KEY=your_key. ClientV2() reads this automatically.