Cohere Python SDK

5.20.4 · active · verified Sat Feb 28

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →