Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/clean-students-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@ai-sdk/amazon-bedrock': patch
'@ai-sdk/gateway': patch
'@ai-sdk/google-vertex': patch
'@ai-sdk/anthropic': patch
---

feat(provider/anthropic): add support for new Claude Sonnet 4.6 model
1 change: 1 addition & 0 deletions content/docs/02-foundations/02-providers-and-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Here are the capabilities of popular models:
| [OpenAI](/providers/ai-sdk-providers/openai) | `gpt-5-codex` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [OpenAI](/providers/ai-sdk-providers/openai) | `gpt-5-chat-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-sonnet-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-1` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
Expand Down
84 changes: 73 additions & 11 deletions content/providers/01-ai-sdk-providers/05-anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,67 @@ for await (const part of result.textStream) {
}
```

### Programmatic Tool Calling
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think programmatic tool calling is available in v5.. might have to remove this docs section

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point, hadn't considered that yet. I can see code_execution_20250825 in https://github.com/vercel/ai/blob/release-v5.0/packages/anthropic/src/anthropic-prepare-tools.ts#L73 - wouldn't that mean it is in v5, or does it require something else?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in 9012fb8


[Programmatic Tool Calling](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/programmatic-tool-calling) allows Claude to write code that calls your tools programmatically within a code execution container, rather than requiring round trips through the model for each tool invocation. This reduces latency for multi-tool workflows and decreases token consumption.

To enable programmatic tool calling, use the `allowedCallers` provider option on tools that you want to be callable from within code execution:

```ts highlight="13-17"
import {
anthropic,
forwardAnthropicContainerIdFromLastStep,
} from '@ai-sdk/anthropic';
import { generateText, tool, stepCountIs } from 'ai';
import { z } from 'zod';

const result = await generateText({
model: anthropic('claude-sonnet-4-5'),
stopWhen: stepCountIs(10),
prompt:
'Get the weather for Tokyo, Sydney, and London, then calculate the average temperature.',
tools: {
code_execution: anthropic.tools.codeExecution_20250825(),

getWeather: tool({
description: 'Get current weather data for a city.',
inputSchema: z.object({
city: z.string().describe('Name of the city'),
}),
execute: async ({ city }) => {
// Your weather API implementation
return { temp: 22, condition: 'Sunny' };
},
// Enable this tool to be called from within code execution
providerOptions: {
anthropic: {
allowedCallers: ['code_execution_20250825'],
},
},
}),
},

// Propagate container ID between steps for code execution continuity
prepareStep: forwardAnthropicContainerIdFromLastStep,
});
```

In this flow:

1. Claude writes Python code that calls your `getWeather` tool multiple times in parallel
2. The SDK automatically executes your tool and returns results to the code execution container
3. Claude processes the results in code and generates the final response

<Note>
Programmatic tool calling requires `claude-sonnet-4-6`, `claude-sonnet-4-5`,
`claude-opus-4-6`, or `claude-opus-4-5` models and uses the
`code_execution_20250825` tool.
</Note>

#### Container Persistence

When using programmatic tool calling across multiple steps, you need to preserve the container ID between steps using `prepareStep`. You can use the `forwardAnthropicContainerIdFromLastStep` helper function to do this automatically. The container ID is available in `providerMetadata.anthropic.container.id` after each step completes.

## Agent Skills

[Anthropic Agent Skills](https://docs.claude.com/en/docs/agents-and-tools/agent-skills/overview) enable Claude to perform specialized tasks like document processing (PPTX, DOCX, PDF, XLSX) and data analysis. Skills run in a sandboxed container and require the code execution tool to be enabled.
Expand Down Expand Up @@ -993,17 +1054,18 @@ and the `mediaType` should be set to `'application/pdf'`.

### Model Capabilities

| Model | Image Input | Object Generation | Tool Usage | Computer Use | Web Search |
| -------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| `claude-opus-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-opus-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-haiku-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-sonnet-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-opus-4-1` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-opus-4-0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-sonnet-4-0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-3-7-sonnet-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-3-5-haiku-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| Model | Image Input | Object Generation | Tool Usage | Computer Use | Web Search | Tool Search | Compaction |
| -------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| `claude-opus-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `claude-sonnet-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
| `claude-opus-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
| `claude-haiku-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | | |
| `claude-sonnet-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
| `claude-opus-4-1` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | | |
| `claude-opus-4-0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | | |
| `claude-sonnet-4-0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | | |
| `claude-3-7-sonnet-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | | |
| `claude-3-5-haiku-latest` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | | |

<Note>
The table above lists popular models. Please see the [Anthropic
Expand Down
1 change: 1 addition & 0 deletions content/providers/01-ai-sdk-providers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Not all providers support all AI SDK features. Here's a quick comparison of the
| [OpenAI](/providers/ai-sdk-providers/openai) | `gpt-5.1-codex-mini` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [OpenAI](/providers/ai-sdk-providers/openai) | `gpt-5.1-codex` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-sonnet-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-1` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| [Anthropic](/providers/ai-sdk-providers/anthropic) | `claude-opus-4-0` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
Expand Down
2 changes: 1 addition & 1 deletion examples/ai-core/src/generate-text/anthropic-reasoning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dotenv/config';

