@ai-sdk/anthropic 3.0.69 → 3.0.71

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' | (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' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -946,7 +946,7 @@ declare class CacheControlValidator {
946
946
  getWarnings(): SharedV3Warning[];
947
947
  }
948
948
 
949
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, }: {
949
+ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, }: {
950
950
  tools: LanguageModelV3CallOptions['tools'];
951
951
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
952
952
  disableParallelToolUse?: boolean;
@@ -959,6 +959,11 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
959
959
  * Whether the model supports strict mode on tool definitions.
960
960
  */
961
961
  supportsStrictTools: boolean;
962
+ /**
963
+ * Default for `eager_input_streaming` on function tools that do not set
964
+ * it explicitly. Driven by the model-level `toolStreaming` option.
965
+ */
966
+ defaultEagerInputStreaming?: boolean;
962
967
  }): Promise<{
963
968
  tools: Array<AnthropicTool> | undefined;
964
969
  toolChoice: AnthropicToolChoice | undefined;
@@ -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' | (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' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -946,7 +946,7 @@ declare class CacheControlValidator {
946
946
  getWarnings(): SharedV3Warning[];
947
947
  }
948
948
 
949
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, }: {
949
+ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, }: {
950
950
  tools: LanguageModelV3CallOptions['tools'];
951
951
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
952
952
  disableParallelToolUse?: boolean;
@@ -959,6 +959,11 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
959
959
  * Whether the model supports strict mode on tool definitions.
960
960
  */
961
961
  supportsStrictTools: boolean;
962
+ /**
963
+ * Default for `eager_input_streaming` on function tools that do not set
964
+ * it explicitly. Driven by the model-level `toolStreaming` option.
965
+ */
966
+ defaultEagerInputStreaming?: boolean;
962
967
  }): Promise<{
963
968
  tools: Array<AnthropicTool> | undefined;
964
969
  toolChoice: AnthropicToolChoice | undefined;
@@ -837,7 +837,13 @@ var anthropicLanguageModelOptions = import_v43.z.object({
837
837
  thinking: import_v43.z.discriminatedUnion("type", [
838
838
  import_v43.z.object({
839
839
  /** for Sonnet 4.6, Opus 4.6, and newer models */
840
- type: import_v43.z.literal("adaptive")
840
+ type: import_v43.z.literal("adaptive"),
841
+ /**
842
+ * Controls whether thinking content is included in the response.
843
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
844
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
845
+ */
846
+ display: import_v43.z.enum(["omitted", "summarized"]).optional()
841
847
  }),
842
848
  import_v43.z.object({
843
849
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
@@ -906,10 +912,11 @@ var anthropicLanguageModelOptions = import_v43.z.object({
906
912
  ).optional()
907
913
  }).optional(),
908
914
  /**
909
- * Whether to enable tool streaming (and structured output streaming).
910
- *
911
- * When set to false, the model will return all tool calls and results
912
- * at once after a delay.
915
+ * Whether to enable fine-grained (eager) streaming of tool call inputs
916
+ * and structured outputs for every function tool in the request. When
917
+ * true (the default), each function tool receives a default of
918
+ * `eager_input_streaming: true` unless it explicitly sets
919
+ * `providerOptions.anthropic.eagerInputStreaming`.
913
920
  *
914
921
  * @default true
915
922
  */
@@ -917,7 +924,19 @@ var anthropicLanguageModelOptions = import_v43.z.object({
917
924
  /**
918
925
  * @default 'high'
919
926
  */
920
- effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
927
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
928
+ /**
929
+ * Task budget for agentic turns. Informs the model of the total token budget
930
+ * available for the current task, allowing it to prioritize work and wind down
931
+ * gracefully as the budget is consumed.
932
+ *
933
+ * Advisory only — does not enforce a hard token limit.
934
+ */
935
+ taskBudget: import_v43.z.object({
936
+ type: import_v43.z.literal("tokens"),
937
+ total: import_v43.z.number().int().min(2e4),
938
+ remaining: import_v43.z.number().int().min(0).optional()
939
+ }).optional(),
921
940
  /**
922
941
  * Enable fast mode for faster inference (2.5x faster output token speeds).
923
942
  * Only supported with claude-opus-4-6.
@@ -1285,9 +1304,10 @@ async function prepareTools({
1285
1304
  disableParallelToolUse,
1286
1305
  cacheControlValidator,
1287
1306
  supportsStructuredOutput,
1288
- supportsStrictTools
1307
+ supportsStrictTools,
1308
+ defaultEagerInputStreaming = false
1289
1309
  }) {
1290
- var _a;
1310
+ var _a, _b;
1291
1311
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1292
1312
  const toolWarnings = [];
1293
1313
  const betas = /* @__PURE__ */ new Set();
@@ -1304,7 +1324,7 @@ async function prepareTools({
1304
1324
  canCache: true
1305
1325
  });
1306
1326
  const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1307
- const eagerInputStreaming = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming;
1327
+ const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
1308
1328
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1309
1329
  const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1310
1330
  if (!supportsStrictTools && tool.strict != null) {
@@ -2893,7 +2913,7 @@ var AnthropicMessagesLanguageModel = class {
2893
2913
  providerOptions,
2894
2914
  stream
2895
2915
  }) {
2896
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2916
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2897
2917
  const warnings = [];
2898
2918
  if (frequencyPenalty != null) {
2899
2919
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2948,8 +2968,35 @@ var AnthropicMessagesLanguageModel = class {
2948
2968
  const {
2949
2969
  maxOutputTokens: maxOutputTokensForModel,
2950
2970
  supportsStructuredOutput: modelSupportsStructuredOutput,
2971
+ rejectsSamplingParameters,
2951
2972
  isKnownModel
2952
2973
  } = getModelCapabilities(this.modelId);
2974
+ if (rejectsSamplingParameters) {
2975
+ if (temperature != null) {
2976
+ warnings.push({
2977
+ type: "unsupported",
2978
+ feature: "temperature",
2979
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2980
+ });
2981
+ temperature = void 0;
2982
+ }
2983
+ if (topK != null) {
2984
+ warnings.push({
2985
+ type: "unsupported",
2986
+ feature: "topK",
2987
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2988
+ });
2989
+ topK = void 0;
2990
+ }
2991
+ if (topP != null) {
2992
+ warnings.push({
2993
+ type: "unsupported",
2994
+ feature: "topP",
2995
+ details: `topP is not supported by ${this.modelId} and will be ignored`
2996
+ });
2997
+ topP = void 0;
2998
+ }
2999
+ }
2953
3000
  const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2954
3001
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2955
3002
  const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
@@ -2996,6 +3043,7 @@ var AnthropicMessagesLanguageModel = class {
2996
3043
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
2997
3044
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2998
3045
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3046
+ const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
2999
3047
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3000
3048
  const baseArgs = {
3001
3049
  // model id:
@@ -3010,14 +3058,24 @@ var AnthropicMessagesLanguageModel = class {
3010
3058
  ...isThinking && {
3011
3059
  thinking: {
3012
3060
  type: thinkingType,
3013
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
3061
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3062
+ ...thinkingDisplay != null && { display: thinkingDisplay }
3014
3063
  }
3015
3064
  },
3016
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3065
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3017
3066
  output_config: {
3018
3067
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
3019
3068
  effort: anthropicOptions.effort
3020
3069
  },
3070
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
3071
+ task_budget: {
3072
+ type: anthropicOptions.taskBudget.type,
3073
+ total: anthropicOptions.taskBudget.total,
3074
+ ...anthropicOptions.taskBudget.remaining != null && {
3075
+ remaining: anthropicOptions.taskBudget.remaining
3076
+ }
3077
+ }
3078
+ },
3021
3079
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
3022
3080
  format: {
3023
3081
  type: "json_schema",
@@ -3035,7 +3093,7 @@ var AnthropicMessagesLanguageModel = class {
3035
3093
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3036
3094
  cache_control: anthropicOptions.cacheControl
3037
3095
  },
3038
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
3096
+ ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3039
3097
  metadata: { user_id: anthropicOptions.metadata.userId }
3040
3098
  },
3041
3099
  // mcp servers:
@@ -3205,12 +3263,13 @@ var AnthropicMessagesLanguageModel = class {
3205
3263
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
3206
3264
  betas.add("effort-2025-11-24");
3207
3265
  }
3266
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3267
+ betas.add("task-budgets-2026-03-13");
3268
+ }
3208
3269
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3209
3270
  betas.add("fast-mode-2026-02-01");
3210
3271
  }
3211
- if (stream && ((_h = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _h : true)) {
3212
- betas.add("fine-grained-tool-streaming-2025-05-14");
3213
- }
3272
+ const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
3214
3273
  const {
3215
3274
  tools: anthropicTools2,
3216
3275
  toolChoice: anthropicToolChoice,
@@ -3223,14 +3282,16 @@ var AnthropicMessagesLanguageModel = class {
3223
3282
  disableParallelToolUse: true,
3224
3283
  cacheControlValidator,
3225
3284
  supportsStructuredOutput: false,
3226
- supportsStrictTools
3285
+ supportsStrictTools,
3286
+ defaultEagerInputStreaming
3227
3287
  } : {
3228
3288
  tools: tools != null ? tools : [],
3229
3289
  toolChoice,
3230
3290
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
3231
3291
  cacheControlValidator,
3232
3292
  supportsStructuredOutput,
3233
- supportsStrictTools
3293
+ supportsStrictTools,
3294
+ defaultEagerInputStreaming
3234
3295
  }
3235
3296
  );
3236
3297
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -3247,7 +3308,7 @@ var AnthropicMessagesLanguageModel = class {
3247
3308
  ...betas,
3248
3309
  ...toolsBetas,
3249
3310
  ...userSuppliedBetas,
3250
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
3311
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3251
3312
  ]),
3252
3313
  usesJsonResponseTool: jsonResponseTool != null,
3253
3314
  toolNameMapping,
@@ -4506,46 +4567,60 @@ var AnthropicMessagesLanguageModel = class {
4506
4567
  }
4507
4568
  };
4508
4569
  function getModelCapabilities(modelId) {
4509
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4570
+ if (modelId.includes("claude-opus-4-7")) {
4571
+ return {
4572
+ maxOutputTokens: 128e3,
4573
+ supportsStructuredOutput: true,
4574
+ rejectsSamplingParameters: true,
4575
+ isKnownModel: true
4576
+ };
4577
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4510
4578
  return {
4511
4579
  maxOutputTokens: 128e3,
4512
4580
  supportsStructuredOutput: true,
4581
+ rejectsSamplingParameters: false,
4513
4582
  isKnownModel: true
4514
4583
  };
4515
4584
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
4516
4585
  return {
4517
4586
  maxOutputTokens: 64e3,
4518
4587
  supportsStructuredOutput: true,
4588
+ rejectsSamplingParameters: false,
4519
4589
  isKnownModel: true
4520
4590
  };
4521
4591
  } else if (modelId.includes("claude-opus-4-1")) {
4522
4592
  return {
4523
4593
  maxOutputTokens: 32e3,
4524
4594
  supportsStructuredOutput: true,
4595
+ rejectsSamplingParameters: false,
4525
4596
  isKnownModel: true
4526
4597
  };
4527
4598
  } else if (modelId.includes("claude-sonnet-4-")) {
4528
4599
  return {
4529
4600
  maxOutputTokens: 64e3,
4530
4601
  supportsStructuredOutput: false,
4602
+ rejectsSamplingParameters: false,
4531
4603
  isKnownModel: true
4532
4604
  };
4533
4605
  } else if (modelId.includes("claude-opus-4-")) {
4534
4606
  return {
4535
4607
  maxOutputTokens: 32e3,
4536
4608
  supportsStructuredOutput: false,
4609
+ rejectsSamplingParameters: false,
4537
4610
  isKnownModel: true
4538
4611
  };
4539
4612
  } else if (modelId.includes("claude-3-haiku")) {
4540
4613
  return {
4541
4614
  maxOutputTokens: 4096,
4542
4615
  supportsStructuredOutput: false,
4616
+ rejectsSamplingParameters: false,
4543
4617
  isKnownModel: true
4544
4618
  };
4545
4619
  } else {
4546
4620
  return {
4547
4621
  maxOutputTokens: 4096,
4548
4622
  supportsStructuredOutput: false,
4623
+ rejectsSamplingParameters: false,
4549
4624
  isKnownModel: false
4550
4625
  };
4551
4626
  }