Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

createCohere

createCohere creates a customized Cohere provider instance from optional settings such as an API key, base URL, headers, and fetch implementation. Use the provider to create models for Cohere's chat API.

How it works

createCohere constructs a Cohere provider instance from optional settings. The instance can then create models for the Cohere chat API; the API key defaults to COHERE_API_KEY when not supplied.

Syntax

createCohere(options?: { baseURL?: string; apiKey?: string; headers?: Record<string, string>; fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response> })

Parameters

NameTypeDescription
baseURLstringURL prefix used for API calls; defaults to https://api.cohere.com/v2.
apiKeystringCredential sent in the Authorization header; defaults to COHERE_API_KEY.
headersRecord<string,string>Additional request headers.
fetch(input: RequestInfo, init?: RequestInit) => Promise<Response>Custom implementation for making requests.

Returns

A Cohere provider instance that can create models for the Cohere chat API.

Key points

  • Import createCohere from the dedicated @ai-sdk/cohere package.
  • Calling createCohere returns a provider instance configured with the supplied options.
  • Without a custom baseURL, requests use the Cohere v2 API prefix.
  • The configured API key is transmitted through the Authorization header.
  • Use the returned provider to create models targeting Cohere's chat API.

Common mistakes

  • If apiKey is omitted, the provider reads the COHERE_API_KEY environment variable.
  • Changing baseURL redirects API calls, so set it only when using a compatible proxy or endpoint.

Example: Create a configured Cohere provider

import { createCohere } from '@ai-sdk/cohere';
import { generateText } from 'ai';

const cohere = createCohere({
  apiKey: process.env.COHERE_API_KEY,
});

const { text } = await generateText({
  model: cohere('command-r'),
  prompt: 'Explain vector embeddings in one sentence.',
});

console.log(text);

Creates a configured Cohere provider and uses it to select a Cohere chat model for text generation.

When to use it

Configure Cohere model access

You need to call Cohere models through the AI SDK's unified model interface.

Use a custom API endpoint

Your application routes outbound model traffic through an internal compatible proxy.

Customize HTTP requests

Tests or infrastructure require custom request behavior or headers.

Interview questions

QWhat does createCohere do?

createCohere is imported from @ai-sdk/cohere and returns a configurable provider instance. That instance can be used to create models for Cohere's chat API.

Follow-up: How would you avoid hard-coding credentials? Omit apiKey and provide COHERE_API_KEY through the environment, or pass it from a secure runtime configuration.

QHow is authentication configured?

The optional apiKey is sent in the Authorization header. If it is not supplied, the provider uses the COHERE_API_KEY environment variable.

Follow-up: What other provider-level customization is available? baseURL, headers, and fetch can also be supplied.

QWhich settings can customize the provider?

baseURL changes the URL prefix used for API calls, while headers adds request headers and fetch allows a custom request implementation. The documented default base URL is https://api.cohere.com/v2.

Follow-up: When is baseURL useful? It is useful when requests must pass through a proxy server or compatible alternate endpoint.

  • cohere
  • @ai-sdk/cohere
  • generateText
  • Cohere chat API

Source: Cohere Provider | AI SDK. Checked 2026-10-15.