Skip to main content

Overview

The Anthropic provider gives you access to Claude models with advanced reasoning capabilities through adaptive and manual thinking modes.

Installation

createAnthropic()

Create an Anthropic provider instance.

Options

string
Your Anthropic API key. Defaults to ANTHROPIC_API_KEY environment variable.
string
Custom base URL for API requests.
number
default:"4096"
Default maximum tokens for completions. Can be overridden per request.
AnthropicChatClient
Provide your own configured Anthropic client instance.

Returns

AnthropicProvider with method chatModel().

Supported models

Claude Fable and Mythos models use adaptive thinking mode.
  • claude-fable-5 - Widely available model for demanding reasoning and agentic work
  • claude-mythos-5 - Limited-access model with the same capability handling
  • claude-mythos-preview - Limited-access preview model
Current Opus and Sonnet models use effort-based adaptive thinking.
  • claude-opus-5 - Strongest Opus model for complex agentic coding and enterprise work
  • claude-sonnet-5 - Most agentic Sonnet model with near-Opus performance at lower cost
  • claude-opus-4-8 - Opus model for complex reasoning and agentic coding
  • claude-opus-4-7 - Opus model with max effort support
  • claude-opus-4-6 - Opus model with max effort support
  • claude-sonnet-4-6 - Balanced performance and speed with max effort support
Models with manual thinking budget control.
  • claude-opus-4-5 - High capability
  • claude-sonnet-4-5 - Efficient reasoning
  • claude-haiku-4-5 - Fast and lightweight
  • claude-opus-4-1 - Enhanced reasoning
  • claude-opus-4 - Strong performance
  • claude-sonnet-4 - Balanced model
  • claude-sonnet-3-7 - Previous generation

Provider support

Model capabilities

Use ChatModel.capabilities to inspect the constraints for the selected model, or call getAnthropicModelCapabilities(modelId) without creating a model:
For registered Claude models:
  • supportedEfforts lists the accepted effort levels. Models with adaptive thinking may also support max.
  • mode is optional; reasoning is enabled by passing reasoning.
  • restrictsSamplingParams is true. The exact temperature, topP, and topK rules are described under Reasoning restrictions.
  • supportedToolChoices is ['auto', 'none'] while reasoning is enabled.
  • modalities.input is ['text', 'image', 'file'] for every Claude model. Image sources accept both base64 and url. File parts are PDF-only. modalities.output is ['text'].

Examples

Basic chat

Extended thinking

The provider requests summarized thinking, matching the OpenAI provider’s reasoning-summary behavior. Every reasoning part also retains Anthropic’s signature so you can safely pass the result into a later tool-result request.

Streaming

Tool calling

Vision and file inputs

Anthropic accepts image parts and PDF file parts. Other file MIME types are rejected.

Thinking modes

Adaptive thinking

The model automatically determines thinking depth based on the effort level.
claude-fable-5, claude-mythos-5, claude-mythos-preview, claude-opus-5, claude-opus-4-8, claude-opus-4-7, claude-opus-4-6, claude-sonnet-5, and claude-sonnet-4-6 support 'max' effort directly.

Manual thinking budget (Claude 4.5 and earlier)

Token budgets: minimal -> 1,024, low -> 2,048, medium -> 8,192, high -> 32,768, max -> 65,536. The adapter caps the selected budget at maxTokens - 1 because Anthropic requires the thinking budget to be lower than the total output limit. maxTokens must be greater than 1,024.

Reasoning restrictions

When reasoning is enabled, Anthropic enforces additional request constraints:
  • temperature must be omitted
  • topP must be between 0.95 and 1
  • toolChoice must be 'auto' or 'none'
  • providerOptions.anthropic.topK must be omitted
Claude Fable 5, Mythos 5, Mythos Preview, Opus 5, Opus 4.8, Opus 4.7, and Sonnet 5 also reject non-default sampling parameters when you do not explicitly enable reasoning. For these models, use temperature: 1, topP: 1, and omit topK.
Violating these constraints throws a ValidationError before the request is sent.
Adaptive thinking automatically supports reasoning between tool calls. For older compatible manual-thinking models, the adapter sends the interleaved-thinking-2025-05-14 beta as an anthropic-beta header.

Reasoning metadata

When reasoning is enabled, Anthropic reasoning parts include provider metadata with signature and redacted data fields. Use getProviderMetadata to access them in a type-safe way.
The AnthropicReasoningMetadata type contains:
  • signature — cryptographic signature for multi-turn reasoning fidelity
  • redactedData — redacted thinking content, if present

Provider-specific options

Options are namespaced under anthropic in providerOptions:
Available fields: topK, stopSequences, betas, outputConfig, and cacheControl.
  • betas are sent through the anthropic-beta request header.

Prompt caching

Use cacheControl to enable Anthropic prompt caching. This maps to Anthropic’s top-level cache_control request field and uses automatic caching for the reusable prompt prefix.
You can request a 1-hour cache TTL when you expect follow-up requests to arrive later than Anthropic’s default 5-minute cache window:
Anthropic reports cache usage in result.usage.inputTokenDetails:
  • cacheReadTokens: Tokens served from an existing cache entry
  • cacheWriteTokens: Tokens written to the cache for future requests
Anthropic only caches prompts above the model’s minimum cacheable length:
  • 1024 tokens for Claude Opus 4.8
  • 1024 tokens for Claude Sonnet 4.5, Claude Opus 4.1, Claude Opus 4, Claude Sonnet 4, and Claude Sonnet 3.7
  • 2048 tokens for Claude Sonnet 4.6
  • 4096 tokens for Claude Opus 4.6, Claude Opus 4.5, and Claude Haiku 4.5

Error handling

OpenAI Provider

GPT models with reasoning capabilities

Google GenAI Provider

Gemini models with multimodal support

Chat Completion Guide

Learn how to use chat completion