@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.70
4
+
5
+ ### Patch Changes
6
+
7
+ - 2ff8d57: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
8
+
9
+ ## 3.0.69
10
+
11
+ ### Patch Changes
12
+
13
+ - 61f1a61: feat (provider/anthropic): add support for inference_geo provider option
14
+
3
15
  ## 3.0.68
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -128,7 +128,7 @@ interface AnthropicMessageMetadata {
128
128
  } | null;
129
129
  }
130
130
 
131
- 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 & {});
131
+ 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 & {});
132
132
  declare const anthropicLanguageModelOptions: z.ZodObject<{
133
133
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
134
134
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -138,6 +138,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
138
138
  }>>;
139
139
  thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
140
140
  type: z.ZodLiteral<"adaptive">;
141
+ display: z.ZodOptional<z.ZodEnum<{
142
+ omitted: "omitted";
143
+ summarized: "summarized";
144
+ }>>;
141
145
  }, z.core.$strip>, z.ZodObject<{
142
146
  type: z.ZodLiteral<"enabled">;
143
147
  budgetTokens: z.ZodOptional<z.ZodNumber>;
@@ -175,12 +179,22 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
175
179
  low: "low";
176
180
  medium: "medium";
177
181
  high: "high";
182
+ xhigh: "xhigh";
178
183
  max: "max";
179
184
  }>>;
185
+ taskBudget: z.ZodOptional<z.ZodObject<{
186
+ type: z.ZodLiteral<"tokens">;
187
+ total: z.ZodNumber;
188
+ remaining: z.ZodOptional<z.ZodNumber>;
189
+ }, z.core.$strip>>;
180
190
  speed: z.ZodOptional<z.ZodEnum<{
181
191
  fast: "fast";
182
192
  standard: "standard";
183
193
  }>>;
194
+ inferenceGeo: z.ZodOptional<z.ZodEnum<{
195
+ us: "us";
196
+ global: "global";
197
+ }>>;
184
198
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
185
199
  contextManagement: z.ZodOptional<z.ZodObject<{
186
200
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -128,7 +128,7 @@ interface AnthropicMessageMetadata {
128
128
  } | null;
129
129
  }
130
130
 
131
- 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 & {});
131
+ 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 & {});
132
132
  declare const anthropicLanguageModelOptions: z.ZodObject<{
133
133
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
134
134
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -138,6 +138,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
138
138
  }>>;
139
139
  thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
140
140
  type: z.ZodLiteral<"adaptive">;
141
+ display: z.ZodOptional<z.ZodEnum<{
142
+ omitted: "omitted";
143
+ summarized: "summarized";
144
+ }>>;
141
145
  }, z.core.$strip>, z.ZodObject<{
142
146
  type: z.ZodLiteral<"enabled">;
143
147
  budgetTokens: z.ZodOptional<z.ZodNumber>;
@@ -175,12 +179,22 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
175
179
  low: "low";
176
180
  medium: "medium";
177
181
  high: "high";
182
+ xhigh: "xhigh";
178
183
  max: "max";
179
184
  }>>;
185
+ taskBudget: z.ZodOptional<z.ZodObject<{
186
+ type: z.ZodLiteral<"tokens">;
187
+ total: z.ZodNumber;
188
+ remaining: z.ZodOptional<z.ZodNumber>;
189
+ }, z.core.$strip>>;
180
190
  speed: z.ZodOptional<z.ZodEnum<{
181
191
  fast: "fast";
182
192
  standard: "standard";
183
193
  }>>;
