@ai-sdk/anthropic 3.0.123 → 3.0.125

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.
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
5
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -66,6 +66,11 @@ declare function getModelCapabilities(modelId: string): {
66
66
  * Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
67
67
  */
68
68
  rejectsForcedToolUse: boolean;
69
+ /**
70
+ * Supports `thinking.type` `between_tools`, the lowest thinking setting on
71
+ * models that reject disabled thinking.
72
+ */
73
+ supportsBetweenToolsThinking: boolean;
69
74
  isKnownModel: boolean;
70
75
  };
71
76
 
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
5
+ type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -66,6 +66,11 @@ declare function getModelCapabilities(modelId: string): {
66
66
  * Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
67
67
  */
68
68
  rejectsForcedToolUse: boolean;
69
+ /**
70
+ * Supports `thinking.type` `between_tools`, the lowest thinking setting on
71
+ * models that reject disabled thinking.
72
+ */
73
+ supportsBetweenToolsThinking: boolean;
69
74
  isKnownModel: boolean;
70
75
  };
71
76
 
@@ -942,6 +942,9 @@ var anthropicLanguageModelOptions = import_v43.z.object({
942
942
  * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
943
943
  * provider drops the unsupported setting, emits a warning, and sends an
944
944
  * adaptive thinking request. Use `effort` to control how much they think.
945
+ *
946
+ * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
947
+ * and the provider uses it in place of `disabled` for that model.
945
948
  */
946
949
  thinking: import_v43.z.union([
947
950
  import_v43.z.discriminatedUnion("type", [
@@ -970,6 +973,14 @@ var anthropicLanguageModelOptions = import_v43.z.object({
970
973
  }),
971
974
  import_v43.z.object({
972
975
  type: import_v43.z.literal("disabled")
976
+ }),
977
+ import_v43.z.object({
978
+ /**
979
+ * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
980
+ * between tool calls are returned as summarized thinking blocks.
981
+ * Only supported at `low`, `medium`, and `high` effort.
982
+ */
983
+ type: import_v43.z.literal("between_tools")
973
984
  })
974
985
  ]),
975
986
  /**
@@ -2396,6 +2407,7 @@ async function convertToAnthropicMessagesPrompt({
2396
2407
  const validator = cacheControlValidator || new CacheControlValidator();
2397
2408
  let system = void 0;
2398
2409
  const messages = [];
2410
+ let lastUserMessageIndex = -1;
2399
2411
  async function shouldEnableCitations(providerMetadata) {
2400
2412
  var _a2, _b2;
2401
2413
  const anthropicOptions = await (0, import_provider_utils15.parseProviderOptions)({
@@ -2507,6 +2519,9 @@ async function convertToAnthropicMessagesPrompt({
2507
2519
  const { role, content } = message;
2508
2520
  switch (role) {
2509
2521
  case "user": {
2522
+ if (content.length > 0) {
2523
+ lastUserMessageIndex = messages.length;
2524
+ }
2510
2525
  for (let j = 0; j < content.length; j++) {
2511
2526
  const part = content[j];
2512
2527
  const isLastPart = j === content.length - 1;
@@ -3291,6 +3306,42 @@ async function convertToAnthropicMessagesPrompt({
3291
3306
  }
3292
3307
  }
3293
3308
  }
3309
+ const codeExecutionToolCallIds = /* @__PURE__ */ new Set();
3310
+ for (const message of messages) {
3311
+ if (message.role !== "assistant") {
3312
+ continue;
3313
+ }
3314
+ for (const part of message.content) {
3315
+ if (part.type === "server_tool_use" && part.name === "code_execution") {
3316
+ codeExecutionToolCallIds.add(part.id);
3317
+ }
3318
+ }
3319
+ }
3320
+ const warnedToolCallIds = /* @__PURE__ */ new Set();
3321
+ for (let i = 0; i < lastUserMessageIndex; i++) {
3322
+ const message = messages[i];
3323
+ if (message.role !== "assistant") {
3324
+ continue;
3325
+ }
3326
+ for (const part of message.content) {
3327
+ if (!("caller" in part)) {
3328
+ continue;
3329
+ }
3330
+ const caller = part.caller;
3331
+ if (caller == null || caller.type === "direct" || codeExecutionToolCallIds.has(caller.tool_id)) {
3332
+ continue;
3333
+ }
3334
+ const toolCallId = "id" in part ? part.id : part.tool_use_id;
3335
+ delete part.caller;
3336
+ if (!warnedToolCallIds.has(toolCallId)) {
3337
+ warnedToolCallIds.add(toolCallId);
3338
+ warnings.push({
3339
+ type: "other",
3340
+ message: `Omitted caller metadata for tool ${toolCallId} because source code execution tool ${caller.tool_id} is missing from the conversation history.`
3341
+ });
3342
+ }
3343
+ }
3344
+ }
3294
3345
  return {
3295
3346
  prompt: { system, messages },
3296
3347
  betas
@@ -3734,6 +3785,7 @@ var AnthropicMessagesLanguageModel = class {
3734
3785
  rejectsThinkingDisabledAboveHighEffort,
3735
3786
  rejectsThinkingDisabled,
3736
3787
  rejectsForcedToolUse,
3788
+ supportsBetweenToolsThinking,
3737
3789
  isKnownModel
3738
3790
  } = getModelCapabilities(this.modelId);
3739
3791
  if (!isKnownModel && maxOutputTokens == null) {
@@ -3835,7 +3887,14 @@ var AnthropicMessagesLanguageModel = class {
3835
3887
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
3836
3888
  const requestedThinking = anthropicOptions.thinking;
3837
3889
  const requestedType = "type" in requestedThinking ? requestedThinking.type : void 0;
3838
- if (requestedType === "disabled") {
3890
+ if (requestedType === "disabled" && supportsBetweenToolsThinking) {
3891
+ warnings.push({
3892
+ type: "unsupported",
3893
+ feature: "providerOptions.anthropic.thinking",
3894
+ details: `thinking cannot be disabled for ${this.modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
3895
+ });
3896
+ anthropicOptions.thinking = { type: "between_tools" };
3897
+ } else if (requestedType === "disabled") {
3839
3898
  warnings.push({
3840
3899
  type: "unsupported",
3841
3900
  feature: "providerOptions.anthropic.thinking",
@@ -3861,7 +3920,15 @@ var AnthropicMessagesLanguageModel = class {
3861
3920
  });
3862
3921
  anthropicOptions.effort = "high";
3863
3922
  }
3864
- const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3923
+ if (thinkingType === "between_tools" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3924
+ warnings.push({
3925
+ type: "unsupported",
3926
+ feature: "providerOptions.anthropic.effort",
3927
+ details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
3928
+ });
3929
+ anthropicOptions.effort = "high";
3930
+ }
3931
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
3865
3932
  const sendThinking = isThinking || thinkingType === "disabled";
3866
3933
  let thinkingBudget = thinkingType === "enabled" && thinking != null && "budgetTokens" in thinking ? thinking.budgetTokens : void 0;
3867
3934
  const thinkingDisplay = thinkingType === "adaptive" && thinking != null && "display" in thinking ? thinking.display : void 0;
@@ -5697,7 +5764,18 @@ var AnthropicMessagesLanguageModel = class {
5697
5764
  }
5698
5765
  };
5699
5766
  function getModelCapabilities(modelId) {
5700
- if (modelId.includes("claude-opus-5-5")) {
5767
+ if (modelId.includes("claude-sonnet-5-5")) {
5768
+ return {
5769
+ maxOutputTokens: 128e3,
5770
+ supportsStructuredOutput: true,
5771
+ rejectsSamplingParameters: true,
5772
+ rejectsThinkingDisabledAboveHighEffort: true,
5773
+ rejectsThinkingDisabled: true,
5774
+ rejectsForcedToolUse: true,
5775
+ supportsBetweenToolsThinking: true,
5776
+ isKnownModel: true
5777
+ };
5778
+ } else if (modelId.includes("claude-opus-5-5")) {
5701
5779
  return {
5702
5780
  maxOutputTokens: 128e3,
5703
5781
  supportsStructuredOutput: true,
@@ -5705,6 +5783,7 @@ function getModelCapabilities(modelId) {
5705
5783
  rejectsThinkingDisabledAboveHighEffort: true,
5706
5784
  rejectsThinkingDisabled: true,
5707
5785
  rejectsForcedToolUse: true,
5786
+ supportsBetweenToolsThinking: false,
5708
5787
  isKnownModel: true
5709
5788
  };
5710
5789
  } else if (modelId.includes("claude-opus-5")) {
@@ -5715,6 +5794,7 @@ function getModelCapabilities(modelId) {
5715
5794
  rejectsThinkingDisabledAboveHighEffort: true,
5716
5795
  rejectsThinkingDisabled: false,
5717
5796
  rejectsForcedToolUse: false,
5797
+ supportsBetweenToolsThinking: false,
5718
5798
  isKnownModel: true
5719
5799
  };
5720
5800
  } else if (modelId.includes("claude-fable-5-1")) {
@@ -5725,6 +5805,7 @@ function getModelCapabilities(modelId) {
5725
5805
  rejectsThinkingDisabledAboveHighEffort: false,
5726
5806
  rejectsThinkingDisabled: true,
5727
5807
  rejectsForcedToolUse: true,
5808
+ supportsBetweenToolsThinking: false,
5728
5809
  isKnownModel: true
5729
5810
  };
5730
5811
  } else if (modelId.includes("claude-fable-5")) {
@@ -5735,6 +5816,7 @@ function getModelCapabilities(modelId) {
5735
5816
  rejectsThinkingDisabledAboveHighEffort: false,
5736
5817
  rejectsThinkingDisabled: true,
5737
5818
  rejectsForcedToolUse: false,
5819
+ supportsBetweenToolsThinking: false,
5738
5820
  isKnownModel: true
5739
5821
  };
5740
5822
  } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
@@ -5745,6 +5827,7 @@ function getModelCapabilities(modelId) {
5745
5827
  rejectsThinkingDisabledAboveHighEffort: false,
5746
5828
  rejectsThinkingDisabled: false,
5747
5829
  rejectsForcedToolUse: false,
5830
+ supportsBetweenToolsThinking: false,
5748
5831
  isKnownModel: true
5749
5832
  };
5750
5833
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -5755,6 +5838,7 @@ function getModelCapabilities(modelId) {
5755
5838
  rejectsThinkingDisabledAboveHighEffort: false,
5756
5839
  rejectsThinkingDisabled: false,
5757
5840
  rejectsForcedToolUse: false,
5841
+ supportsBetweenToolsThinking: false,
5758
5842
  isKnownModel: true
5759
5843
  };
5760
5844
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -5765,6 +5849,7 @@ function getModelCapabilities(modelId) {
5765
5849
  rejectsThinkingDisabledAboveHighEffort: false,
5766
5850
  rejectsThinkingDisabled: false,
5767
5851
  rejectsForcedToolUse: false,
5852
+ supportsBetweenToolsThinking: false,
5768
5853
  isKnownModel: true
5769
5854
  };
5770
5855
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -5775,6 +5860,7 @@ function getModelCapabilities(modelId) {
5775
5860
  rejectsThinkingDisabledAboveHighEffort: false,
5776
5861
  rejectsThinkingDisabled: false,
5777
5862
  rejectsForcedToolUse: false,
5863
+ supportsBetweenToolsThinking: false,
5778
5864
  isKnownModel: true
5779
5865
  };
5780
5866
  } else if (modelId.includes("claude-sonnet-4-")) {
@@ -5785,6 +5871,7 @@ function getModelCapabilities(modelId) {
5785
5871
  rejectsThinkingDisabledAboveHighEffort: false,
5786
5872
  rejectsThinkingDisabled: false,
5787
5873
  rejectsForcedToolUse: false,
5874
+ supportsBetweenToolsThinking: false,
5788
5875
  isKnownModel: true
5789
5876
  };
5790
5877
  } else if (modelId.includes("claude-opus-4-")) {
@@ -5795,6 +5882,7 @@ function getModelCapabilities(modelId) {
5795
5882
  rejectsThinkingDisabledAboveHighEffort: false,
5796
5883
  rejectsThinkingDisabled: false,
5797
5884
  rejectsForcedToolUse: false,
5885
+ supportsBetweenToolsThinking: false,
5798
5886
  isKnownModel: true
5799
5887
  };
5800
5888
  } else if (modelId.includes("claude-3-haiku")) {
@@ -5805,6 +5893,7 @@ function getModelCapabilities(modelId) {
5805
5893
  rejectsThinkingDisabledAboveHighEffort: false,
5806
5894
  rejectsThinkingDisabled: false,
5807
5895
  rejectsForcedToolUse: false,
5896
+ supportsBetweenToolsThinking: false,
5808
5897
  isKnownModel: true
5809
5898
  };
5810
5899
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -5815,6 +5904,7 @@ function getModelCapabilities(modelId) {
5815
5904
  rejectsThinkingDisabledAboveHighEffort: false,
5816
5905
  rejectsThinkingDisabled: false,
5817
5906
  rejectsForcedToolUse: false,
5907
+ supportsBetweenToolsThinking: false,
5818
5908
  isKnownModel: false
5819
5909
  };
5820
5910
  } else if (modelId.includes("claude-")) {
@@ -5825,6 +5915,7 @@ function getModelCapabilities(modelId) {
5825
5915
  rejectsThinkingDisabledAboveHighEffort: true,
5826
5916
  rejectsThinkingDisabled: false,
5827
5917
  rejectsForcedToolUse: false,
5918
+ supportsBetweenToolsThinking: false,
5828
5919
  isKnownModel: false
5829
5920
  };
5830
5921
  } else {
@@ -5835,6 +5926,7 @@ function getModelCapabilities(modelId) {
5835
5926
  rejectsThinkingDisabledAboveHighEffort: false,
5836
5927
  rejectsThinkingDisabled: false,
5837
5928
  rejectsForcedToolUse: false,
5929
+ supportsBetweenToolsThinking: false,
5838
5930
  isKnownModel: false
5839
5931
  };
5840
5932
  }