Skip to main content
Cohere

Search documentation

Type to search this documentation.

On this pageOverview

Creating a client

To start using all features available in the Cohere SDK, you should create a client first.

Python
import cohere

co = cohere.ClientV2(api_key="YOUR_API_KEY")

Source

The Cohere API client initializes with the following parameters:

ParameterTypeDefaultDescription
api_keystr/callableNoneAPI key for authenticating requests to the Cohere V2 API.
base_urlstros.getenv("CO_API_URL")Base URL for the Cohere API.
environmentClientEnvironmentClientEnvironment.PRODUCTIONSpecifies the API environment (e.g., production, staging).
client_namestrNoneOptional name for the client instance, useful for logging.
timeoutfloatNoneTimeout in seconds for API requests.
httpx_clienthttpx.ClientNoneOptional pre-configured httpx.Client for making HTTP requests.
thread_pool_executorThreadPoolExecutorThreadPoolExecutor(64)Thread pool executor for concurrent operations, with 64 threads by default.
log_experimentalboolTrueEnables/disables warnings for experimental features.
TypeScript
import { CohereClientV2 } from 'cohere-ai';

const cohere = new CohereClientV2({ token: 'YOUR_API_KEY' });

Source

The Cohere API client initializes with the following parameters:

ParameterTypeDefaultDescription
tokenstringundefinedRequired. API key used for authenticating requests to the Cohere API.
baseUrlstring"https://api.cohere.ai/v1"Base URL endpoint for the Cohere API.
clientNamestringundefinedOptional identifier for the client instance, useful for logging.
timeoutnumber (milliseconds)120000 (120 seconds)Request timeout in milliseconds.
fetchtypeof fetchGlobal fetchCustom fetch implementation for HTTP requests.
Java
import com.cohere.api.Cohere;

Cohere cohere = Cohere.builder()
                      .token("YOUR_API_KEY")
                      .clientName("your-client-name")
                      .build();

Source

The Cohere API client initializes with the following parameters:

ParameterTypeDefaultDescription
tokenStringnullRequired. Your Cohere API key for authenticating requests.
baseUrlString"https://api.cohere.ai/v1"The base URL for the Cohere API.
clientNameStringnullOptional identifier for your client application.
timeoutDurationnullTimeout duration for API requests.
okHttpClientOkHttpClientnullCustom OkHttpClient instance for making HTTP requests.
Go
import (
    client "github.com/cohere-ai/cohere-go/v2/client"
)

co := client.NewClient(client.WithToken("YOUR_API_KEY"))

Source

The Cohere API client initializes with the following parameters:

ParameterTypeDefaultDescription
tokenstring"" (empty string)Required. Your Cohere API key for authenticating requests.
baseURLstring"https://api.cohere.ai/v1"The base URL for the Cohere API.
httpClient*http.Clienthttp.DefaultClientCustom HTTP client for making requests.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu