@ai-sdk/anthropic 2.0.100 → 2.0.101

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.
@@ -649,6 +649,19 @@ var anthropicFilePartProviderOptions = z3.object({
649
649
  context: z3.string().optional()
650
650
  });
651
651
  var anthropicSystemMessageProviderOptions = z3.object({
652
+ /**
653
+ * Controls when a mid-conversation system message is cleared.
654
+ *
655
+ * The value is forwarded to Anthropic as `clear_at`. The required
656
+ * `mid-conversation-system-clear-at-2026-08-21` beta is added automatically.
657
+ */
658
+ clearAt: z3.literal("next_user_message").optional(),
659
+ /**
660
+ * Overrides the effort for the turn following this mid-conversation system
661
+ * message. The required `mid-conversation-effort-2026-08-01` beta is added
662
+ * automatically.
663
+ */
664
+ effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
652
665
  /**
653
666
  * Mid-conversation tool changes. Adds or removes tools from the
654
667
  * conversation's tool set between turns without invalidating the prompt
@@ -676,6 +689,14 @@ var anthropicSystemMessageProviderOptions = z3.object({
676
689
  ])
677
690
  ).optional()
678
691
  });
692
+ var anthropicThinkingBlockBinding = z3.object({
693
+ /**
694
+ * Controls behavior when a replayed thinking block does not match its
695
+ * conversation prefix. The `drop_block` behavior drops the mismatched block
696
+ * instead of returning an invalid signature error.
697
+ */
698
+ prefixMismatchBehavior: z3.literal("drop_block")
699
+ });
679
700
  var anthropicProviderOptions = z3.object({
680
701
  /**
681
702
  * Whether to send reasoning to the model.
@@ -687,8 +708,8 @@ var anthropicProviderOptions = z3.object({
687
708
  * Determines how structured outputs are generated.
688
709
  *
689
710
  * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
690
- * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default).
691
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
711
+ * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
712
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Fable 5.1).
692
713
  */
693
714
  structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
694
715
  /**
@@ -697,7 +718,7 @@ var anthropicProviderOptions = z3.object({
697
718
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
698
719
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
699
720
  */
700
- thinking: z3.discriminatedUnion("type", [
721
+ thinking: z3.union([
701
722
  z3.object({
702
723
  /** for Sonnet 4.6, Opus 4.6, and newer models */
703
724
  type: z3.literal("adaptive"),
@@ -705,16 +726,34 @@ var anthropicProviderOptions = z3.object({
705
726
  * Controls whether thinking content is included in the response.
706
727
  * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
707
728
  * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
729
+ * - `"updates"`: Thinking summaries are emitted between tool calls.
730
+ */
731
+ display: z3.enum(["omitted", "summarized", "updates"]).optional(),
732
+ /**
733
+ * Controls handling for thinking blocks whose conversation prefix no
734
+ * longer matches. Forwarded as `block_binding`.
708
735
  */
709
- display: z3.enum(["omitted", "summarized"]).optional()
736
+ blockBinding: anthropicThinkingBlockBinding.optional()
710
737
  }),
711
738
  z3.object({
712
739
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
713
740
  type: z3.literal("enabled"),
714
- budgetTokens: z3.number().optional()
741
+ budgetTokens: z3.number().optional(),
742
+ /**
743
+ * Controls handling for thinking blocks whose conversation prefix no
744
+ * longer matches. Forwarded as `block_binding`.
745
+ */
746
+ blockBinding: anthropicThinkingBlockBinding.optional()
715
747
  }),
716
748
  z3.object({
717
749
  type: z3.literal("disabled")
750
+ }),
751
+ z3.object({
752
+ /**
753
+ * Configure prefix mismatch handling without changing the model's
754
+ * default thinking mode.
755
+ */
756
+ blockBinding: anthropicThinkingBlockBinding
718
757
  })
719
758
  ]).optional(),
720
759
  /**
@@ -1485,7 +1524,7 @@ async function convertToAnthropicMessagesPrompt({
1485
1524
  warnings,
1486
1525
  cacheControlValidator
1487
1526
  }) {
1488
- var _a, _b, _c, _d, _e, _f, _g;
1527
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1489
1528
  const betas = /* @__PURE__ */ new Set();
1490
1529
  const blocks = groupIntoBlocks(prompt);
1491
1530
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1519,6 +1558,8 @@ async function convertToAnthropicMessagesPrompt({
1519
1558
  case "system": {
1520
1559
  const content = [];
1521
1560
  let toolChangeCount = 0;
1561
+ let clearAt = void 0;
1562
+ let effort = void 0;
1522
1563
  for (const { content: text, providerOptions } of block.messages) {
1523
1564
  const systemMessageOptions = await parseProviderOptions({
1524
1565
  provider: "anthropic",
@@ -1526,7 +1567,9 @@ async function convertToAnthropicMessagesPrompt({
1526
1567
  schema: anthropicSystemMessageProviderOptions
1527
1568
  });
1528
1569
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1529
- if (text !== "" || toolChanges.length === 0) {
1570
+ clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1571
+ effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1572
+ if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1530
1573
  content.push({
1531
1574
  type: "text",
1532
1575
  text,
@@ -1547,22 +1590,34 @@ async function convertToAnthropicMessagesPrompt({
1547
1590
  });
1548
1591
  }
1549
1592
  }
1550
- if (i === 0 || system == null && toolChangeCount === 0) {
1551
- if (toolChangeCount > 0) {
1593
+ const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1594
+ if (i === 0 || system == null && !hasMidConversationOptions) {
1595
+ if (hasMidConversationOptions) {
1552
1596
  warnings.push({
1553
1597
  type: "other",
1554
- message: "tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored."
1598
+ message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1555
1599
  });
1556
1600
  }
1557
1601
  system = content.filter(
1558
1602
  (part) => part.type === "text"
1559
1603
  );
1560
1604
  } else {
1561
- messages.push({ role: "system", content });
1605
+ messages.push({
1606
+ role: "system",
1607
+ content,
1608
+ ...clearAt != null && { clear_at: clearAt },
1609
+ ...effort != null && { output_config: { effort } }
1610
+ });
1562
1611
  betas.add("mid-conversation-system-2026-04-07");
1563
1612
  if (toolChangeCount > 0) {
1564
1613
  betas.add("mid-conversation-tool-changes-2026-07-01");
1565
1614
  }
1615
+ if (clearAt != null) {
1616
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
1617
+ }
1618
+ if (effort != null) {
1619
+ betas.add("mid-conversation-effort-2026-08-01");
1620
+ }
1566
1621
  }
1567
1622
  break;
1568
1623
  }
@@ -1575,10 +1630,10 @@ async function convertToAnthropicMessagesPrompt({
1575
1630
  for (let j = 0; j < content.length; j++) {
1576
1631
  const part = content[j];
1577
1632
  const isLastPart = j === content.length - 1;
1578
- const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1633
+ const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1579
1634
  type: "user message part",
1580
1635
  canCache: true
1581
- })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1636
+ })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1582
1637
  type: "user message",
1583
1638
  canCache: true
1584
1639
  }) : void 0;
@@ -1623,7 +1678,7 @@ async function convertToAnthropicMessagesPrompt({
1623
1678
  media_type: "application/pdf",
1624
1679
  data: convertToBase64(part.data)
1625
1680
  },
1626
- title: (_c = metadata.title) != null ? _c : part.filename,
1681
+ title: (_e = metadata.title) != null ? _e : part.filename,
1627
1682
  ...metadata.context && { context: metadata.context },
1628
1683
  ...enableCitations && {
1629
1684
  citations: { enabled: true }
@@ -1647,7 +1702,7 @@ async function convertToAnthropicMessagesPrompt({
1647
1702
  media_type: "text/plain",
1648
1703
  data: convertToString(part.data)
1649
1704
  },
1650
- title: (_d = metadata.title) != null ? _d : part.filename,
1705
+ title: (_f = metadata.title) != null ? _f : part.filename,
1651
1706
  ...metadata.context && { context: metadata.context },
1652
1707
  ...enableCitations && {
1653
1708
  citations: { enabled: true }
@@ -1669,10 +1724,10 @@ async function convertToAnthropicMessagesPrompt({
1669
1724
  for (let i2 = 0; i2 < content.length; i2++) {
1670
1725
  const part = content[i2];
1671
1726
  const isLastPart = i2 === content.length - 1;
1672
- const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1727
+ const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1673
1728
  type: "tool result part",
1674
1729
  canCache: true
1675
- })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1730
+ })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1676
1731
  type: "tool result message",
1677
1732
  canCache: true
1678
1733
  }) : void 0;
@@ -1754,16 +1809,16 @@ async function convertToAnthropicMessagesPrompt({
1754
1809
  for (let k = 0; k < content.length; k++) {
1755
1810
  const part = content[k];
1756
1811
  const isLastContentPart = k === content.length - 1;
1757
- const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1812
+ const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1758
1813
  type: "assistant message part",
1759
1814
  canCache: true
1760
- })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1815
+ })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1761
1816
  type: "assistant message",
1762
1817
  canCache: true
1763
1818
  }) : void 0;
1764
1819
  switch (part.type) {
1765
1820
  case "text": {
1766
- const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1821
+ const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1767
1822
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1768
1823
  anthropicContent.push({
1769
1824
  type: "compaction",
@@ -2332,7 +2387,7 @@ var AnthropicMessagesLanguageModel = class {
2332
2387
  toolChoice,
2333
2388
  providerOptions
2334
2389
  }) {
2335
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2390
+ var _a, _b, _c, _d, _e;
2336
2391
  const warnings = [];
2337
2392
  if (frequencyPenalty != null) {
2338
2393
  warnings.push({
@@ -2421,7 +2476,7 @@ var AnthropicMessagesLanguageModel = class {
2421
2476
  }
2422
2477
  }
2423
2478
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
2424
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
2479
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") ? "auto" : "jsonTool";
2425
2480
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2426
2481
  const jsonResponseToolName = getJsonResponseToolName(tools);
2427
2482
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
@@ -2444,7 +2499,9 @@ var AnthropicMessagesLanguageModel = class {
2444
2499
  warnings,
2445
2500
  cacheControlValidator
2446
2501
  });
2447
- if (rejectsThinkingDisabledAboveHighEffort && ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2502
+ const thinkingOptions = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
2503
+ const thinkingType = thinkingOptions != null && "type" in thinkingOptions ? thinkingOptions.type : void 0;
2504
+ if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2448
2505
  warnings.push({
2449
2506
  type: "unsupported-setting",
2450
2507
  setting: "providerOptions.anthropic.effort",
@@ -2452,10 +2509,10 @@ var AnthropicMessagesLanguageModel = class {
2452
2509
  });
2453
2510
  anthropicOptions.effort = "high";
2454
2511
  }
2455
- const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2456
2512
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2457
- let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2458
- const thinkingDisplay = thinkingType === "adaptive" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.display : void 0;
2513
+ let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
2514
+ const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
2515
+ const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
2459
2516
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2460
2517
  const baseArgs = {
2461
2518
  // model id:
@@ -2467,11 +2524,16 @@ var AnthropicMessagesLanguageModel = class {
2467
2524
  top_p: topP,
2468
2525
  stop_sequences: stopSequences,
2469
2526
  // provider specific settings:
2470
- ...isThinking && {
2527
+ ...(isThinking || thinkingBlockBinding != null) && {
2471
2528
  thinking: {
2472
- type: thinkingType,
2529
+ ...thinkingType != null && { type: thinkingType },
2473
2530
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2474
- ...thinkingDisplay != null && { display: thinkingDisplay }
2531
+ ...thinkingDisplay != null && { display: thinkingDisplay },
2532
+ ...thinkingBlockBinding != null && {
2533
+ block_binding: {
2534
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
2535
+ }
2536
+ }
2475
2537
  }
2476
2538
  },
2477
2539
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -2508,14 +2570,14 @@ var AnthropicMessagesLanguageModel = class {
2508
2570
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2509
2571
  cache_control: anthropicOptions.cacheControl
2510
2572
  },
2511
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
2573
+ ...((_c = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _c.userId) != null && {
2512
2574
  metadata: { user_id: anthropicOptions.metadata.userId }
2513
2575
  },
2514
2576
  // container with agent skills:
2515
2577
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2516
2578
  container: {
2517
2579
  id: anthropicOptions.container.id,
2518
- skills: (_h = anthropicOptions.container.skills) == null ? void 0 : _h.map((skill) => ({
2580
+ skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
2519
2581
  type: skill.type,
2520
2582
  skill_id: skill.skillId,
2521
2583
  version: skill.version
@@ -2641,6 +2703,12 @@ var AnthropicMessagesLanguageModel = class {
2641
2703
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2642
2704
  betas.add("effort-2025-11-24");
2643
2705
  }
2706
+ if (thinkingDisplay === "updates") {
2707
+ betas.add("thinking-display-updates-2026-08-18");
2708
+ }
2709
+ if (thinkingBlockBinding != null) {
2710
+ betas.add("thinking-binding-controls-2026-08-01");
2711
+ }
2644
2712
  if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
2645
2713
  betas.add("task-budgets-2026-03-13");
2646
2714
  }
@@ -2652,7 +2720,7 @@ var AnthropicMessagesLanguageModel = class {
2652
2720
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
2653
2721
  betas.add("server-side-fallback-2026-06-01");
2654
2722
  }
2655
- if (useStructuredOutput) {
2723
+ if (useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
2656
2724
  betas.add("structured-outputs-2025-11-13");
2657
2725
  }
2658
2726
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
@@ -2692,7 +2760,7 @@ var AnthropicMessagesLanguageModel = class {
2692
2760
  ...betas,
2693
2761
  ...toolsBetas,
2694
2762
  ...userSuppliedBetas,
2695
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
2763
+ ...(_e = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _e : []
2696
2764
  ]),
2697
2765
  jsonResponseToolName: jsonResponseTool != null ? jsonResponseToolName : void 0
2698
2766
  };
@@ -3752,7 +3820,7 @@ function getModelCapabilities(modelId) {
3752
3820
  rejectsThinkingDisabledAboveHighEffort: true,
3753
3821
  isKnownModel: true
3754
3822
  };
3755
- } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3823
+ } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5-1") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3756
3824
  return {
3757
3825
  maxOutputTokens: 128e3,
3758
3826
  supportsStructuredOutput: true,