@ai-sdk/anthropic 3.0.68 → 3.0.70

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;
@@ -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;
@@ -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 */
@@ -917,12 +923,33 @@ var anthropicLanguageModelOptions = import_v43.z.object({
917
923
  /**
918
924
  * @default 'high'
919
925
  */
920
- effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
926
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
927
+ /**
928
+ * Task budget for agentic turns. Informs the model of the total token budget
929
+ * available for the current task, allowing it to prioritize work and wind down
930
+ * gracefully as the budget is consumed.
931
+ *
932
+ * Advisory only — does not enforce a hard token limit.
933
+ */
934
+ taskBudget: import_v43.z.object({
935
+ type: import_v43.z.literal("tokens"),
936
+ total: import_v43.z.number().int().min(2e4),
937
+ remaining: import_v43.z.number().int().min(0).optional()
938
+ }).optional(),
921
939
  /**
922
940
  * Enable fast mode for faster inference (2.5x faster output token speeds).
923
941
  * Only supported with claude-opus-4-6.
924
942
  */
925
943
  speed: import_v43.z.enum(["fast", "standard"]).optional(),
944
+ /**
945
+ * Controls where model inference runs for this request.
946
+ *
947
+ * - `"global"`: Inference may run in any available geography (default).
948
+ * - `"us"`: Inference runs only in US-based infrastructure.
949
+ *
950
+ * See https://platform.claude.com/docs/en/build-with-claude/data-residency
951
+ */
952
+ inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
926
953
  /**
927
954
  * A set of beta features to enable.
928
955
  * Allow a provider to receive the full `betas` set if it needs it.
@@ -2884,7 +2911,7 @@ var AnthropicMessagesLanguageModel = class {
2884
2911
  providerOptions,
2885
2912
  stream
2886
2913
  }) {
2887
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2914
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2888
2915
  const warnings = [];
2889
2916
  if (frequencyPenalty != null) {
2890
2917
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2939,8 +2966,35 @@ var AnthropicMessagesLanguageModel = class {
2939
2966
  const {
2940
2967
  maxOutputTokens: maxOutputTokensForModel,
2941
2968
  supportsStructuredOutput: modelSupportsStructuredOutput,
2969
+ rejectsSamplingParameters,
2942
2970
  isKnownModel
2943
2971
  } = getModelCapabilities(this.modelId);
2972
+ if (rejectsSamplingParameters) {
2973
+ if (temperature != null) {
2974
+ warnings.push({
2975
+ type: "unsupported",
2976
+ feature: "temperature",
2977
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2978
+ });
2979
+ temperature = void 0;
2980
+ }
2981
+ if (topK != null) {
2982
+ warnings.push({
2983
+ type: "unsupported",
2984
+ feature: "topK",
2985
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2986
+ });
2987
+ topK = void 0;
2988
+ }
2989
+ if (topP != null) {
2990
+ warnings.push({
2991
+ type: "unsupported",
2992
+ feature: "topP",
2993
+ details: `topP is not supported by ${this.modelId} and will be ignored`
2994
+ });
2995
+ topP = void 0;
2996
+ }
2997
+ }
2944
2998
  const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2945
2999
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2946
3000
  const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
@@ -2987,6 +3041,7 @@ var AnthropicMessagesLanguageModel = class {
2987
3041
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
2988
3042
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2989
3043
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3044
+ const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
2990
3045
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2991
3046
  const baseArgs = {
2992
3047
  // model id:
@@ -3001,14 +3056,24 @@ var AnthropicMessagesLanguageModel = class {
3001
3056
  ...isThinking && {
3002
3057
  thinking: {
3003
3058
  type: thinkingType,
3004
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
3059
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3060
+ ...thinkingDisplay != null && { display: thinkingDisplay }
3005
3061
  }
3006
3062
  },
3007
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3063
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3008
3064
  output_config: {
3009
3065
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
3010
3066
  effort: anthropicOptions.effort
3011
3067
  },
3068
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
3069
+ task_budget: {
3070
+ type: anthropicOptions.taskBudget.type,
3071
+ total: anthropicOptions.taskBudget.total,
3072
+ ...anthropicOptions.taskBudget.remaining != null && {
3073
+ remaining: anthropicOptions.taskBudget.remaining
3074
+ }
3075
+ }
3076
+ },
3012
3077
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
3013
3078
  format: {
3014
3079
  type: "json_schema",
@@ -3020,10 +3085,13 @@ var AnthropicMessagesLanguageModel = class {
3020
3085
  ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
3021
3086
  speed: anthropicOptions.speed
3022
3087
  },
3088
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3089
+ inference_geo: anthropicOptions.inferenceGeo
3090
+ },
3023
3091
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3024
3092
  cache_control: anthropicOptions.cacheControl
3025
3093
  },
3026
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
3094
+ ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3027
3095
  metadata: { user_id: anthropicOptions.metadata.userId }
3028
3096
  },
3029
3097
  // mcp servers:
@@ -3193,10 +3261,13 @@ var AnthropicMessagesLanguageModel = class {
3193
3261
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
3194
3262
  betas.add("effort-2025-11-24");
3195
3263
  }
3264
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3265
+ betas.add("task-budgets-2026-03-13");
3266
+ }
3196
3267
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3197
3268
  betas.add("fast-mode-2026-02-01");
3198
3269
  }
3199
- if (stream && ((_h = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _h : true)) {
3270
+ if (stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true)) {
3200
3271
  betas.add("fine-grained-tool-streaming-2025-05-14");
3201
3272
  }
3202
3273
  const {
@@ -3235,7 +3306,7 @@ var AnthropicMessagesLanguageModel = class {
3235
3306
  ...betas,
3236
3307
  ...toolsBetas,
3237
3308
  ...userSuppliedBetas,
3238
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
3309
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3239
3310
  ]),
3240
3311
  usesJsonResponseTool: jsonResponseTool != null,
3241
3312
  toolNameMapping,
@@ -4494,46 +4565,60 @@ var AnthropicMessagesLanguageModel = class {
4494
4565
  }
4495
4566
  };
4496
4567
  function getModelCapabilities(modelId) {
4497
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4568
+ if (modelId.includes("claude-opus-4-7")) {
4569
+ return {
4570
+ maxOutputTokens: 128e3,
4571
+ supportsStructuredOutput: true,
4572
+ rejectsSamplingParameters: true,
4573
+ isKnownModel: true
4574
+ };
4575
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4498
4576
  return {
4499
4577
  maxOutputTokens: 128e3,
4500
4578
  supportsStructuredOutput: true,
4579
+ rejectsSamplingParameters: false,
4501
4580
  isKnownModel: true
4502
4581
  };
4503
4582
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
4504
4583
  return {
4505
4584
  maxOutputTokens: 64e3,
4506
4585
  supportsStructuredOutput: true,
4586
+ rejectsSamplingParameters: false,
4507
4587
  isKnownModel: true
4508
4588
  };
4509
4589
  } else if (modelId.includes("claude-opus-4-1")) {
4510
4590
  return {
4511
4591
  maxOutputTokens: 32e3,
4512
4592
  supportsStructuredOutput: true,
4593
+ rejectsSamplingParameters: false,
4513
4594
  isKnownModel: true
4514
4595
  };
4515
4596
  } else if (modelId.includes("claude-sonnet-4-")) {
4516
4597
  return {
4517
4598
  maxOutputTokens: 64e3,
4518
4599
  supportsStructuredOutput: false,
4600
+ rejectsSamplingParameters: false,
4519
4601
  isKnownModel: true
4520
4602
  };
4521
4603
  } else if (modelId.includes("claude-opus-4-")) {
4522
4604
  return {
4523
4605
  maxOutputTokens: 32e3,
4524
4606
  supportsStructuredOutput: false,
4607
+ rejectsSamplingParameters: false,
4525
4608
  isKnownModel: true
4526
4609
  };
4527
4610
  } else if (modelId.includes("claude-3-haiku")) {
4528
4611
  return {
4529
4612
  maxOutputTokens: 4096,
4530
4613
  supportsStructuredOutput: false,
4614
+ rejectsSamplingParameters: false,
4531
4615
  isKnownModel: true
4532
4616
  };
4533
4617
  } else {
4534
4618
  return {
4535
4619
  maxOutputTokens: 4096,
4536
4620
  supportsStructuredOutput: false,
4621
+ rejectsSamplingParameters: false,
4537
4622
  isKnownModel: false
4538
4623
  };
4539
4624
  }