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 output limit for requests that omit maxTokens. When unset, each request uses the model’s output ceiling. See Output limits.
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-1 - Current Fable model for demanding reasoning and long-horizon agentic work. Adaptive thinking is always on, and forced tool choice is rejected on every request
  • claude-mythos-5-1 - Limited-access model with the same capability handling as Claude Fable 5.1
  • 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, Sonnet, and Haiku models use effort-based adaptive thinking.
  • claude-opus-5-5 - Current Opus model for long-running agentic coding and knowledge work. Adaptive thinking is always on
  • claude-opus-5 - Opus model for complex agentic coding and enterprise work
  • claude-sonnet-5-5 - Current Sonnet model for focused coding and knowledge work. Adaptive thinking is on by default, and forced tool choice is rejected on every request
  • claude-sonnet-5 - Most agentic Sonnet model with near-Opus performance at lower cost
  • claude-haiku-5-5 - Fast model for high-volume, latency-sensitive work. Adaptive thinking accepts max effort, and the API default effort is medium
  • 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 always-on for claude-opus-5-5, claude-fable-5-1, and claude-mythos-5-1, because adaptive thinking cannot be disabled. For every other registered Claude model, mode is optional and 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. On claude-opus-5-5, claude-sonnet-5-5, claude-fable-5-1, and claude-mythos-5-1 that restriction applies to every request, including requests that omit reasoning.
  • 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'].
  • tools.strictSchemas reports whether the model supports strict tool schemas. Supported models report { supported: true, maxStrictTools: 20, maxUnionParameters: 16 }.
  • tools.toolDiscovery is 'native' for Claude 4.5 and later models and 'emulated' for older ones. See Tool discovery.
  • messages.systemPlacement is 'before-reply' from Claude Opus 4.8, Sonnet 5, and Haiku 5.5 on, and 'leading' for earlier models. See System messages.

Strict tool schemas

Claude 4.5 and later models support per-tool strict: true and report { supported: true, maxStrictTools: 20, maxUnionParameters: 16 }. Both limits count only tools that set strict: true; exceeding one throws ToolSchemaStrictnessError locally. The Anthropic API enforces both limits, but Anthropic’s documentation pages do not list them:
  • At most 20 strict tools (“The maximum number of strict tools supported is 20”).
  • At most 16 union-typed parameters across the request’s strict tools (“limit: 16 parameters with unions”). Every property whose schema is an anyOf, a oneOf, or a type array with more than one entry counts, including nullable keys, in nested objects, array items, and anyOf and oneOf branches. Unions directly under items, enums with null, $defs, and the properties of an object whose type is an array do not count.
Older models — Claude Opus 4.1, Opus 4, Sonnet 4, Sonnet 3.7, and Claude 3.x — report { supported: false } and reject explicit strict: true locally. Unrecognized model IDs resolve optimistically to supported, so future Claude models work without a registry update. Only strict tools and structured-output schemas go through Anthropic’s schema normalization ($schema stripped, additionalProperties: false added, numeric and length constraints removed, oneOf rewritten to anyOf). Strict tools and structured output schemas also list nullable and defaulted keys in required, because Anthropic allows at most 24 optional parameters across a request’s strict tools. Anthropic also rejects a single strict schema it finds too complex, a limit it does not publish and core-ai cannot check. Non-strict tools are sent with their raw JSON Schema, so declared constraints reach the model as hints. Strict tool schemas do not change Anthropic’s structured response format for generateObject() and streamObject(). See Strict tool schemas for the schema contract, error reasons, and cross-provider behavior.

Tool discovery

Claude Opus 4.5, Sonnet 4.5, Haiku 4.5, and later models report tools.toolDiscovery: 'native', and so do unrecognized model IDs. Claude Opus 4.1, Opus 4, Sonnet 4, Sonnet 3.7, and Claude 3.x models report 'emulated'. Natively, discovered tools are declared as deferred tools (defer_loading: true), and each discovery result loads them with tool_reference blocks. Adding deferred tools keeps the cached prompt prefix, so a discovery keeps the prompt cache. Declaring the first deferred tool does change the prefix, so every native request also declares a deferred placeholder tool, core_ai_deferred_tools_placeholder, which the model never loads. Deferred loading is then active from the first request on, and the first discovery keeps the cache too. A result that loads tools holds only tool_reference blocks. An empty result is sent as text: its note, or that no tools were found. Set emulateToolDiscovery: true to declare discovered tools as ordinary tools instead, for example behind a proxy that does not forward deferred tools or tool_reference blocks:
See Tool Discovery for the agent loop and rules.

System messages

