Text generation
Generate text with an Anthropic Claude model through the AI SDK unified generation API.
AI Tools · Const
Anthropic is the AI SDK provider for Anthropic Messages API models. Import anthropic from @ai-sdk/anthropic, select a model by ID, and pass it to AI SDK generation functions.
The Anthropic provider gives AI SDK applications access to Anthropic Messages API models. Import the default provider instance, select a model by identifier, and pass that model to AI SDK functions such as generateText; use createAnthropic when custom settings are needed.
anthropic(modelId)| Name | Type | Description |
|---|---|---|
modelId | string | Anthropic model identifier, for example claude-sonnet-4-5. |
A language model instance that can be passed to AI SDK generation functions.
import { anthropic } from '@ai-sdk/anthropic';
import { generateText } from 'ai';
const result = await generateText({
model: anthropic('claude-sonnet-4-5'),
prompt: 'Summarize the benefits of typed APIs.',
});
console.log(result.text);This runnable TypeScript example uses the default Anthropic provider instance to create a model and generate text.
Generate text with an Anthropic Claude model through the AI SDK unified generation API.
Route Anthropic API requests through an organizational proxy.
Configure provider settings instead of using the default provider instance.
The Anthropic provider is the AI SDK integration for Anthropic's Messages API. It is distributed in the @ai-sdk/anthropic module and exposes a default anthropic provider instance.
Follow-up: How would you customize the provider? Import createAnthropic and create a provider instance with custom settings, such as a different URL prefix.
Install @ai-sdk/anthropic, import anthropic, and call it with a model identifier such as claude-sonnet-4-5. Pass the resulting model to an AI SDK generation function.
Follow-up: What API does the resulting model target? It calls Anthropic's Messages API through the provider.
The provider uses ANTHROPIC_API_KEY by default for authentication. Its standard API URL prefix is https://api.anthropic.com/v1.
Follow-up: When would the URL prefix be changed? Use a custom prefix when routing requests through a proxy or another compatible endpoint.
anthropiccreateAnthropic@ai-sdk/anthropicgenerateText