@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.
@@ -824,7 +824,13 @@ var anthropicLanguageModelOptions = z3.object({
824
824
  thinking: z3.discriminatedUnion("type", [
825
825
  z3.object({
826
826
  /** for Sonnet 4.6, Opus 4.6, and newer models */
827
- type: z3.literal("adaptive")
827
+ type: z3.literal("adaptive"),
828
+ /**
829
+ * Controls whether thinking content is included in the response.
830
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
831
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
832
+ */
833
+ display: z3.enum(["omitted", "summarized"]).optional()
828
834
  }),
829
835
  z3.object({
830
836
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
@@ -893,10 +899,11 @@ var anthropicLanguageModelOptions = z3.object({
893
899
  ).optional()
894
900
  }).optional(),
895
901
  /**
896
- * Whether to enable tool streaming (and structured output streaming).
897
- *
898
- * When set to false, the model will return all tool calls and results
899
- * at once after a delay.
902
+ * Whether to enable fine-grained (eager) streaming of tool call inputs
903
+ * and structured outputs for every function tool in the request. When
904
+ * true (the default), each function tool receives a default of
905
+ * `eager_input_streaming: true` unless it explicitly sets
906
+ * `providerOptions.anthropic.eagerInputStreaming`.
900
907
  *
901
908
  * @default true
902
909
  */
@@ -904,7 +911,19 @@ var anthropicLanguageModelOptions = z3.object({
904
911
  /**
905
912
  * @default 'high'
906
913
  */
907
- effort: z3.enum(["low", "medium", "high", "max"]).optional(),
914
+ effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
915
+ /**
916
+ * Task budget for agentic turns. Informs the model of the total token budget
917
+ * available for the current task, allowing it to prioritize work and wind down
918
+ * gracefully as the budget is consumed.
919
+ *
920
+ * Advisory only — does not enforce a hard token limit.
921
+ */
922
+ taskBudget: z3.object({
923
+ type: z3.literal("tokens"),
924
+ total: z3.number().int().min(2e4),
925
+ remaining: z3.number().int().min(0).optional()
926
+ }).optional(),
908
927
  /**
909
928
  * Enable fast mode for faster inference (2.5x faster output token speeds).
910
929
  * Only supported with claude-opus-4-6.
@@ -1290,9 +1309,10 @@ async function prepareTools({
1290
1309
  disableParallelToolUse,
1291
1310
  cacheControlValidator,
1292
1311
  supportsStructuredOutput,
1293
- supportsStrictTools
1312
+ supportsStrictTools,
1313
+ defaultEagerInputStreaming = false
1294
1314
  }) {
1295
- var _a;
1315
+ var _a, _b;
1296
1316
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1297
1317
  const toolWarnings = [];
1298
1318
  const betas = /* @__PURE__ */ new Set();
@@ -1309,7 +1329,7 @@ async function prepareTools({
1309
1329
  canCache: true
1310
1330
  });
1311
1331
  const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1312
- const eagerInputStreaming = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming;
1332
+ const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
1313
1333
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1314
1334
  const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1315
1335
  if (!supportsStrictTools && tool.strict != null) {
@@ -2922,7 +2942,7 @@ var AnthropicMessagesLanguageModel = class {
2922
2942
  providerOptions,
2923
2943
  stream
2924
2944
  }) {
2925
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2945
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2926
2946
  const warnings = [];
2927
2947
  if (frequencyPenalty != null) {
2928
2948
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2977,8 +2997,35 @@ var AnthropicMessagesLanguageModel = class {
2977
2997
  const {
2978
2998
  maxOutputTokens: maxOutputTokensForModel,
2979
2999
  supportsStructuredOutput: modelSupportsStructuredOutput,
3000
+ rejectsSamplingParameters,
2980
3001
  isKnownModel
2981
3002
  } = getModelCapabilities(this.modelId);
3003
+ if (rejectsSamplingParameters) {
3004
+ if (temperature != null) {
3005
+ warnings.push({
3006
+ type: "unsupported",
3007
+ feature: "temperature",
3008
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
3009
+ });
3010
+ temperature = void 0;
3011
+ }
3012
+ if (topK != null) {
3013
+ warnings.push({
3014
+ type: "unsupported",
3015
+ feature: "topK",
3016
+ details: `topK is not supported by ${this.modelId} and will be ignored`
3017
+ });
3018
+ topK = void 0;
3019
+ }
3020
+ if (topP != null) {
3021
+ warnings.push({
3022
+ type: "unsupported",
3023
+ feature: "topP",
3024
+ details: `topP is not supported by ${this.modelId} and will be ignored`
3025
+ });
3026
+ topP = void 0;
3027
+ }
3028
+ }
2982
3029
  const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2983
3030
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2984
3031
  const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
@@ -3025,6 +3072,7 @@ var AnthropicMessagesLanguageModel = class {
3025
3072
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3026
3073
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3027
3074
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3075
+ const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
3028
3076
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3029
3077
  const baseArgs = {
3030
3078
  // model id:
@@ -3039,14 +3087,24 @@ var AnthropicMessagesLanguageModel = class {
3039
3087
  ...isThinking && {
3040
3088
  thinking: {
3041
3089
  type: thinkingType,
3042
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
3090
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3091
+ ...thinkingDisplay != null && { display: thinkingDisplay }
3043
3092
  }
3044
3093
  },
3045
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3094
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3046
3095
  output_config: {
3047
3096
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
3048
3097
  effort: anthropicOptions.effort
3049
3098
  },
3099
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
3100
+ task_budget: {
3101
+ type: anthropicOptions.taskBudget.type,
3102
+ total: anthropicOptions.taskBudget.total,
3103
+ ...anthropicOptions.taskBudget.remaining != null && {
3104
+ remaining: anthropicOptions.taskBudget.remaining
3105
+ }
3106
+ }
3107
+ },
3050
3108
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
3051
3109
  format: {
3052
3110
  type: "json_schema",
@@ -3064,7 +3122,7 @@ var AnthropicMessagesLanguageModel = class {
3064
3122
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3065
3123
  cache_control: anthropicOptions.cacheControl
3066
3124
  },
3067
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
3125
+ ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3068
3126
  metadata: { user_id: anthropicOptions.metadata.userId }
3069
3127
  },
3070
3128
  // mcp servers:
@@ -3234,12 +3292,13 @@ var AnthropicMessagesLanguageModel = class {
3234
3292
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
3235
3293
  betas.add("effort-2025-11-24");
3236
3294
  }
3295
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3296
+ betas.add("task-budgets-2026-03-13");
3297
+ }
3237
3298
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3238
3299
  betas.add("fast-mode-2026-02-01");
3239
3300
  }
3240
- if (stream && ((_h = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _h : true)) {
3241
- betas.add("fine-grained-tool-streaming-2025-05-14");
3242
- }
3301
+ const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
3243
3302
  const {
3244
3303
  tools: anthropicTools2,
3245
3304
  toolChoice: anthropicToolChoice,
@@ -3252,14 +3311,16 @@ var AnthropicMessagesLanguageModel = class {
3252
3311
  disableParallelToolUse: true,
3253
3312
  cacheControlValidator,
3254
3313
  supportsStructuredOutput: false,
3255
- supportsStrictTools
3314
+ supportsStrictTools,
3315
+ defaultEagerInputStreaming
3256
3316
  } : {
3257
3317
  tools: tools != null ? tools : [],
3258
3318
  toolChoice,
3259
3319
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
3260
3320
  cacheControlValidator,
3261
3321
  supportsStructuredOutput,
3262
- supportsStrictTools
3322
+ supportsStrictTools,
3323
+ defaultEagerInputStreaming
3263
3324
  }
3264
3325
  );
3265
3326
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -3276,7 +3337,7 @@ var AnthropicMessagesLanguageModel = class {
3276
3337
  ...betas,
3277
3338
  ...toolsBetas,
3278
3339
  ...userSuppliedBetas,
3279
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
3340
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3280
3341
  ]),
3281
3342
  usesJsonResponseTool: jsonResponseTool != null,
3282
3343
  toolNameMapping,
@@ -4535,46 +4596,60 @@ var AnthropicMessagesLanguageModel = class {
4535
4596
  }
4536
4597
  };
4537
4598
  function getModelCapabilities(modelId) {
4538
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4599
+ if (modelId.includes("claude-opus-4-7")) {
4600
+ return {
4601
+ maxOutputTokens: 128e3,
4602
+ supportsStructuredOutput: true,
4603
+ rejectsSamplingParameters: true,
4604
+ isKnownModel: true
4605
+ };
4606
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4539
4607
  return {
4540
4608
  maxOutputTokens: 128e3,
4541
4609
  supportsStructuredOutput: true,
4610
+ rejectsSamplingParameters: false,
4542
4611
  isKnownModel: true
4543
4612
  };
4544
4613
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
4545
4614
  return {
4546
4615
  maxOutputTokens: 64e3,
4547
4616
  supportsStructuredOutput: true,
4617
+ rejectsSamplingParameters: false,
4548
4618
  isKnownModel: true
4549
4619
  };
4550
4620
  } else if (modelId.includes("claude-opus-4-1")) {
4551
4621
  return {
4552
4622
  maxOutputTokens: 32e3,
4553
4623
  supportsStructuredOutput: true,
4624
+ rejectsSamplingParameters: false,
4554
4625
  isKnownModel: true
4555
4626
  };
4556
4627
  } else if (modelId.includes("claude-sonnet-4-")) {
4557
4628
  return {
4558
4629
  maxOutputTokens: 64e3,
4559
4630
  supportsStructuredOutput: false,
4631
+ rejectsSamplingParameters: false,
4560
4632
  isKnownModel: true
4561
4633
  };
4562
4634
  } else if (modelId.includes("claude-opus-4-")) {
4563
4635
  return {
4564
4636
  maxOutputTokens: 32e3,
4565
4637
  supportsStructuredOutput: false,
4638
+ rejectsSamplingParameters: false,
4566
4639
  isKnownModel: true
4567
4640
  };
4568
4641
  } else if (modelId.includes("claude-3-haiku")) {
4569
4642
  return {
4570
4643
  maxOutputTokens: 4096,
4571
4644
  supportsStructuredOutput: false,
4645
+ rejectsSamplingParameters: false,
4572
4646
  isKnownModel: true
4573
4647
  };
4574
4648
  } else {
4575
4649
  return {
4576
4650
  maxOutputTokens: 4096,
4577
4651
  supportsStructuredOutput: false,
4652
+ rejectsSamplingParameters: false,
4578
4653
  isKnownModel: false
4579
4654
  };
4580
4655
  }