@ai-sdk/anthropic 4.0.63 → 4.0.66

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.
@@ -1572,13 +1572,16 @@ This sends `tool_reference` blocks to Anthropic, which loads the corresponding d
1572
1572
 
1573
1573
  ### Mid-Conversation System Controls
1574
1574
 
1575
- With `claude-opus-5-5` and `claude-fable-5-1`, a mid-conversation system message
1576
- can be cleared before the next user message with `clearAt: 'next_user_message'`,
1577
- or set the effort for the next turn without invalidating the prompt cache. The provider adds the required
1575
+ With `claude-opus-5-5` and `claude-fable-5-1`, use an empty system message to
1576
+ change effort from the next user turn. A separate system message containing text
1577
+ can provide a turn-scoped reminder with `clearAt: 'next_user_message'`: its text
1578
+ applies until the next user message. Keep the reminder after a user turn and
1579
+ before an assistant turn, or at the end of the messages array.
1580
+ The provider adds the required
1578
1581
  `mid-conversation-system-clear-at-2026-08-21` and
1579
1582
  `mid-conversation-output-config-2026-07-01` beta headers automatically.
1580
1583
 
1581
- ```ts highlight="17-25"
1584
+ ```ts highlight="16-24,29-37"
1582
1585
  import { anthropic } from '@ai-sdk/anthropic';
1583
1586
  import { generateText } from 'ai';
1584
1587
 
@@ -1596,10 +1599,9 @@ const result = await generateText({
1596
1599
  },
1597
1600
  {
1598
1601
  role: 'system',
1599
- content: 'For the next turn, verify every compatibility claim.',
1602
+ content: '',
1600
1603
  providerOptions: {
1601
1604
  anthropic: {
1602
- clearAt: 'next_user_message',
1603
1605
  effort: 'high',
1604
1606
  },
1605
1607
  },
@@ -1608,19 +1610,39 @@ const result = await generateText({
1608
1610
  role: 'user',
1609
1611
  content: 'Complete the plan.',
1610
1612
  },
1613
+ {
1614
+ role: 'system',
1615
+ content: 'For this turn, verify every compatibility claim.',
1616
+ providerOptions: {
1617
+ anthropic: {
1618
+ clearAt: 'next_user_message',
1619
+ },
1620
+ },
1621
+ },
1611
1622
  ],
1612
1623
  });
1613
1624
  ```
1614
1625
 
1615
1626
  An effort-only system message can use an empty content array at the API level;
1616
1627
  in an AI SDK prompt, set `content: ''`. The provider serializes it as
1617
- `content: []`.
1628
+ `content: []`. These effort-only messages can appear first or later in the
1629
+ conversation, including consecutively. The provider preserves their order. The new
1630
+ level applies from the next user turn until a later message changes it.
1631
+ Initial instruction text is sent in the top-level `system` field.
1632
+
1633
+ Consecutive inline system messages are evaluated as a group. If an effort-only
1634
+ message is adjacent to a system message containing text, the whole group must
1635
+ follow Anthropic's [content placement rules](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages#limitations).
1636
+
1637
+ Turn-scoped messages with `clearAt` support text only. Put effort updates in a
1638
+ separate message, as in the example above.
1618
1639
 
1619
1640
  <Note>
1620
- `clearAt` and per-message `effort` apply only to mid-conversation system
1621
- messages. When used on the initial system message, the provider ignores them
1622
- and emits a warning. Use the top-level `effort` provider option to configure
1623
- effort for the full request.
1641
+ `clearAt` applies only to mid-conversation system messages. On initial system
1642
+ messages, the provider ignores `clearAt` and effort attached to non-empty
1643
+ content and emits a warning. Use an empty system message for an initial
1644
+ per-message effort setting, or the top-level `effort` provider option to
1645
+ configure effort for the full request.
1624
1646
  </Note>
1625
1647
 
1626
1648
  ### Mid-Conversation Tool Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.63",
3
+ "version": "4.0.66",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,11 +35,11 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.18",
39
- "@ai-sdk/provider-utils": "5.0.47"
38
+ "@ai-sdk/provider": "4.0.19",
39
+ "@ai-sdk/provider-utils": "5.0.50"
40
40
  },
41
41
  "devDependencies": {
42
- "@ai-sdk/test-server": "2.0.1",
42
+ "@ai-sdk/test-server": "2.0.2",
43
43
  "@types/node": "22.19.19",
44
44
  "@vercel/ai-tsconfig": "0.0.0",
45
45
  "tsup": "^8.5.1",
@@ -82,9 +82,10 @@ export const anthropicSystemMessageProviderOptions = z.object({
82
82
  clearAt: z.literal('next_user_message').optional(),
83
83
 
84
84
  /**
85
- * Sets the model effort for the turn that follows this mid-conversation
86
- * system message. The required `mid-conversation-output-config-2026-07-01`
87
- * beta is added automatically.
85
+ * Sets the model effort from the next user turn until a later message
86
+ * changes it. An effort-only system message with empty content can appear
87
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
88
+ * added automatically.
88
89
  */
89
90
  effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
90
91
 
@@ -204,11 +204,6 @@ export async function convertToAnthropicPrompt({
204
204
  });
205
205
  }
206
206
 
207
- // The first block becomes the top-level system prompt. Later system
208
- // blocks are sent as inline system messages — always when they carry
209
- // tool changes (which are only valid mid-conversation), and otherwise
210
- // only when a top-level system prompt already exists (preserving the
211
- // existing hoisting behavior for plain text).
212
207
  const toolChangeCount = convertedMessages.reduce(
213
208
  (count, message) => count + message.toolChangeCount,
214
209
  0,
@@ -230,12 +225,26 @@ export async function convertToAnthropicPrompt({
230
225
  });
231
226
  }
232
227
 
228
+ // Initial instruction text goes in the top-level system field.
229
+ // Effort-only messages stay in the messages array.
233
230
  for (const message of convertedMessages) {
234
- if (message.clearAt != null || message.effort != null) {
231
+ if (
232
+ message.content.length === 0 &&
233
+ message.clearAt == null &&
234
+ message.effort != null
235
+ ) {
236
+ messages.push({
237
+ role: 'system',
238
+ content: [],
239
+ output_config: { effort: message.effort },
240
+ });
241
+ betas.add('mid-conversation-output-config-2026-07-01');
242
+ } else if (message.clearAt != null || message.effort != null) {
235
243
  warnings.push({
236
244
  type: 'other',
237
245
  message:
238
- 'clearAt and effort on the initial system message are not supported by Anthropic. ' +
246
+ 'clearAt and effort on this initial system message are not supported by Anthropic. ' +
247
+ 'Use a separate effort-only system message with empty content to set effort. ' +
239
248
  'These options have been ignored.',
240
249
  });
241
250
  }