Implementation:Cohere ai Cohere python V2Client Chat
Appearance
| Metadata | |
|---|---|
| Source Repo | Cohere Python SDK |
| Source Doc | Cohere Chat API |
| Domains | NLP, Text_Generation, Chat_API |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete method for sending non-streaming chat completion requests to Cohere language models.
Description
V2Client.chat sends a synchronous chat request to the Cohere V2 API. It delegates to RawV2Client.chat for HTTP transport and returns a parsed V2ChatResponse. Supports all generation parameters, tool definitions, document citations, response format constraints, safety modes, and thinking/reasoning modes.
Usage
Call after initializing a ClientV2 and constructing messages. Use for non-streaming completions. The method blocks until the full response is received.
Code Reference
- Source Location: Repository cohere-ai/cohere-python, File
src/cohere/v2/client.py, Lines L217-383 - Signature:
def chat(
self,
*,
model: str,
messages: ChatMessages,
tools: typing.Optional[typing.Sequence[ToolV2]] = OMIT,
strict_tools: typing.Optional[bool] = OMIT,
documents: typing.Optional[typing.Sequence[V2ChatRequestDocumentsItem]] = OMIT,
citation_options: typing.Optional[CitationOptions] = OMIT,
response_format: typing.Optional[ResponseFormatV2] = OMIT,
safety_mode: typing.Optional[V2ChatRequestSafetyMode] = OMIT,
max_tokens: typing.Optional[int] = OMIT,
stop_sequences: typing.Optional[typing.Sequence[str]] = OMIT,
temperature: typing.Optional[float] = OMIT,
seed: typing.Optional[int] = OMIT,
frequency_penalty: typing.Optional[float] = OMIT,
presence_penalty: typing.Optional[float] = OMIT,
k: typing.Optional[int] = OMIT,
p: typing.Optional[float] = OMIT,
logprobs: typing.Optional[bool] = OMIT,
tool_choice: typing.Optional[V2ChatRequestToolChoice] = OMIT,
thinking: typing.Optional[Thinking] = OMIT,
priority: typing.Optional[int] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> V2ChatResponse:
- Import:
from cohere import ClientV2(access viaclient.chat())
I/O Contract
| Name | Type | Required | Description |
|---|---|---|---|
| Inputs | |||
model |
str |
Yes | Model name, e.g. "command-a-03-2025"
|
messages |
ChatMessages |
Yes | Conversation history |
tools |
Optional[Sequence[ToolV2]] |
No | Tool/function definitions |
temperature |
Optional[float] |
No | Sampling temperature (default 0.3) |
max_tokens |
Optional[int] |
No | Max output tokens |
stop_sequences |
Optional[Sequence[str]] |
No | Up to 5 stop strings |
seed |
Optional[int] |
No | For deterministic sampling |
frequency_penalty |
Optional[float] |
No | Repetition penalty (0-1) |
presence_penalty |
Optional[float] |
No | Presence penalty (0-1) |
k |
Optional[int] |
No | Top-k sampling (0-500) |
p |
Optional[float] |
No | Nucleus sampling (0.01-0.99) |
| Outputs | |||
| Return value | V2ChatResponse |
— | Response with id, finish_reason, message (containing content, tool_calls, citations), usage
|
Usage Examples
from cohere import ClientV2, UserChatMessageV2
client = ClientV2()
response = client.chat(
model="command-a-03-2025",
messages=[UserChatMessageV2(content="Explain quantum computing in simple terms.")],
temperature=0.5,
max_tokens=500,
)
print(response.message.content[0].text)
print(f"Tokens used: {response.usage}")
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment