@ai-sdk/anthropic 4.0.71 → 4.0.72
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.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +10 -0
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +39 -11
- package/package.json +3 -3
- package/src/anthropic-language-model.ts +12 -0
- package/src/anthropic-provider.ts +13 -7
- package/src/convert-to-anthropic-prompt.ts +1 -0
package/docs/05-anthropic.mdx
CHANGED
|
@@ -93,6 +93,34 @@ Anthropic language models can also be used in the `streamText` function
|
|
|
93
93
|
and support structured data generation with [`Output`](/docs/reference/ai-sdk-core/output)
|
|
94
94
|
(see [AI SDK Core](/docs/ai-sdk-core)).
|
|
95
95
|
|
|
96
|
+
### Message-start events
|
|
97
|
+
|
|
98
|
+
During streaming, each Anthropic `message_start` event is exposed as an
|
|
99
|
+
`anthropic.message_start` custom stream part containing the message ID, model,
|
|
100
|
+
and raw initial token usage. No provider option is required.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
104
|
+
import { streamText } from 'ai';
|
|
105
|
+
|
|
106
|
+
const result = streamText({
|
|
107
|
+
model: anthropic('claude-haiku-4-5'),
|
|
108
|
+
prompt: 'Say hi in one word.',
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
for await (const part of result.fullStream) {
|
|
112
|
+
if (part.type === 'custom' && part.kind === 'anthropic.message_start') {
|
|
113
|
+
console.log(part.providerMetadata?.anthropic);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Initial usage may be incomplete; use `result.usage` for final token counts.
|
|
119
|
+
Like other custom parts, this event is included in response content and forwarded
|
|
120
|
+
to UI message streams. It is ignored when replaying conversation history to Anthropic.
|
|
121
|
+
|
|
122
|
+
### Provider options
|
|
123
|
+
|
|
96
124
|
The following optional provider options are available for Anthropic models:
|
|
97
125
|
|
|
98
126
|
- `disableParallelToolUse` _boolean_
|
|
@@ -1334,7 +1362,7 @@ together with an older `computer_*` tool.
|
|
|
1334
1362
|
|
|
1335
1363
|
Parameters:
|
|
1336
1364
|
|
|
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.
|
|
1365
|
+
- `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
1366
|
- `coordinate` (number[], optional): Required for `mouse_move` and `left_click_drag` actions. Specifies the (x, y) coordinates.
|
|
1339
1367
|
- `text` (string, optional): Required for `type` and `key` actions.
|
|
1340
1368
|
- `region` (number[], optional): Required for `zoom` action. Specifies `[x1, y1, x2, y2]` coordinates for the area to inspect.
|
|
@@ -2231,18 +2259,18 @@ and the `mediaType` should be set to `'application/pdf'`.
|
|
|
2231
2259
|
any available provider model ID as a string if needed.
|
|
2232
2260
|
</Note>
|
|
2233
2261
|
|
|
2234
|
-
##
|
|
2262
|
+
## Decision Models
|
|
2235
2263
|
|
|
2236
|
-
Create an experimental
|
|
2264
|
+
Create an experimental decision model with `anthropic.decisionModel(modelId)`.
|
|
2237
2265
|
It uses the Messages API's structured-output support for Choice, Score, and Boolean
|
|
2238
2266
|
questions. `claude-haiku-4-5-20251001` is one supported model.
|
|
2239
2267
|
|
|
2240
2268
|
```ts
|
|
2241
2269
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
2242
|
-
import {
|
|
2270
|
+
import { experimental_decide } from 'ai';
|
|
2243
2271
|
|
|
2244
|
-
const { answers } = await
|
|
2245
|
-
model: anthropic.
|
|
2272
|
+
const { answers } = await experimental_decide({
|
|
2273
|
+
model: anthropic.decisionModel('claude-haiku-4-5-20251001'),
|
|
2246
2274
|
state: 'I was charged twice.',
|
|
2247
2275
|
questions: {
|
|
2248
2276
|
requestsRefund: {
|
|
@@ -2272,10 +2300,10 @@ It respects
|
|
|
2272
2300
|
`structuredOutputMode`. Supported models use native structured output by default;
|
|
2273
2301
|
`jsonTool` uses the existing Messages JSON-tool fallback. Usage, warnings,
|
|
2274
2302
|
response information, and provider metadata are preserved.
|
|
2275
|
-
See [
|
|
2303
|
+
See [Decisions](/docs/ai-sdk-core/decisions).
|
|
2276
2304
|
|
|
2277
|
-
|
|
2278
|
-
`createProviderRegistry().
|
|
2305
|
+
Decision models can also be accessed through `customProvider` aliases or
|
|
2306
|
+
`createProviderRegistry().decisionModel('provider:model')`. Direct string IDs
|
|
2279
2307
|
use Gateway by default, or an explicitly configured default provider with an
|
|
2280
|
-
`
|
|
2281
|
-
[model aliases and registries](/docs/ai-sdk-core/
|
|
2308
|
+
`decisionModel` method. See
|
|
2309
|
+
[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.72",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
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.22",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.54"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.3",
|
|
@@ -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) {
|
|
@@ -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
|
|
|
@@ -209,11 +213,13 @@ export function createAnthropic(
|
|
|
209
213
|
provider.languageModel = createChatModel;
|
|
210
214
|
provider.chat = createChatModel;
|
|
211
215
|
provider.messages = createChatModel;
|
|
212
|
-
provider.
|
|
213
|
-
new
|
|
216
|
+
provider.decisionModel = (modelId: AnthropicModelId) =>
|
|
217
|
+
new DecisionLanguageModel({
|
|
214
218
|
model: createChatModel(modelId),
|
|
215
|
-
provider: `${providerName.replace(/\.messages$/, '')}.
|
|
219
|
+
provider: `${providerName.replace(/\.messages$/, '')}.decision`,
|
|
216
220
|
});
|
|
221
|
+
provider.evaluationModel =
|
|
222
|
+
provider.decisionModel as AnthropicProvider['evaluationModel'];
|
|
217
223
|
provider.experimental_batch = createBatch;
|
|
218
224
|
|
|
219
225
|
provider.embeddingModel = (modelId: string) => {
|