🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@ai-sdk/anthropic

Package Overview
Dependencies
Maintainers
3
Versions
549
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/anthropic - npm Package Compare versions

Comparing version
3.0.101
to
3.0.102
+8
-0
CHANGELOG.md
# @ai-sdk/anthropic
## 3.0.102
### Patch Changes
- b4c4426: feat (provider/anthropic): support fallbacks 'default' mode, which routes safety classifier refusals to Anthropic's recommended fallback model (adds the server-side-fallback-2026-07-01 beta automatically)
- b4c4426: feat (provider/anthropic): support mid-conversation tool changes via the toolChanges system message provider option, emitting tool_addition/tool_removal content blocks and the mid-conversation-tool-changes-2026-07-01 beta
- b4c4426: feat (provider/anthropic): add claude-opus-5 model id with frontier-tier capabilities (128k output tokens, structured output, adaptive thinking, xhigh effort, sampling parameter rejection, thinking-disabled only at effort high or below)
## 3.0.101

@@ -4,0 +12,0 @@

+17
-4

@@ -187,3 +187,16 @@ import { JSONObject, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';

type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
/**
* Anthropic provider options for system messages.
*/
declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
type: z.ZodLiteral<"tool_addition">;
toolName: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
type: z.ZodLiteral<"tool_removal">;
toolName: z.ZodString;
}, z.core.$strip>]>>>;
}, z.core.$strip>;
type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessageProviderOptions>;
declare const anthropicLanguageModelOptions: z.ZodObject<{

@@ -255,3 +268,3 @@ sendReasoning: z.ZodOptional<z.ZodBoolean>;

}>>;
fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
fallbacks: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"default">, z.ZodArray<z.ZodObject<{
model: z.ZodString;

@@ -265,3 +278,3 @@ max_tokens: z.ZodOptional<z.ZodNumber>;

}>>;
}, z.core.$strip>>>;
}, z.core.$strip>>]>>;
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;

@@ -1230,2 +1243,2 @@ contextManagement: z.ZodOptional<z.ZodObject<{

export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicSystemMessageProviderOptions, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };

@@ -187,3 +187,16 @@ import { JSONObject, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';

type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
/**
* Anthropic provider options for system messages.
*/
declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
type: z.ZodLiteral<"tool_addition">;
toolName: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
type: z.ZodLiteral<"tool_removal">;
toolName: z.ZodString;
}, z.core.$strip>]>>>;
}, z.core.$strip>;
type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessageProviderOptions>;
declare const anthropicLanguageModelOptions: z.ZodObject<{

@@ -255,3 +268,3 @@ sendReasoning: z.ZodOptional<z.ZodBoolean>;

}>>;
fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
fallbacks: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"default">, z.ZodArray<z.ZodObject<{
model: z.ZodString;

@@ -265,3 +278,3 @@ max_tokens: z.ZodOptional<z.ZodNumber>;

}>>;
}, z.core.$strip>>>;
}, z.core.$strip>>]>>;
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;

@@ -1230,2 +1243,2 @@ contextManagement: z.ZodOptional<z.ZodObject<{

export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicSystemMessageProviderOptions, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
+2
-1

@@ -5,3 +5,3 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, JSONSchema7, SharedV3ProviderMetadata, SharedV3Warning } from '@ai-sdk/provider';

type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});

@@ -60,2 +60,3 @@ type AnthropicMessagesConfig = {

rejectsSamplingParameters: boolean;
rejectsThinkingDisabledAboveHighEffort: boolean;
isKnownModel: boolean;

@@ -62,0 +63,0 @@ };

@@ -5,3 +5,3 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, JSONSchema7, SharedV3ProviderMetadata, SharedV3Warning } from '@ai-sdk/provider';

type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});

@@ -60,2 +60,3 @@ type AnthropicMessagesConfig = {

rejectsSamplingParameters: boolean;
rejectsThinkingDisabledAboveHighEffort: boolean;
isKnownModel: boolean;

@@ -62,0 +63,0 @@ };

