@ai-sdk/anthropic 3.0.122 → 3.0.123
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 +9 -0
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +14 -10
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -10
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +33 -11
- package/package.json +3 -3
- package/src/anthropic-messages-options.ts +4 -5
- package/src/convert-to-anthropic-messages-prompt.ts +22 -8
package/docs/05-anthropic.mdx
CHANGED
|
@@ -1376,13 +1376,16 @@ This sends `tool_reference` blocks to Anthropic, which loads the corresponding d
|
|
|
1376
1376
|
|
|
1377
1377
|
### Mid-Conversation System Controls
|
|
1378
1378
|
|
|
1379
|
-
With `claude-opus-5-5` and `claude-fable-5-1`,
|
|
1380
|
-
|
|
1381
|
-
|
|
1379
|
+
With `claude-opus-5-5` and `claude-fable-5-1`, use an empty system message to
|
|
1380
|
+
change effort from the next user turn. A separate system message containing text
|
|
1381
|
+
can provide a turn-scoped reminder with `clearAt: 'next_user_message'`: its text
|
|
1382
|
+
applies until the next user message. Keep the reminder after a user turn and
|
|
1383
|
+
before an assistant turn, or at the end of the messages array.
|
|
1384
|
+
The provider adds the required
|
|
1382
1385
|
`mid-conversation-system-clear-at-2026-08-21` and
|
|
1383
1386
|
`mid-conversation-output-config-2026-07-01` beta headers automatically.
|
|
1384
1387
|
|
|
1385
|
-
```ts highlight="
|
|
1388
|
+
```ts highlight="16-24,29-37"
|
|
1386
1389
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
1387
1390
|
import { generateText } from 'ai';
|
|
1388
1391
|
|
|
@@ -1400,10 +1403,9 @@ const result = await generateText({
|
|
|
1400
1403
|
},
|
|
1401
1404
|
{
|
|
1402
1405
|
role: 'system',
|
|
1403
|
-
content: '
|
|
1406
|
+
content: '',
|
|
1404
1407
|
providerOptions: {
|
|
1405
1408
|
anthropic: {
|
|
1406
|
-
clearAt: 'next_user_message',
|
|
1407
1409
|
effort: 'high',
|
|
1408
1410
|
},
|
|
1409
1411
|
},
|
|
@@ -1412,19 +1414,39 @@ const result = await generateText({
|
|
|
1412
1414
|
role: 'user',
|
|
1413
1415
|
content: 'Complete the plan.',
|
|
1414
1416
|
},
|
|
1417
|
+
{
|
|
1418
|
+
role: 'system',
|
|
1419
|
+
content: 'For this turn, verify every compatibility claim.',
|
|
1420
|
+
providerOptions: {
|
|
1421
|
+
anthropic: {
|
|
1422
|
+
clearAt: 'next_user_message',
|
|
1423
|
+
},
|
|
1424
|
+
},
|
|
1425
|
+
},
|
|
1415
1426
|
],
|
|
1416
1427
|
});
|
|
1417
1428
|
```
|
|
1418
1429
|
|
|
1419
1430
|
An effort-only system message can use an empty content array at the API level;
|
|
1420
1431
|
in an AI SDK prompt, set `content: ''`. The provider serializes it as
|
|
1421
|
-
`content: []`.
|
|
1432
|
+
`content: []`. These effort-only messages can appear first or later in the
|
|
1433
|
+
conversation, including consecutively. The provider preserves their order. The new
|
|
1434
|
+
level applies from the next user turn until a later message changes it.
|
|
1435
|
+
Initial instruction text is sent in the top-level `system` field.
|
|
1436
|
+
|
|
1437
|
+
Consecutive inline system messages are evaluated as a group. If an effort-only
|
|
1438
|
+
message is adjacent to a system message containing text, the whole group must
|
|
1439
|
+
follow Anthropic's [content placement rules](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#limitations).
|
|
1440
|
+
|
|
1441
|
+
Turn-scoped messages with `clearAt` support text only. Put effort updates in a
|
|
1442
|
+
separate message, as in the example above.
|
|
1422
1443
|
|
|
1423
1444
|
<Note>
|
|
1424
|
-
`clearAt`
|
|
1425
|
-
messages
|
|
1426
|
-
and emits a warning. Use
|
|
1427
|
-
effort
|
|
1445
|
+
`clearAt` applies only to mid-conversation system messages. On initial system
|
|
1446
|
+
messages, the provider ignores `clearAt` and effort attached to non-empty
|
|
1447
|
+
content and emits a warning. Use an empty system message for an initial
|
|
1448
|
+
per-message effort setting, or the top-level `effort` provider option to
|
|
1449
|
+
configure effort for the full request.
|
|
1428
1450
|
</Note>
|
|
1429
1451
|
|
|
1430
1452
|
### Mid-Conversation Tool Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.123",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/provider": "3.0.
|
|
40
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
39
|
+
"@ai-sdk/provider": "3.0.18",
|
|
40
|
+
"@ai-sdk/provider-utils": "4.0.55"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
|
@@ -75,11 +75,10 @@ export const anthropicSystemMessageProviderOptions = z.object({
|
|
|
75
75
|
clearAt: z.literal('next_user_message').optional(),
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* which is added automatically.
|
|
78
|
+
* Sets the model effort from the next user turn until a later message
|
|
79
|
+
* changes it. An effort-only system message with empty content can appear
|
|
80
|
+
* first. The required `mid-conversation-output-config-2026-07-01` beta is
|
|
81
|
+
* added automatically.
|
|
83
82
|
*/
|
|
84
83
|
effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
|
|
85
84
|
|
|
@@ -247,14 +247,28 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
247
247
|
'The tool changes have been ignored.',
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
250
|
+
// Initial instruction text goes in the top-level system field.
|
|
251
|
+
// Effort-only messages stay in the messages array.
|
|
252
|
+
for (const message of systemMessages) {
|
|
253
|
+
if (
|
|
254
|
+
message.content.length === 0 &&
|
|
255
|
+
message.clear_at == null &&
|
|
256
|
+
message.output_config != null
|
|
257
|
+
) {
|
|
258
|
+
messages.push(message);
|
|
259
|
+
betas.add('mid-conversation-output-config-2026-07-01');
|
|
260
|
+
} else if (
|
|
261
|
+
message.clear_at != null ||
|
|
262
|
+
message.output_config != null
|
|
263
|
+
) {
|
|
264
|
+
warnings.push({
|
|
265
|
+
type: 'other',
|
|
266
|
+
message:
|
|
267
|
+
'clearAt and effort on this initial system message are not supported by Anthropic. ' +
|
|
268
|
+
'Use a separate effort-only system message with empty content to set effort. ' +
|
|
269
|
+
'These options have been ignored.',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
258
272
|
}
|
|
259
273
|
system = systemMessages.flatMap(message =>
|
|
260
274
|
message.content.filter(
|