async function main() {
const result = await generateText({
model: anthropic('claude-3-7-sonnet-20250219'),
model: anthropic('claude-sonnet-4-6'),
prompt: 'How many "r"s are in the word "strawberry"?',
temperature: 0.5, // should get ignored (warning)
providerOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ run(async () => {
}
}
},
model: anthropic('claude-haiku-4-5'),
model: anthropic('claude-sonnet-4-6'),
messages: [
{ role: 'user', content: 'What is the weather in San Francisco?' },
{
Expand Down
2 changes: 1 addition & 1 deletion examples/ai-core/src/stream-text/anthropic-reasoning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dotenv/config';

async function main() {
const result = streamText({
model: anthropic('claude-3-7-sonnet-20250219'),
model: anthropic('claude-sonnet-4-6'),
prompt: 'How many "r"s are in the word "strawberry"?',
temperature: 0.5, // should get ignored (warning)
onError: error => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {
anthropic,
type AnthropicLanguageModelOptions,
Copy link
Copy Markdown
Contributor

@vercel vercel bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example file imports non-existent type AnthropicLanguageModelOptions from @ai-sdk/anthropic, causing a TypeScript compilation error.

Fix on Vercel

} from '@ai-sdk/anthropic';
import { generateText, tool } from 'ai';
import { z } from 'zod';
import { run } from '../lib/run';

run(async () => {
const result = await generateText({
model: anthropic('claude-sonnet-4-6'),
messages: [
{
role: 'user',
content: 'What is the weather in San Francisco?',
},
{
role: 'assistant',
content: [
{
type: 'tool-call',
toolCallId: 'tool_1',
toolName: 'weather',
input: { location: 'San Francisco' },
},
],
},
{
role: 'tool',
content: [
{
type: 'tool-result',
toolCallId: 'tool_1',
toolName: 'weather',
output: {
type: 'json',
value: { temperature: 72, condition: 'sunny' },
},
},
],
},
{
role: 'user',
content: 'What about New York?',
},
{
role: 'assistant',
content: [
{
type: 'tool-call',
toolCallId: 'tool_2',
toolName: 'weather',
input: { location: 'New York' },
},
],
},
{
role: 'tool',
content: [
{
type: 'tool-result',
toolCallId: 'tool_2',
toolName: 'weather',
output: {
type: 'json',
value: { temperature: 65, condition: 'cloudy' },
},
},
],
},
{
role: 'user',
content: 'compare the two cities.',
},
],
tools: {
weather: tool({
description: 'Get the weather of a location',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for'),
}),
execute: async ({ location }) => ({
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
condition: 'sunny',
}),
}),
},
providerOptions: {
anthropic: {
contextManagement: {
edits: [
{
type: 'clear_tool_uses_20250919',
trigger: {
type: 'input_tokens',
value: 1000,
},
keep: {
type: 'tool_uses',
value: 1,
},
clearAtLeast: {
type: 'input_tokens',
value: 500,
},
clearToolInputs: true,
excludeTools: ['important_tool'],
},
],
},
} satisfies AnthropicLanguageModelOptions,
},
});

console.log('request body:', JSON.stringify(result.request.body, null, 2));
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type BedrockAnthropicModelId =
| 'anthropic.claude-opus-4-6-v1'
| 'anthropic.claude-sonnet-4-6-v1'
| 'anthropic.claude-opus-4-5-20251101-v1:0'
| 'anthropic.claude-sonnet-4-5-20250929-v1:0'
| 'anthropic.claude-opus-4-20250514-v1:0'
Expand All @@ -14,6 +15,7 @@ export type BedrockAnthropicModelId =
| 'anthropic.claude-3-sonnet-20240229-v1:0'
| 'anthropic.claude-3-haiku-20240307-v1:0'
| 'us.anthropic.claude-opus-4-6-v1'
| 'us.anthropic.claude-sonnet-4-6-v1'
| 'us.anthropic.claude-opus-4-5-20251101-v1:0'
| 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
| 'us.anthropic.claude-opus-4-20250514-v1:0'
Expand Down
5 changes: 4 additions & 1 deletion packages/anthropic/src/anthropic-messages-language-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,10 @@ function getModelCapabilities(modelId: string): {
supportsStructuredOutput: boolean;
isKnownModel: boolean;
} {
if (modelId.includes('claude-opus-4-6')) {
if (
modelId.includes('claude-sonnet-4-6') ||
modelId.includes('claude-opus-4-6')
) {
return {
maxOutputTokens: 128000,
supportsStructuredOutput: true,
Expand Down
5 changes: 3 additions & 2 deletions packages/anthropic/src/anthropic-messages-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type AnthropicMessagesModelId =
| 'claude-sonnet-4-20250514'
| 'claude-sonnet-4-5-20250929'
| 'claude-sonnet-4-5'
| 'claude-sonnet-4-6'
| 'claude-opus-4-6'
| (string & {});

Expand Down Expand Up @@ -79,11 +80,11 @@ export const anthropicProviderOptions = z.object({
thinking: z
.discriminatedUnion('type', [
z.object({
/** for Opus 4.6 and newer models */
/** for Sonnet 4.6, Opus 4.6, and newer models */
type: z.literal('adaptive'),
}),
z.object({
/** for models before Opus 4.6 */
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
type: z.literal('enabled'),
budgetTokens: z.number().optional(),
}),
Expand Down
1 change: 1 addition & 0 deletions packages/gateway/src/gateway-language-model-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type GatewayModelId =
| 'anthropic/claude-opus-4.6'
| 'anthropic/claude-sonnet-4'
| 'anthropic/claude-sonnet-4.5'
| 'anthropic/claude-sonnet-4.6'
| 'arcee-ai/trinity-large-preview'
| 'arcee-ai/trinity-mini'
| 'bytedance/seed-1.6'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude
export type GoogleVertexAnthropicMessagesModelId =
| 'claude-opus-4-6'
| 'claude-sonnet-4-6'
| 'claude-opus-4-5@20251101'
| 'claude-sonnet-4-5@20250929'
| 'claude-opus-4-1@20250805'
Expand Down
Loading