194
+ inferenceGeo: z.ZodOptional<z.ZodEnum<{
195
+ us: "us";
196
+ global: "global";
197
+ }>>;
184
198
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
185
199
  contextManagement: z.ZodOptional<z.ZodObject<{
186
200
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.68" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.70" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -845,7 +845,13 @@ var anthropicLanguageModelOptions = import_v43.z.object({
845
845
  thinking: import_v43.z.discriminatedUnion("type", [
846
846
  import_v43.z.object({
847
847
  /** for Sonnet 4.6, Opus 4.6, and newer models */
848
- type: import_v43.z.literal("adaptive")
848
+ type: import_v43.z.literal("adaptive"),
849
+ /**
850
+ * Controls whether thinking content is included in the response.
851
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
852
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
853
+ */
854
+ display: import_v43.z.enum(["omitted", "summarized"]).optional()
849
855
  }),
850
856
  import_v43.z.object({
851
857
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
@@ -925,12 +931,33 @@ var anthropicLanguageModelOptions = import_v43.z.object({
925
931
  /**
926
932
  * @default 'high'
927
933
  */
928
- effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
934
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
935
+ /**
936
+ * Task budget for agentic turns. Informs the model of the total token budget
937
+ * available for the current task, allowing it to prioritize work and wind down
938
+ * gracefully as the budget is consumed.
939
+ *
940
+ * Advisory only — does not enforce a hard token limit.
941
+ */
942
+ taskBudget: import_v43.z.object({
943
+ type: import_v43.z.literal("tokens"),
944
+ total: import_v43.z.number().int().min(2e4),
945
+ remaining: import_v43.z.number().int().min(0).optional()
946
+ }).optional(),
929
947
  /**
930
948
  * Enable fast mode for faster inference (2.5x faster output token speeds).
931
949
  * Only supported with claude-opus-4-6.
932
950
  */
933
951
  speed: import_v43.z.enum(["fast", "standard"]).optional(),
952
+ /**
953
+ * Controls where model inference runs for this request.
954
+ *
955
+ * - `"global"`: Inference may run in any available geography (default).
956
+ * - `"us"`: Inference runs only in US-based infrastructure.
957
+ *
958
+ * See https://platform.claude.com/docs/en/build-with-claude/data-residency
959
+ */
960
+ inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
934
961
  /**
935
962
  * A set of beta features to enable.
936
963
  * Allow a provider to receive the full `betas` set if it needs it.
@@ -2892,7 +2919,7 @@ var AnthropicMessagesLanguageModel = class {
2892
2919
  providerOptions,
2893
2920
  stream
2894
2921
  }) {
2895
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2922
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2896
2923
  const warnings = [];
2897
2924
  if (frequencyPenalty != null) {
2898
2925
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2947,8 +2974,35 @@ var AnthropicMessagesLanguageModel = class {
2947
2974
  const {
2948
2975
  maxOutputTokens: maxOutputTokensForModel,
2949
2976
  supportsStructuredOutput: modelSupportsStructuredOutput,
2977
+ rejectsSamplingParameters,
2950
2978
  isKnownModel
2951
2979
  } = getModelCapabilities(this.modelId);
2980
+ if (rejectsSamplingParameters) {
2981
+ if (temperature != null) {
2982
+ warnings.push({
2983
+ type: "unsupported",
2984
+ feature: "temperature",
2985
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2986
+ });
2987
+ temperature = void 0;
2988
+ }
2989
+ if (topK != null) {
2990
+ warnings.push({
2991
+ type: "unsupported",
2992
+ feature: "topK",
2993
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2994
+ });
2995
+ topK = void 0;
2996
+ }
2997
+ if (topP != null) {
2998
+ warnings.push({
2999
+ type: "unsupported",
3000
+ feature: "topP",
3001
+ details: `topP is not supported by ${this.modelId} and will be ignored`
3002
+ });
3003
+ topP = void 0;
3004
+ }
3005
+ }
2952
3006
  const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2953
3007
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2954
3008
  const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
@@ -2995,6 +3049,7 @@ var AnthropicMessagesLanguageModel = class {
2995
3049
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
2996
3050
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2997
3051
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3052
+ const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
2998
3053
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2999
3054
  const baseArgs = {
3000
3055
  // model id:
@@ -3009,14 +3064,24 @@ var AnthropicMessagesLanguageModel = class {
3009
3064
  ...isThinking && {
3010
3065
  thinking: {
3011
3066
  type: thinkingType,
3012
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
3067
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3068
+ ...thinkingDisplay != null && { display: thinkingDisplay }
3013
3069
  }
3014
3070
  },
3015
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3071
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3016
3072
  output_config: {
3017
3073
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
3018
3074
  effort: anthropicOptions.effort
3019
3075
  },
3076
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
3077
+ task_budget: {
3078
+ type: anthropicOptions.taskBudget.type,
3079
+ total: anthropicOptions.taskBudget.total,
3080
+ ...anthropicOptions.taskBudget.remaining != null && {
3081
+ remaining: anthropicOptions.taskBudget.remaining
3082
+ }
3083
+ }
3084
+ },
3020
3085
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
3021
3086
  format: {
3022
3087
  type: "json_schema",
@@ -3028,10 +3093,13 @@ var AnthropicMessagesLanguageModel = class {
3028
3093
  ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
3029
3094
  speed: anthropicOptions.speed
3030
3095
  },
3096
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3097
+ inference_geo: anthropicOptions.inferenceGeo
3098
+ },
3031
3099
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3032
3100
  cache_control: anthropicOptions.cacheControl
3033
3101
  },
3034
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
3102
+ ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3035
3103
  metadata: { user_id: anthropicOptions.metadata.userId }
3036
3104
  },
3037
3105
  // mcp servers:
@@ -3201,10 +3269,13 @@ var AnthropicMessagesLanguageModel = class {
3201
3269
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
3202
3270
  betas.add("effort-2025-11-24");
3203
3271
  }
3272
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3273
+ betas.add("task-budgets-2026-03-13");
3274
+ }
3204
3275
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3205
3276
  betas.add("fast-mode-2026-02-01");
3206
3277
  }
3207
- if (stream && ((_h = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _h : true)) {
3278
+ if (stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true)) {
3208
3279
  betas.add("fine-grained-tool-streaming-2025-05-14");
3209
3280
  }
3210
3281
  const {
@@ -3243,7 +3314,7 @@ var AnthropicMessagesLanguageModel = class {
3243
3314
  ...betas,
3244
3315
  ...toolsBetas,
3245
3316
  ...userSuppliedBetas,
3246
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
3317
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3247
3318
  ]),
3248
3319
  usesJsonResponseTool: jsonResponseTool != null,
3249
3320
  toolNameMapping,
@@ -4502,46 +4573,60 @@ var AnthropicMessagesLanguageModel = class {
4502
4573
  }
4503
4574
  };
4504
4575
  function getModelCapabilities(modelId) {
4505
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4576
+ if (modelId.includes("claude-opus-4-7")) {
4577
+ return {
4578
+ maxOutputTokens: 128e3,
4579
+ supportsStructuredOutput: true,
4580
+ rejectsSamplingParameters: true,
4581
+ isKnownModel: true
4582
+ };
4583
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4506
4584
  return {
4507
4585
  maxOutputTokens: 128e3,
4508
4586
  supportsStructuredOutput: true,
4587
+ rejectsSamplingParameters: false,
4509
4588
  isKnownModel: true
4510
4589
  };
4511
4590
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
4512
4591
  return {
4513
4592
  maxOutputTokens: 64e3,
4514
4593
  supportsStructuredOutput: true,
4594
+ rejectsSamplingParameters: false,
4515
4595
  isKnownModel: true
4516
4596
  };
4517
4597
  } else if (modelId.includes("claude-opus-4-1")) {
4518
4598
  return {
4519
4599
  maxOutputTokens: 32e3,
4520
4600
  supportsStructuredOutput: true,
4601
+ rejectsSamplingParameters: false,
4521
4602
  isKnownModel: true
4522
4603
  };
4523
4604
  } else if (modelId.includes("claude-sonnet-4-")) {
4524
4605
  return {
4525
4606
  maxOutputTokens: 64e3,
4526
4607
  supportsStructuredOutput: false,
4608
+ rejectsSamplingParameters: false,
4527
4609
  isKnownModel: true
4528
4610
  };
4529
4611
  } else if (modelId.includes("claude-opus-4-")) {
4530
4612
  return {
4531
4613
  maxOutputTokens: 32e3,
4532
4614
  supportsStructuredOutput: false,
4615
+ rejectsSamplingParameters: false,
4533
4616
  isKnownModel: true
4534
4617
  };
4535
4618
  } else if (modelId.includes("claude-3-haiku")) {
4536
4619
  return {
4537
4620
  maxOutputTokens: 4096,
4538
4621
  supportsStructuredOutput: false,
4622
+ rejectsSamplingParameters: false,
4539
4623
  isKnownModel: true
4540
4624
  };
4541
4625
  } else {
4542
4626
  return {
4543
4627
  maxOutputTokens: 4096,
4544
4628
  supportsStructuredOutput: false,
4629
+ rejectsSamplingParameters: false,
4545
4630
  isKnownModel: false
4546
4631
  };
4547
4632
  }