Leading system messages become text blocks in Anthropic’s top-level system field. Models that report 'before-reply' also accept a system message later in the conversation, sent in place as a role: 'system' message. It must directly follow a user or tool message and be the last message or be followed by an assistant message:
A later system message keeps the cached conversation prefix intact, unlike a change to the leading system messages. Claude Opus 4.7, Opus 4.6, Sonnet 4.6, Opus 4.5, Sonnet 4.5, Haiku 4.5, and older models report 'leading' and reject later system messages with UnsupportedSystemMessagePlacementError. Unrecognized model IDs resolve to 'before-reply'. System messages that are empty or contain only whitespace are dropped, because Anthropic rejects empty text blocks. One that sets cacheControl throws ValidationError, since a cache breakpoint needs a block to attach to.

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-1, claude-mythos-5-1, claude-fable-5, claude-mythos-5, claude-mythos-preview, claude-opus-5-5, claude-opus-5, claude-opus-4-8, claude-opus-4-7, claude-opus-4-6, claude-sonnet-5-5, claude-sonnet-5, claude-sonnet-4-6, and claude-haiku-5-5 support 'max' effort directly. On claude-opus-5-5, claude-fable-5-1, and claude-mythos-5-1, thinking cannot be disabled. Omit reasoning to use the model’s API default effort, or pass reasoning.effort to send adaptive thinking at that level. claude-opus-5-5 and claude-haiku-5-5 default to medium. claude-sonnet-5-5, claude-fable-5-1, and claude-mythos-5-1 default to high.

Manual thinking budget (Claude 4.5 and earlier)

Manual-thinking models take a token budget instead of an effort level. This library maps each effort to a budget. high and max are half and three quarters of the model’s output ceiling: The budget is spent out of maxTokens. If you set maxTokens (or defaultMaxTokens) at or below the budget, the request throws a ValidationError. The budget is never reduced to fit. Omit maxTokens to use the model’s output ceiling, which holds every budget. claude-opus-4-5 also accepts Anthropic’s effort parameter alongside manual thinking. To send it, pass it through providerOptions:

Output limits

maxTokens is the total output allowance: thinking and the visible answer together. When you omit it, the request uses the first of:
  1. defaultMaxTokens, if you set it on the provider
  2. The model’s output ceiling (model.capabilities.output.maxTokens)
  3. 4,096, for model ids without a known ceiling
Anthropic’s output-token rate limits count only generated tokens, so a high limit does not use up rate-limit capacity. generate() and generateObject() stream from the Messages API internally and return the same result as a non-streaming call. The Anthropic SDK requires streaming for requests whose output limit could take longer than ten minutes, which applies to these ceilings. A transient error that arrives mid-stream, such as overloaded_error, surfaces as the matching core-ai error (ModelOverloadedError) without an automatic SDK retry.

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 Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1, Claude Mythos 5.1, 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. Claude Haiku 5.5 rejects non-default sampling parameters on every request. Set temperature to 1 or topP to 0.99, and omit topK. A request cannot include both temperature and topP. Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1, and Claude Mythos 5.1 reject toolChoice: 'required' and toolChoice: { type: 'tool', toolName } on every request. 'auto' and 'none' remain valid. Claude Fable 5, Claude Mythos 5, and Claude Haiku 5.5 accept forced tool choice when reasoning is omitted.
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, cacheControl, and emulateToolDiscovery.
  • betas are sent through the anthropic-beta request header.
  • emulateToolDiscovery renders tool discovery with ordinary tools on models that support it natively. See Tool discovery.
System, user, and tool result messages accept their own options under the same key. The only field is cacheControl. See Message cache control.

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:

Message cache control

Set cacheControl on a system, user, tool result, or discovery result message to place an explicit cache breakpoint at the end of that message. Each breakpoint can use its own TTL. A common setup for agent loops caches the static system prompt for an hour and lets request-level caching follow the growing conversation:
The breakpoint goes on the last content block the message produces:
  • A user message with string content is sent as a single text block that carries the breakpoint.
  • A user message with content parts marks its last part.
  • A tool result or discovery result message marks its tool_result block. Consecutive tool results share one user turn, and each keeps its own breakpoint.
A user message with cacheControl must end with a non-empty part. An empty message or an empty last text part throws ValidationError, since Anthropic cannot place a cache breakpoint on an empty text block. Request-level caching looks back at most 20 blocks for an earlier cache entry. A run of consecutive tool calls or tool results counts as one block, but an agent step that adds more blocks than that (interleaved thinking, text and tool calls, or many images) pushes the previous step’s entry out of reach. Mark the last message the previous step sent so the next step can read it. That message can be a user message, a tool result, or a system message. Give the marker a TTL at least as long as the request-level one; with request-level ttl: '1h', set ttl: '1h' on the marker too:
Breakpoints follow Anthropic’s limits, checked before the request:
  • At most 4 breakpoints per request, request-level cacheControl included.
  • A 1h breakpoint cannot follow a 5m one. Message breakpoints apply in message order, and request-level cacheControl comes last.
  • When the last message sets cacheControl, request-level cacheControl must use the same TTL.
A request that breaks a limit throws ValidationError. A missing ttl means 5m. 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:
  • 512 tokens for Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1, and Claude Mythos 5.1
  • 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