@ai-sdk/anthropic 3.0.79 → 3.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +36 -15
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +36 -15
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +5 -4
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +9 -1
- package/src/anthropic-messages-language-model.ts +34 -9
- package/src/anthropic-messages-options.ts +1 -0
- package/src/anthropic-tools.ts +1 -1
- package/src/convert-to-anthropic-messages-prompt.ts +9 -9
- package/src/tool/advisor_20260301.ts +1 -1
package/docs/05-anthropic.mdx
CHANGED
|
@@ -243,7 +243,7 @@ import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
|
|
|
243
243
|
import { generateText } from 'ai';
|
|
244
244
|
|
|
245
245
|
const { text } = await generateText({
|
|
246
|
-
model: anthropic('claude-opus-4-
|
|
246
|
+
model: anthropic('claude-opus-4-8'),
|
|
247
247
|
prompt: 'Research the pros and cons of Rust vs Go for building CLI tools.',
|
|
248
248
|
providerOptions: {
|
|
249
249
|
anthropic: {
|
|
@@ -342,7 +342,7 @@ Starting with `claude-opus-4-7`, thinking content is omitted from the response b
|
|
|
342
342
|
|
|
343
343
|
```ts highlight="5"
|
|
344
344
|
const { text, reasoningText } = await generateText({
|
|
345
|
-
model: anthropic('claude-opus-4-
|
|
345
|
+
model: anthropic('claude-opus-4-8'),
|
|
346
346
|
providerOptions: {
|
|
347
347
|
anthropic: {
|
|
348
348
|
thinking: { type: 'adaptive', display: 'summarized' },
|
|
@@ -971,7 +971,7 @@ const result = await generateText({
|
|
|
971
971
|
'Build a concurrent worker pool in Go with graceful shutdown. Outline the design first.',
|
|
972
972
|
tools: {
|
|
973
973
|
advisor: anthropic.tools.advisor_20260301({
|
|
974
|
-
model: 'claude-opus-4-
|
|
974
|
+
model: 'claude-opus-4-8',
|
|
975
975
|
maxUses: 3,
|
|
976
976
|
}),
|
|
977
977
|
},
|
|
@@ -989,7 +989,7 @@ The advisor tool supports the following configuration options:
|
|
|
989
989
|
|
|
990
990
|
- **model** _string_
|
|
991
991
|
|
|
992
|
-
Required. The advisor model ID, such as `claude-opus-4-
|
|
992
|
+
Required. The advisor model ID, such as `claude-opus-4-8`. The advisor model must be at least as capable as the executor model.
|
|
993
993
|
|
|
994
994
|
- **maxUses** _number_
|
|
995
995
|
|
|
@@ -1502,6 +1502,7 @@ and the `mediaType` should be set to `'application/pdf'`.
|
|
|
1502
1502
|
|
|
1503
1503
|
| Model | Image Input | Object Generation | Tool Usage | Computer Use | Web Search | Tool Search | Compaction |
|
|
1504
1504
|
| ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
1505
|
+
| `claude-opus-4-8` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
1505
1506
|
| `claude-opus-4-7` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
1506
1507
|
| `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} /> |
|
|
1507
1508
|
| `claude-sonnet-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
|
package/package.json
CHANGED
|
@@ -11,13 +11,21 @@ export type AnthropicMessagesPrompt = {
|
|
|
11
11
|
messages: AnthropicMessage[];
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export type AnthropicMessage =
|
|
14
|
+
export type AnthropicMessage =
|
|
15
|
+
| AnthropicUserMessage
|
|
16
|
+
| AnthropicAssistantMessage
|
|
17
|
+
| AnthropicSystemMessage;
|
|
15
18
|
|
|
16
19
|
export type AnthropicCacheControl = {
|
|
17
20
|
type: 'ephemeral';
|
|
18
21
|
ttl?: '5m' | '1h';
|
|
19
22
|
};
|
|
20
23
|
|
|
24
|
+
export interface AnthropicSystemMessage {
|
|
25
|
+
role: 'system';
|
|
26
|
+
content: Array<AnthropicTextContent>;
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
export interface AnthropicUserMessage {
|
|
22
30
|
role: 'user';
|
|
23
31
|
content: Array<
|
|
@@ -958,12 +958,23 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
958
958
|
part.name === 'text_editor_code_execution' ||
|
|
959
959
|
part.name === 'bash_code_execution'
|
|
960
960
|
) {
|
|
961
|
+
// map tool names for the code execution 20250825 tool:
|
|
962
|
+
// both map to 'code_execution'.
|
|
963
|
+
const providerToolName = 'code_execution';
|
|
961
964
|
content.push({
|
|
962
965
|
type: 'tool-call',
|
|
963
966
|
toolCallId: part.id,
|
|
964
967
|
toolName: toolNameMapping.toCustomToolName('code_execution'),
|
|
965
968
|
input: JSON.stringify({ type: part.name, ...part.input }),
|
|
966
969
|
providerExecuted: true,
|
|
970
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
971
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
972
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
973
|
+
// tool as dynamic.
|
|
974
|
+
...(markCodeExecutionDynamic &&
|
|
975
|
+
providerToolName === 'code_execution'
|
|
976
|
+
? { dynamic: true }
|
|
977
|
+
: {}),
|
|
967
978
|
});
|
|
968
979
|
} else if (
|
|
969
980
|
part.name === 'web_search' ||
|
|
@@ -986,8 +997,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
986
997
|
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
987
998
|
input: JSON.stringify(inputToSerialize),
|
|
988
999
|
providerExecuted: true,
|
|
989
|
-
//
|
|
990
|
-
//
|
|
1000
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
1001
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
1002
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
1003
|
+
// tool as dynamic.
|
|
991
1004
|
...(markCodeExecutionDynamic && part.name === 'code_execution'
|
|
992
1005
|
? { dynamic: true }
|
|
993
1006
|
: {}),
|
|
@@ -1642,12 +1655,16 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
1642
1655
|
toolName: customToolName,
|
|
1643
1656
|
input: finalInput,
|
|
1644
1657
|
providerExecuted: true,
|
|
1658
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
1659
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
1660
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
1661
|
+
// tool as dynamic.
|
|
1645
1662
|
...(markCodeExecutionDynamic &&
|
|
1646
1663
|
providerToolName === 'code_execution'
|
|
1647
1664
|
? { dynamic: true }
|
|
1648
1665
|
: {}),
|
|
1649
1666
|
firstDelta: true,
|
|
1650
|
-
providerToolName
|
|
1667
|
+
providerToolName,
|
|
1651
1668
|
};
|
|
1652
1669
|
|
|
1653
1670
|
controller.enqueue({
|
|
@@ -1655,6 +1672,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
1655
1672
|
id: part.id,
|
|
1656
1673
|
toolName: customToolName,
|
|
1657
1674
|
providerExecuted: true,
|
|
1675
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
1676
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
1677
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
1678
|
+
// tool as dynamic.
|
|
1658
1679
|
...(markCodeExecutionDynamic &&
|
|
1659
1680
|
providerToolName === 'code_execution'
|
|
1660
1681
|
? { dynamic: true }
|
|
@@ -2055,6 +2076,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
2055
2076
|
toolName: contentBlock.toolName,
|
|
2056
2077
|
input: finalInput,
|
|
2057
2078
|
providerExecuted: contentBlock.providerExecuted,
|
|
2079
|
+
// Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
|
|
2080
|
+
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
2081
|
+
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
2082
|
+
// tool as dynamic.
|
|
2058
2083
|
...(markCodeExecutionDynamic &&
|
|
2059
2084
|
contentBlock.providerToolName === 'code_execution'
|
|
2060
2085
|
? { dynamic: true }
|
|
@@ -2168,12 +2193,9 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
|
2168
2193
|
// the type to the delta and change the tool name.
|
|
2169
2194
|
if (
|
|
2170
2195
|
contentBlock.firstDelta &&
|
|
2171
|
-
|
|
2172
|
-
'bash_code_execution' ||
|
|
2173
|
-
contentBlock.providerToolName ===
|
|
2174
|
-
'text_editor_code_execution')
|
|
2196
|
+
contentBlock.providerToolName === 'code_execution'
|
|
2175
2197
|
) {
|
|
2176
|
-
delta = `{"type": "
|
|
2198
|
+
delta = `{"type": "programmatic-tool-call",${delta.substring(1)}`;
|
|
2177
2199
|
}
|
|
2178
2200
|
|
|
2179
2201
|
controller.enqueue({
|
|
@@ -2506,7 +2528,10 @@ function getModelCapabilities(modelId: string): {
|
|
|
2506
2528
|
rejectsSamplingParameters: boolean;
|
|
2507
2529
|
isKnownModel: boolean;
|
|
2508
2530
|
} {
|
|
2509
|
-
if (
|
|
2531
|
+
if (
|
|
2532
|
+
modelId.includes('claude-opus-4-8') ||
|
|
2533
|
+
modelId.includes('claude-opus-4-7')
|
|
2534
|
+
) {
|
|
2510
2535
|
return {
|
|
2511
2536
|
maxOutputTokens: 128000,
|
|
2512
2537
|
supportsStructuredOutput: true,
|
package/src/anthropic-tools.ts
CHANGED
|
@@ -42,7 +42,7 @@ export const anthropicTools = {
|
|
|
42
42
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
43
43
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
44
44
|
*
|
|
45
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
45
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
46
46
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
47
47
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
48
48
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|
|
@@ -157,15 +157,8 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
157
157
|
|
|
158
158
|
switch (type) {
|
|
159
159
|
case 'system': {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
functionality:
|
|
163
|
-
'Multiple system messages that are separated by user/assistant messages',
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
system = block.messages.map(({ content, providerOptions }) => ({
|
|
168
|
-
type: 'text',
|
|
160
|
+
const content = block.messages.map(({ content, providerOptions }) => ({
|
|
161
|
+
type: 'text' as const,
|
|
169
162
|
text: content,
|
|
170
163
|
cache_control: validator.getCacheControl(providerOptions, {
|
|
171
164
|
type: 'system message',
|
|
@@ -173,6 +166,13 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
173
166
|
}),
|
|
174
167
|
}));
|
|
175
168
|
|
|
169
|
+
if (system == null) {
|
|
170
|
+
system = content;
|
|
171
|
+
} else {
|
|
172
|
+
messages.push({ role: 'system', content });
|
|
173
|
+
betas.add('mid-conversation-system-2026-04-07');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
176
|
break;
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -77,7 +77,7 @@ const factory = createProviderToolFactoryWithOutputSchema<
|
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
79
|
/**
|
|
80
|
-
* The advisor model ID, such as `"claude-opus-4-
|
|
80
|
+
* The advisor model ID, such as `"claude-opus-4-8"`. Billed at this
|
|
81
81
|
* model's rates for the sub-inference.
|
|
82
82
|
*
|
|
83
83
|
* The advisor must be at least as capable as the executor; an invalid
|