@ai-sdk/anthropic 4.0.71 → 4.0.73
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 +35 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +12 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +48 -11
- package/package.json +5 -5
- package/src/anthropic-batch.ts +2 -0
- package/src/anthropic-files.ts +3 -1
- package/src/anthropic-language-model.ts +13 -0
- package/src/anthropic-provider.ts +20 -7
- package/src/convert-to-anthropic-prompt.ts +1 -0
- package/src/skills/anthropic-skills.ts +5 -1
package/docs/05-anthropic.mdx
CHANGED
|
@@ -33,6 +33,15 @@ const anthropic = createAnthropic({
|
|
|
33
33
|
|
|
34
34
|
You can use the following optional settings to customize the Anthropic provider instance:
|
|
35
35
|
|
|
36
|
+
- **batchResultDownloads** _object_
|
|
37
|
+
|
|
38
|
+
Settings for downloading JSON Lines batch results.
|
|
39
|
+
- **maxLineBytes** _number_
|
|
40
|
+
|
|
41
|
+
Maximum UTF-8 bytes per row, excluding the LF delimiter. Defaults to 64 MiB
|
|
42
|
+
(67,108,864 bytes). Must be a positive safe integer. Oversized rows throw a
|
|
43
|
+
`DownloadError` and cancel the download.
|
|
44
|
+
|
|
36
45
|
- **baseURL** _string_
|
|
37
46
|
|
|
38
47
|
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
@@ -93,6 +102,34 @@ Anthropic language models can also be used in the `streamText` function
|
|
|
93
102
|
and support structured data generation with [`Output`](/docs/reference/ai-sdk-core/output)
|
|
94
103
|
(see [AI SDK Core](/docs/ai-sdk-core)).
|
|
95
104
|
|
|
105
|
+
### Message-start events
|
|
106
|
+
|
|
107
|
+
During streaming, each Anthropic `message_start` event is exposed as an
|
|
108
|
+
`anthropic.message_start` custom stream part containing the message ID, model,
|
|
109
|
+
and raw initial token usage. No provider option is required.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
113
|
+
import { streamText } from 'ai';
|
|
114
|
+
|
|
115
|
+
const result = streamText({
|
|
116
|
+
model: anthropic('claude-haiku-4-5'),
|
|
117
|
+
prompt: 'Say hi in one word.',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
for await (const part of result.fullStream) {
|
|
121
|
+
if (part.type === 'custom' && part.kind === 'anthropic.message_start') {
|
|
122
|
+
console.log(part.providerMetadata?.anthropic);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Initial usage may be incomplete; use `result.usage` for final token counts.
|
|
128
|
+
Like other custom parts, this event is included in response content and forwarded
|
|
129
|
+
to UI message streams. It is ignored when replaying conversation history to Anthropic.
|
|
130
|
+
|
|
131
|
+
### Provider options
|
|
132
|
+
|
|
96
133
|
The following optional provider options are available for Anthropic models:
|
|
97
134
|
|
|
98
135
|
- `disableParallelToolUse` _boolean_
|
|
@@ -1334,7 +1371,7 @@ together with an older `computer_*` tool.
|
|
|
1334
1371
|
|
|
1335
1372
|
Parameters:
|
|
1336
1373
|
|
|
1337
|
-
- `action` ('key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'screenshot' | 'cursor_position' | 'zoom'): The action to perform.
|
|
1374
|
+
- `action` ('key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'screenshot' | 'cursor_position' | 'zoom'): The action to perform. For versioned computer tools, the `zoom` action is only available with `computer_20251124`. It is also available with `computerToolset_20260801`, where it is enabled by default.
|
|
1338
1375
|
- `coordinate` (number[], optional): Required for `mouse_move` and `left_click_drag` actions. Specifies the (x, y) coordinates.
|
|
1339
1376
|
- `text` (string, optional): Required for `type` and `key` actions.
|
|
1340
1377
|
- `region` (number[], optional): Required for `zoom` action. Specifies `[x1, y1, x2, y2]` coordinates for the area to inspect.
|
|
@@ -2231,18 +2268,18 @@ and the `mediaType` should be set to `'application/pdf'`.
|
|
|
2231
2268
|
any available provider model ID as a string if needed.
|
|
2232
2269
|
</Note>
|
|
2233
2270
|
|
|
2234
|
-
##
|
|
2271
|
+
## Decision Models
|
|
2235
2272
|
|
|
2236
|
-
Create an experimental
|
|
2273
|
+
Create an experimental decision model with `anthropic.decisionModel(modelId)`.
|
|
2237
2274
|
It uses the Messages API's structured-output support for Choice, Score, and Boolean
|
|
2238
2275
|
questions. `claude-haiku-4-5-20251001` is one supported model.
|
|
2239
2276
|
|
|
2240
2277
|
```ts
|
|
2241
2278
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
2242
|
-
import {
|
|
2279
|
+
import { experimental_decide } from 'ai';
|
|
2243
2280
|
|
|
2244
|
-
const { answers } = await
|
|
2245
|
-
model: anthropic.
|
|
2281
|
+
const { answers } = await experimental_decide({
|
|
2282
|
+
model: anthropic.decisionModel('claude-haiku-4-5-20251001'),
|
|
2246
2283
|
state: 'I was charged twice.',
|
|
2247
2284
|
questions: {
|
|
2248
2285
|
requestsRefund: {
|
|
@@ -2272,10 +2309,10 @@ It respects
|
|
|
2272
2309
|
`structuredOutputMode`. Supported models use native structured output by default;
|
|
2273
2310
|
`jsonTool` uses the existing Messages JSON-tool fallback. Usage, warnings,
|
|
2274
2311
|
response information, and provider metadata are preserved.
|
|
2275
|
-
See [
|
|
2312
|
+
See [Decisions](/docs/ai-sdk-core/decisions).
|
|
2276
2313
|
|
|
2277
|
-
|
|
2278
|
-
`createProviderRegistry().
|
|
2314
|
+
Decision models can also be accessed through `customProvider` aliases or
|
|
2315
|
+
`createProviderRegistry().decisionModel('provider:model')`. Direct string IDs
|
|
2279
2316
|
use Gateway by default, or an explicitly configured default provider with an
|
|
2280
|
-
`
|
|
2281
|
-
[model aliases and registries](/docs/ai-sdk-core/
|
|
2317
|
+
`decisionModel` method. See
|
|
2318
|
+
[model aliases and registries](/docs/ai-sdk-core/decisions#model-aliases-and-registries).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.73",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.23",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.55"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@ai-sdk/test-server": "2.0.
|
|
42
|
+
"@ai-sdk/test-server": "2.0.4",
|
|
43
43
|
"@types/node": "22.19.19",
|
|
44
44
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
45
45
|
"tsdown": "^0.23.0",
|
|
46
|
-
"typescript": "
|
|
46
|
+
"typescript": "6.0.3",
|
|
47
47
|
"zod": "3.25.76"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
package/src/anthropic-batch.ts
CHANGED
|
@@ -189,6 +189,7 @@ export class AnthropicBatch implements BatchV4<{
|
|
|
189
189
|
provider: string;
|
|
190
190
|
config: AnthropicLanguageModelConfig;
|
|
191
191
|
supportedUrls: Record<string, RegExp[]>;
|
|
192
|
+
maxLineBytes?: number;
|
|
192
193
|
},
|
|
193
194
|
) {
|
|
194
195
|
this.provider = options.provider;
|
|
@@ -409,6 +410,7 @@ export class AnthropicBatch implements BatchV4<{
|
|
|
409
410
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
410
411
|
successfulResponseHandler: createJsonLinesResponseHandler(
|
|
411
412
|
anthropicBatchResultLineSchema,
|
|
413
|
+
{ maxLineBytes: this.options.maxLineBytes },
|
|
412
414
|
),
|
|
413
415
|
abortSignal: options.abortSignal,
|
|
414
416
|
fetch: this.options.config.fetch,
|
package/src/anthropic-files.ts
CHANGED
|
@@ -54,7 +54,9 @@ export class AnthropicFiles implements FilesV4 {
|
|
|
54
54
|
}: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult> {
|
|
55
55
|
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
56
56
|
|
|
57
|
-
const blob = new Blob([fileBytes], {
|
|
57
|
+
const blob = new Blob([fileBytes as Uint8Array<ArrayBuffer>], {
|
|
58
|
+
type: mediaType,
|
|
59
|
+
});
|
|
58
60
|
|
|
59
61
|
const formData = new FormData();
|
|
60
62
|
if (filename != null) {
|
|
@@ -2906,6 +2906,18 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
2906
2906
|
modelId: value.message.model ?? undefined,
|
|
2907
2907
|
});
|
|
2908
2908
|
|
|
2909
|
+
controller.enqueue({
|
|
2910
|
+
type: 'custom',
|
|
2911
|
+
kind: 'anthropic.message_start',
|
|
2912
|
+
providerMetadata: {
|
|
2913
|
+
anthropic: {
|
|
2914
|
+
id: value.message.id ?? null,
|
|
2915
|
+
model: value.message.model ?? null,
|
|
2916
|
+
usage: rawUsage,
|
|
2917
|
+
},
|
|
2918
|
+
},
|
|
2919
|
+
});
|
|
2920
|
+
|
|
2909
2921
|
// Programmatic tool calling: process pre-populated content blocks
|
|
2910
2922
|
// (for deferred tool calls, content may be in message_start)
|
|
2911
2923
|
if (value.message.content != null) {
|
|
@@ -3484,6 +3496,7 @@ function resolveAnthropicReasoningConfig({
|
|
|
3484
3496
|
medium: 'medium' as const,
|
|
3485
3497
|
high: 'high' as const,
|
|
3486
3498
|
xhigh: supportsXhighEffort ? ('xhigh' as const) : ('max' as const),
|
|
3499
|
+
max: 'max' as const,
|
|
3487
3500
|
},
|
|
3488
3501
|
warnings,
|
|
3489
3502
|
});
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
InvalidArgumentError,
|
|
3
3
|
NoSuchModelError,
|
|
4
4
|
type Experimental_BatchV4 as BatchV4,
|
|
5
|
-
type
|
|
5
|
+
type Experimental_DecisionModelV4 as DecisionModelV4,
|
|
6
6
|
type FilesV4,
|
|
7
7
|
type LanguageModelV4,
|
|
8
8
|
type ProviderV4,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
withUserAgentSuffix,
|
|
18
18
|
type FetchFunction,
|
|
19
19
|
} from '@ai-sdk/provider-utils';
|
|
20
|
-
import {
|
|
20
|
+
import { Experimental_DecisionLanguageModel as DecisionLanguageModel } from '@ai-sdk/provider-utils/experimental-decision';
|
|
21
21
|
import { AnthropicFiles } from './anthropic-files';
|
|
22
22
|
import { AnthropicLanguageModel } from './anthropic-language-model';
|
|
23
23
|
import { AnthropicBatch } from './anthropic-batch';
|
|
@@ -54,8 +54,12 @@ export interface AnthropicProvider extends ProviderV4 {
|
|
|
54
54
|
|
|
55
55
|
messages(modelId: AnthropicModelId): LanguageModelV4;
|
|
56
56
|
|
|
57
|
-
/** Creates an experimental Choice/Score/Boolean
|
|
58
|
-
|
|
57
|
+
/** Creates an experimental Choice/Score/Boolean decision model using Messages. */
|
|
58
|
+
decisionModel(modelId: AnthropicModelId): DecisionModelV4;
|
|
59
|
+
/** @deprecated Use `decisionModel` instead. */
|
|
60
|
+
evaluationModel(modelId: AnthropicModelId): DecisionModelV4 & {
|
|
61
|
+
doEvaluate: DecisionModelV4['doDecide'];
|
|
62
|
+
};
|
|
59
63
|
|
|
60
64
|
experimental_batch(): BatchV4<{ text: AnthropicModelId }>;
|
|
61
65
|
|
|
@@ -78,6 +82,12 @@ export interface AnthropicProvider extends ProviderV4 {
|
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
export interface AnthropicProviderSettings {
|
|
85
|
+
/** Settings for downloading JSON Lines batch results. */
|
|
86
|
+
batchResultDownloads?: {
|
|
87
|
+
/** Maximum UTF-8 bytes per row, excluding LF. Defaults to 64 MiB. */
|
|
88
|
+
maxLineBytes?: number;
|
|
89
|
+
};
|
|
90
|
+
|
|
81
91
|
/**
|
|
82
92
|
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
83
93
|
* The default prefix is `https://api.anthropic.com/v1`.
|
|
@@ -183,6 +193,7 @@ export function createAnthropic(
|
|
|
183
193
|
const createBatch = () =>
|
|
184
194
|
new AnthropicBatch({
|
|
185
195
|
provider: `${providerName.replace(/\.messages$/, '')}.batch`,
|
|
196
|
+
maxLineBytes: options.batchResultDownloads?.maxLineBytes,
|
|
186
197
|
config: languageModelConfig,
|
|
187
198
|
supportedUrls,
|
|
188
199
|
});
|
|
@@ -209,11 +220,13 @@ export function createAnthropic(
|
|
|
209
220
|
provider.languageModel = createChatModel;
|
|
210
221
|
provider.chat = createChatModel;
|
|
211
222
|
provider.messages = createChatModel;
|
|
212
|
-
provider.
|
|
213
|
-
new
|
|
223
|
+
provider.decisionModel = (modelId: AnthropicModelId) =>
|
|
224
|
+
new DecisionLanguageModel({
|
|
214
225
|
model: createChatModel(modelId),
|
|
215
|
-
provider: `${providerName.replace(/\.messages$/, '')}.
|
|
226
|
+
provider: `${providerName.replace(/\.messages$/, '')}.decision`,
|
|
216
227
|
});
|
|
228
|
+
provider.evaluationModel =
|
|
229
|
+
provider.decisionModel as AnthropicProvider['evaluationModel'];
|
|
217
230
|
provider.experimental_batch = createBatch;
|
|
218
231
|
|
|
219
232
|
provider.embeddingModel = (modelId: string) => {
|
|
@@ -89,7 +89,11 @@ export class AnthropicSkills implements SkillsV4 {
|
|
|
89
89
|
|
|
90
90
|
for (const file of params.files) {
|
|
91
91
|
const content = convertInlineFileDataToUint8Array(file.data);
|
|
92
|
-
formData.append(
|
|
92
|
+
formData.append(
|
|
93
|
+
'files[]',
|
|
94
|
+
new Blob([content as Uint8Array<ArrayBuffer>]),
|
|
95
|
+
file.path,
|
|
96
|
+
);
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
const headers = await this.getHeaders();
|