Chat generation
Generate text with a Cohere chat model through the AI SDK.
AI Tools · Const
The Cohere provider integrates Cohere language and embedding models with the AI SDK through @ai-sdk/cohere. Use the default cohere instance for standard setup or createCohere for customization.
The Cohere provider connects the AI SDK to Cohere’s chat API. Use the built-in cohere provider for standard configuration, or create a configured provider with createCohere; provider instances expose model factories for calling Cohere language and embedding models.
import { cohere, createCohere } from '@ai-sdk/cohere';@ai-sdk/cohere.cohere.createCohere to build a provider with custom settings.createCohere instead of the default instance when custom provider configuration is required.import { cohere } from '@ai-sdk/cohere';
import { generateText } from 'ai';
const result = await generateText({
model: cohere('command-r-plus'),
prompt: 'Explain dependency injection in one sentence.',
});
console.log(result.text);Install the provider package, import the default provider, select a Cohere model, and pass it to the AI SDK’s text-generation function.
Generate text with a Cohere chat model through the AI SDK.
Use Cohere’s supported embedding models in an AI SDK application.
Create a provider instance with application-specific settings.
The provider is distributed as @ai-sdk/cohere, and the default instance is imported as cohere. A model can then be created from that provider and supplied to AI SDK operations.
Follow-up: How would you support custom configuration? Import createCohere and construct a provider instance with the required settings.
The provider supports language and embedding models for Cohere’s chat API. Language models are selected through the provider’s model interface, while embeddings use the corresponding embedding-model factory.
Follow-up: What API does the provider call for chat generation? It calls Cohere’s chat API through the selected provider model.
Install the package with pnpm add @ai-sdk/cohere, then import cohere from @ai-sdk/cohere. Pass a selected Cohere model to the AI SDK generation workflow.
Follow-up: What changes when the default provider is insufficient? Create a configured instance with createCohere rather than using the default export.
createCohere@ai-sdk/cohereCohere chat APIlanguage modelsembedding models