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

AI Tools · Const

Anthropic API

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.

How it works

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.

Syntax

anthropic(modelId)

Parameters

NameTypeDescription
modelIdstringAnthropic model identifier, for example claude-sonnet-4-5.

Returns

A language model instance that can be passed to AI SDK generation functions.

Key points

  • Install the @ai-sdk/anthropic package to add Anthropic support to an AI SDK project.
  • The package exports a ready-to-use provider instance named anthropic.
  • Calling the provider with a model identifier produces a model backed by Anthropic's Messages API.
  • Use createAnthropic rather than the default instance when provider configuration must be customized.
  • A custom URL prefix supports routing requests through a proxy server.

Common mistakes

  • The provider reads credentials from ANTHROPIC_API_KEY unless a different key is configured.
  • Custom endpoints require configuring a different base URL or URL prefix.

Example: Generate text with Anthropic

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.

When to use it

Text generation

Generate text with an Anthropic Claude model through the AI SDK unified generation API.

Custom endpoint routing

Route Anthropic API requests through an organizational proxy.

Customized provider setup

Configure provider settings instead of using the default provider instance.

Interview questions

QWhat is the Anthropic provider in the AI SDK?

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.

QHow do you create an Anthropic model?

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.

QWhat defaults should an application configure?

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.

  • anthropic
  • createAnthropic
  • @ai-sdk/anthropic
  • generateText

Source: Anthropic - AI SDK. Checked 2026-10-15.