Cohere
The Cohere provider contains language and embedding model support for the Cohere chat API.
You can use Cohere models through AI Gateway (recommended) or connect directly with @ai-sdk/cohere.
Using AI Gateway
The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install ai:
$ pnpm add ai
$ npm install ai
$ yarn add ai
$ bun add ai
Set an AI Gateway API key in your environment:
Vercel deployments can also use OIDC authentication. See the AI Gateway provider documentation for configuration and the model catalog for available models.
Gateway feature and provider-option support depends on the model and the provider serving the request. See Gateway provider options.
Using @ai-sdk/cohere
For direct access to Cohere, install ai and @ai-sdk/cohere:
$ pnpm add ai @ai-sdk/cohere
$ npm install ai @ai-sdk/cohere
$ yarn add ai @ai-sdk/cohere
$ bun add ai @ai-sdk/cohere
Set your Cohere API credential in the COHERE_API_KEY environment variable:
AI Gateway does not expose every API in @ai-sdk/cohere. Use the direct provider for provider-specific APIs or custom connection settings.
The following sections document the direct @ai-sdk/cohere provider,
including its model factories and settings. Gateway model and feature
availability can differ.
Provider Instance
You can import the default provider instance cohere from @ai-sdk/cohere:
If you need a customized setup, you can import createCohere from @ai-sdk/cohere
and create a provider instance with your settings:
You can use the following optional settings to customize the Cohere provider instance:
-
baseURL string
Use a different URL prefix for API calls, e.g. to use proxy servers. The default prefix is
https://api.cohere.com/v2. -
apiKey string | PromiseLike<string> | (() => string | PromiseLike<string>)
Pass a function to resolve credentials before each request, including when keys rotate. The function can return a string or a promise. Credential caching and refresh are managed by the function.
API key that is being sent using the
Authorizationheader. It defaults to theCOHERE_API_KEYenvironment variable. -
headers Record<string,string>
Custom headers to include in the requests.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation. Defaults to the global
fetchfunction. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing. -
generateId () => string
Optional function to generate unique IDs for each request. Defaults to the SDK's built-in ID generator.
Language Models
You can create models that call the Cohere chat API using a provider instance.
The first argument is the model id, e.g. command-a-03-2025.
Some Cohere chat models support tool calls.
Example
You can use Cohere language models to generate text with the generateText function:
Cohere language models can also be used in the streamText function
and support structured data generation with Output
(see AI SDK Core).
Model Capabilities
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
command-a-03-2025 | ||||
command-a-reasoning-08-2025 | ||||
command-a-vision-07-2025 | ||||
command-r7b-12-2024 | ||||
command-r-plus-04-2024 | ||||
command-r-plus | ||||
command-r-08-2024 | ||||
command-r-03-2024 | ||||
command-r | ||||
command | ||||
command-nightly | ||||
command-light | ||||
command-light-nightly |
The table above lists popular models. Please see the Cohere docs for a full list of available models. You can also pass any available provider model ID as a string if needed.
Image Inputs
Vision-capable Cohere models such as command-a-vision-07-2025 accept image inputs as part of the message content. You can pass images as raw bytes, base64-encoded strings, or URLs:
You can use the cohere provider option on a file part to set the image input detail to high, low, or auto:
Reasoning
Cohere has introduced reasoning with the command-a-reasoning-08-2025 model. You can learn more at https://docs.cohere.com/docs/reasoning.
Sources
You can ground a Cohere response in documents by adding text files to the prompt as file parts. When the model cites one of these documents, the provider returns the cited text span as a source.
With generateText, cited documents are available in result.sources:
With streamText, the same citations are emitted as source stream parts:
Each source has sourceType: 'document', the document title ('Document' when
Cohere does not return one), and citation details in providerMetadata.cohere:
start/endnumber - character offsets of the cited text in the response.textstring - the cited text.sourcesarray - the raw Cohere sources, including each document'sid,text, andtitle.citationTypestring - the Cohere citation type, e.g.'TEXT_CONTENT'.
Keys that Cohere omits are absent from providerMetadata.cohere. Citations that
only reference tool output have no document to cite and are not emitted as
sources.
Embedding Models
You can create models that call the Cohere embed API
using the .embedding() factory method.
You can use Cohere embedding models to generate embeddings with the embed function:
Cohere embedding models support additional provider options that can be passed via providerOptions.cohere:
The following provider options are available:
-
embeddingType 'float' | 'int8' | 'uint8' | 'binary' | 'ubinary'
Selects one embedding format per call. Defaults to
float, preserving the existing behavior. Non-float formats require Embed v3.0 or newer. For example:The selected format is returned in
embedding(orembeddingsforembedMany) as number arrays. The provider returns the values without converting or unpacking them.binaryandubinarycontain packed bytes: each number represents eight dimensions. Use a binary-aware vector database or unpack the bits before comparing vectors; do not pass packed bytes directly tocosineSimilarity. Compressed formats can affect retrieval quality, and compact storage requires an appropriate database representation. -
inputType 'search_document' | 'search_query' | 'classification' | 'clustering'
Specifies the type of input passed to the model. Default is
search_query.search_document: Used for embeddings stored in a vector database for search use-cases.search_query: Used for embeddings of search queries run against a vector DB to find relevant documents.classification: Used for embeddings passed through a text classifier.clustering: Used for embeddings run through a clustering algorithm.
-
outputDimension 256 | 512 | 768 | 1024 | 1536 | 2048
The number of dimensions of the output embedding. Available for Embed v4.0 and newer models. Embed v4.0 supports
256,512,1024, and1536(default). Embed v5.0 Pro and Fast also support768and2048(default). When omitted, the API uses the model's default dimension. -
truncate 'NONE' | 'START' | 'END'
Specifies how the API will handle inputs longer than the maximum token length. Default is
END.NONE: If selected, when the input exceeds the maximum input token length will return an error.START: Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.END: Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
Model Capabilities
| Model | Default Dimensions | Supported Dimensions | Custom Dimensions |
|---|---|---|---|
embed-v5.0-pro | 2048 | 256, 512, 768, 1024, 1536, 2048 | |
embed-v5.0-fast | 2048 | 256, 512, 768, 1024, 1536, 2048 | |
embed-v4.0 | 1536 | 256, 512, 1024, 1536 | |
embed-english-v3.0 | 1024 | 1024 | |
embed-multilingual-v3.0 | 1024 | 1024 | |
embed-english-light-v3.0 | 384 | 384 | |
embed-multilingual-light-v3.0 | 384 | 384 | |
embed-english-v2.0 | 4096 | 4096 | |
embed-english-light-v2.0 | 1024 | 1024 | |
embed-multilingual-v2.0 | 768 | 768 |
Reranking Models
You can create models that call the Cohere rerank API
using the .reranking() factory method.
You can use Cohere reranking models to rerank documents with the rerank function:
Cohere reranking models support additional provider options that can be passed via providerOptions.cohere:
The following provider options are available:
-
maxTokensPerDoc number
Maximum number of tokens per document. Default is
4096. -
priority number
Priority of the request. Default is
0.
Model Capabilities
| Model | Text Documents | Object Documents | Top N |
|---|---|---|---|
rerank-v4.0-pro | Conditional: Objects are converted to JSON strings with a compatibility warning. | ||
rerank-v4.0-fast | Conditional: Objects are converted to JSON strings with a compatibility warning. | ||
rerank-v3.5 | Conditional: Objects are converted to JSON strings with a compatibility warning. | ||
rerank-english-v3.0 | Conditional: Objects are converted to JSON strings with a compatibility warning. | ||
rerank-multilingual-v3.0 | Conditional: Objects are converted to JSON strings with a compatibility warning. |