{
"name": "@ai-sdk/anthropic",
"version": "3.0.101",
"version": "3.0.102",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "sideEffects": false,

@@ -26,5 +26,18 @@ import type { JSONSchema7 } from '@ai-sdk/provider';

role: 'system';
content: Array<AnthropicTextContent>;
content: Array<AnthropicTextContent | AnthropicToolChangeContent>;
}
/**
* Mid-conversation tool change content block. Adds or removes a tool from the
* conversation's tool set without invalidating the prompt cache.
*
* Only valid inside system messages that appear in the `messages` array.
* Requires the `mid-conversation-tool-changes-2026-07-01` beta.
*/
export interface AnthropicToolChangeContent {
type: 'tool_addition' | 'tool_removal';
tool: { type: 'tool_reference'; name: string };
cache_control?: never;
}
export interface AnthropicUserMessage {

@@ -31,0 +44,0 @@ role: 'user';

@@ -22,2 +22,3 @@ import { z } from 'zod/v4';

| 'claude-opus-4-8'
| 'claude-opus-5'
| 'claude-fable-5'

@@ -63,2 +64,40 @@ | 'claude-sonnet-5'

/**
* Anthropic provider options for system messages.
*/
export const anthropicSystemMessageProviderOptions = z.object({
/**
* Mid-conversation tool changes. Adds or removes tools from the
* conversation's tool set between turns without invalidating the prompt
* cache.
*
* Only supported on system messages that appear mid-conversation (not the
* initial system prompt). A system message carrying tool changes must come
* right before an assistant message or at the end of the messages.
*
* Tools referenced by a `tool_addition` must be declared in the `tools`
* option (typically with `deferLoading: true` so they are not loaded until
* the addition surfaces them). The required
* `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
*/
toolChanges: z
.array(
z.discriminatedUnion('type', [
z.object({
type: z.literal('tool_addition'),
toolName: z.string(),
}),
z.object({
type: z.literal('tool_removal'),
toolName: z.string(),
}),
]),
)
.optional(),
});
export type AnthropicSystemMessageProviderOptions = z.infer<
typeof anthropicSystemMessageProviderOptions
>;
export const anthropicLanguageModelOptions = z.object({

@@ -232,27 +271,32 @@ /**

/**
* Server-side fallback chain.
* Server-side fallback configuration.
*
* When the primary model's safety classifiers block a turn, the API
* automatically retries it on the next model in the chain, server-side. A
* `content-filter` finish reason means the entire chain refused.
* automatically retries it server-side on a fallback model. A
* `content-filter` finish reason means the fallback(s) refused as well.
*
* Each entry is merged into the request as a direct request to that entry's
* model, so it must be formatted accordingly: `model` is required, and an
* entry may additionally override `max_tokens`, `thinking`, `output_config`,
* and `speed` for that attempt only (`speed` additionally requires the speed
* beta). The value is passed through to the API as-is.
*
* The required `server-side-fallback-2026-06-01` beta is added automatically
* when this option is set.
* - `'default'` (recommended): the API routes the retry to Anthropic's
* recommended fallback model based on the refusal category. Requires the
* `server-side-fallback-2026-07-01` beta, which is added automatically.
* - Array form: an explicit fallback chain. Each entry is merged into the
* request as a direct request to that entry's model, so it must be
* formatted accordingly: `model` is required, and an entry may
* additionally override `max_tokens`, `thinking`, `output_config`, and
* `speed` for that attempt only (`speed` additionally requires the speed
* beta). The value is passed through to the API as-is, and the
* `server-side-fallback-2026-06-01` beta is added automatically.
*/
fallbacks: z
.array(
z.object({
model: z.string(),
max_tokens: z.number().int().optional(),
thinking: z.record(z.string(), z.unknown()).optional(),
output_config: z.record(z.string(), z.unknown()).optional(),
speed: z.enum(['fast', 'standard']).optional(),
}),
)
.union([
z.literal('default'),
z.array(
z.object({
model: z.string(),
max_tokens: z.number().int().optional(),
thinking: z.record(z.string(), z.unknown()).optional(),
output_config: z.record(z.string(), z.unknown()).optional(),
speed: z.enum(['fast', 'standard']).optional(),
}),
),
])
.optional(),

@@ -259,0 +303,0 @@

@@ -23,2 +23,5 @@ import {

type AnthropicMessagesPrompt,
type AnthropicSystemMessage,
type AnthropicTextContent,
type AnthropicToolChangeContent,
type AnthropicToolResultContent,

@@ -29,3 +32,6 @@ type AnthropicUserMessage,

} from './anthropic-messages-api';
import { anthropicFilePartProviderOptions } from './anthropic-messages-options';
import {
anthropicFilePartProviderOptions,
anthropicSystemMessageProviderOptions,
} from './anthropic-messages-options';
import { CacheControlValidator } from './get-cache-control';

@@ -164,16 +170,62 @@ import { advisor_20260301OutputSchema } from './tool/advisor_20260301';

case 'system': {
const content = block.messages.map(({ content, providerOptions }) => ({
type: 'text' as const,
text: content,
cache_control: validator.getCacheControl(providerOptions, {
type: 'system message',
canCache: true,
}),
}));
const content: AnthropicSystemMessage['content'] = [];
let toolChangeCount = 0;
if (system == null) {
system = content;
for (const { content: text, providerOptions } of block.messages) {
const systemMessageOptions = await parseProviderOptions({
provider: 'anthropic',
providerOptions,
schema: anthropicSystemMessageProviderOptions,
});
const toolChanges = systemMessageOptions?.toolChanges ?? [];
// A system message that only carries tool changes may have empty
// text; do not emit an empty text block for it.
if (text !== '' || toolChanges.length === 0) {
content.push({
type: 'text' as const,
text,
cache_control: validator.getCacheControl(providerOptions, {
type: 'system message',
canCache: true,
}),
});
}
for (const toolChange of toolChanges) {
toolChangeCount++;
content.push({
type: toolChange.type,
tool: {
type: 'tool_reference',
name: toolNameMapping.toProviderToolName(toolChange.toolName),
},
} satisfies AnthropicToolChangeContent);
}
}
// The first block becomes the top-level system prompt. Later system
// blocks are sent as inline system messages — always when they carry
// tool changes (which are only valid mid-conversation), and otherwise
// only when a top-level system prompt already exists (preserving the
// existing hoisting behavior for plain text).
if (i === 0 || (system == null && toolChangeCount === 0)) {
if (toolChangeCount > 0) {
warnings.push({
type: 'other',
message:
'tool changes on the initial system message are not supported by Anthropic. ' +
'Configure the initial tool set via the tools option instead. ' +
'The tool changes have been ignored.',
});
}
system = content.filter(
(part): part is AnthropicTextContent => part.type === 'text',
);
} else {
messages.push({ role: 'system', content });
betas.add('mid-conversation-system-2026-04-07');
if (toolChangeCount > 0) {
betas.add('mid-conversation-tool-changes-2026-07-01');
}
}

@@ -180,0 +232,0 @@

@@ -9,2 +9,3 @@ export type {

AnthropicLanguageModelOptions as AnthropicProviderOptions,
AnthropicSystemMessageProviderOptions,
} from './anthropic-messages-options';

@@ -11,0 +12,0 @@ export type { AnthropicToolOptions } from './anthropic-prepare-tools';

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display