{"id":12,"library":"cohere","title":"Cohere Python SDK","description":"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.","status":"active","version":"5.20.4","language":"python","source_language":"en","source_url":"https://docs.cohere.com/v2/docs/chat-api","tags":["cohere","llm","chat","embeddings","rerank","rag","command"],"install":[{"cmd":"pip install cohere","lang":"bash","label":"pip"},{"cmd":"uv add cohere","lang":"bash","label":"uv"}],"dependencies":[{"reason":"v5 was a full rewrite. Anything below 5.x is incompatible with current API.","package":"cohere>=5.0.0","optional":false}],"imports":[{"wrong":"import cohere; co = cohere.ClientV2()","symbol":"ClientV2","correct":"from cohere import ClientV2"}],"quickstart":{"code":"import cohere\n\nco = cohere.ClientV2()  # reads CO_API_KEY env var\n\nresponse = co.chat(\n    model='command-a-03-2025',\n    messages=[{'role': 'user', 'content': 'Hello'}]\n)\nprint(response.message.content[0].text)","lang":"python","description":"Minimal chat completion using v2 client"},"warnings":[{"fix":"Migrate to co.chat() with ClientV2. See https://docs.cohere.com/v1/docs/migrating-from-cogenerate-to-cochat","message":"Generate endpoint (co.generate()) deprecated as of Aug 26, 2025. Calls will fail after sunset.","severity":"breaking","affected_versions":"all v1"},{"fix":"Always pass model= explicitly. Current recommended: command-a-03-2025","message":"model is a required parameter in all v2 API calls. Omitting it raises an error. v1 had a default model fallback.","severity":"breaking","affected_versions":"v2 (ClientV2)"},{"fix":"Replace preamble='...' with messages=[{'role': 'system', 'content': '...'}, ...]","message":"preamble parameter removed in v2. System instructions must be passed as a system role message.","severity":"breaking","affected_versions":"v1 → v2 migration"},{"fix":"Manage conversation history client-side by passing full messages array each turn","message":"conversation_id removed in v2. Cohere no longer manages chat history server-side.","severity":"breaking","affected_versions":"v1 → v2 migration"},{"fix":"Implement web search as a tool_use pattern. See v2 migration guide.","message":"connectors (built-in RAG) removed in v2. Web search now requires passing a web search tool explicitly.","severity":"breaking","affected_versions":"v1 → v2 migration"},{"fix":"Update rerank calls to use v3.5 endpoint. Check SDK release notes for exact method changes.","message":"rerank v2 deprecated. Use rerank v3.5.","severity":"breaking","affected_versions":"current"},{"fix":"Check which client you instantiated (Client vs ClientV2) and use the matching response access pattern.","message":"Response 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.","severity":"gotcha","affected_versions":"all"},{"fix":"For num_generations=n, call co.chat() n times. Trim outputs on your side instead of stop_sequences.","message":"num_generations, stop_sequences, logit_bias, and truncate parameters from Generate are not supported in Chat. No direct equivalent for num_generations.","severity":"gotcha","affected_versions":"all v2"},{"fix":"Set export CO_API_KEY=your_key. ClientV2() reads this automatically.","message":"CO_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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'api':9 'call':42 'chat':45 'class':14 'client':13,15 'clientv2':19 'code':26 'coexist':12 'coher':1,8,43 'command':49 'current':21 'deprec':34 'embed':46 'endpoint':32 'generat':25,31 'legaci':17 'llm':24,44 'llm-gener':23 'model':35 'offici':4 'pattern':29 'python':2,5 'rag':48 'requir':38 'rerank':47 'sdk':3,6 'two':11 'use':27 'v1':16,28 'v2':20,41","created_at":"2026-03-16T04:39:09.011572+00:00","updated_at":"2026-04-16T03:02:29.410963+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":0,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"7.0.3","cli_name":"","cli_version":null,"type":"library","homepage":"https://cohere.com","github":"https://github.com/cohere-ai/cohere-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/cohere/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["llm-agents","ai-ml","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":"stale"}}