Implementation:Cohere ai Cohere python ClientV2 Init
| Metadata | |
|---|---|
| Source Repo | Cohere Python SDK |
| Domains | SDK_Configuration, Client_Architecture |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete constructor for the unified Cohere API client combining V1 and V2 capabilities.
Description
ClientV2.__init__ creates a unified client by first initializing the V1 Client (which sets up BaseCohere, authentication, httpx client, thread pool executor, and argument validation), then initializing V2Client with the shared client_wrapper. A _CombinedRawClient proxy is created to delegate attribute access to V2 first, falling back to V1 for legacy methods.
Usage
Use this to create the primary Cohere SDK client. Pass an API key explicitly or let it auto-detect from environment variables. Configure timeout, base_url, or provide a custom httpx.Client for advanced networking needs.
Code Reference
- Source Location: Repository cohere-ai/cohere-python, File
src/cohere/client_v2.py, Lines L31-61 - Signature:
class ClientV2(V2Client, Client):
def __init__(
self,
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
*,
base_url: typing.Optional[str] = os.getenv("CO_API_URL"),
environment: ClientEnvironment = ClientEnvironment.PRODUCTION,
client_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
httpx_client: typing.Optional[httpx.Client] = None,
thread_pool_executor: ThreadPoolExecutor = ThreadPoolExecutor(64),
log_warning_experimental_features: bool = True,
):
- Import:
from cohere import ClientV2
I/O Contract
| Name | Type | Required | Description |
|---|---|---|---|
| Inputs | |||
api_key |
Optional[Union[str, Callable]] |
No | API key string or callable; auto-detected from env if None
|
base_url |
Optional[str] |
No | Override base URL; defaults to CO_API_URL env var
|
environment |
ClientEnvironment |
No | Defaults to PRODUCTION (https://api.cohere.com)
|
client_name |
Optional[str] |
No | Client identifier sent with requests |
timeout |
Optional[float] |
No | Request timeout in seconds |
httpx_client |
Optional[httpx.Client] |
No | Custom HTTP client |
thread_pool_executor |
ThreadPoolExecutor |
No | Executor for concurrent batching (default: 64 threads) |
| Outputs | |||
| Return value | ClientV2 |
— | Configured ClientV2 instance with access to chat, embed, rerank, chat_stream, and all V1/V2 methods
|
Usage Examples
from cohere import ClientV2
# Basic initialization (API key from environment)
client = ClientV2()
# Explicit API key
client = ClientV2(api_key="your-api-key")
# Custom configuration
client = ClientV2(
api_key="your-api-key",
timeout=60.0,
client_name="my-app",
)