@ai-sdk/anthropic 2.0.74 → 2.0.76

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
+ ## 2.0.76
4
+
5
+ ### Patch Changes
6
+
7
+ - 2fe3997: feat (provider/anthropic): add support for inference_geo provider option
8
+
9
+ ## 2.0.75
10
+
11
+ ### Patch Changes
12
+
13
+ - 4b40033: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
14
+
3
15
  ## 2.0.74
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -126,7 +126,7 @@ interface AnthropicMessageMetadata {
126
126
  } | null;
127
127
  }
128
128
 
129
- type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
129
+ type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
130
130
  declare const anthropicProviderOptions: z.ZodObject<{
131
131
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
132
132
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -136,6 +136,10 @@ declare const anthropicProviderOptions: z.ZodObject<{
136
136
  }>>;
137
137
  thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
138
138
  type: z.ZodLiteral<"adaptive">;
139
+ display: z.ZodOptional<z.ZodEnum<{
140
+ omitted: "omitted";
141
+ summarized: "summarized";
142
+ }>>;
139
143
  }, z.core.$strip>, z.ZodObject<{
140
144
  type: z.ZodLiteral<"enabled">;
141
145
  budgetTokens: z.ZodOptional<z.ZodNumber>;
@@ -162,12 +166,22 @@ declare const anthropicProviderOptions: z.ZodObject<{
162
166
  low: "low";
163
167
  medium: "medium";
164
168
  high: "high";
169
+ xhigh: "xhigh";
165
170
  max: "max";
166
171
  }>>;
172
+ taskBudget: z.ZodOptional<z.ZodObject<{
173
+ type: z.ZodLiteral<"tokens">;
174
+ total: z.ZodNumber;
175
+ remaining: z.ZodOptional<z.ZodNumber>;
176
+ }, z.core.$strip>>;
167
177
  speed: z.ZodOptional<z.ZodEnum<{
168
178
  fast: "fast";
169
179
  standard: "standard";
170
180
  }>>;
181
+ inferenceGeo: z.ZodOptional<z.ZodEnum<{
182
+ us: "us";
183
+ global: "global";
184
+ }>>;
171
185
  contextManagement: z.ZodOptional<z.ZodObject<{
172
186
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
173
187
  type: z.ZodLiteral<"clear_tool_uses_20250919">;
package/dist/index.d.ts CHANGED
@@ -126,7 +126,7 @@ interface AnthropicMessageMetadata {
126
126
  } | null;
127
127
  }
128
128
 
129
- type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
129
+ type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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 & {});
130
130
  declare const anthropicProviderOptions: z.ZodObject<{
131
131
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
132
132
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -136,6 +136,10 @@ declare const anthropicProviderOptions: z.ZodObject<{
136
136
  }>>;
137
137
  thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
138
138
  type: z.ZodLiteral<"adaptive">;
139
+ display: z.ZodOptional<z.ZodEnum<{
140
+ omitted: "omitted";
141
+ summarized: "summarized";
142
+ }>>;
139
143
  }, z.core.$strip>, z.ZodObject<{
140
144
  type: z.ZodLiteral<"enabled">;
141
145
  budgetTokens: z.ZodOptional<z.ZodNumber>;
@@ -162,12 +166,22 @@ declare const anthropicProviderOptions: z.ZodObject<{
162
166
  low: "low";
163
167
  medium: "medium";
164
168
  high: "high";
169
+ xhigh: "xhigh";
165
170
  max: "max";
166
171
  }>>;
172
+ taskBudget: z.ZodOptional<z.ZodObject<{
173
+ type: z.ZodLiteral<"tokens">;
174
+ total: z.ZodNumber;
175
+ remaining: z.ZodOptional<z.ZodNumber>;
176
+ }, z.core.$strip>>;
167
177
  speed: z.ZodOptional<z.ZodEnum<{
168
178
  fast: "fast";
169
179
  standard: "standard";
170
180
  }>>;
181
+ inferenceGeo: z.ZodOptional<z.ZodEnum<{
182
+ us: "us";
183
+ global: "global";
184
+ }>>;
171
185
  contextManagement: z.ZodOptional<z.ZodObject<{
172
186
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
173
187
  type: z.ZodLiteral<"clear_tool_uses_20250919">;
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils21 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.74" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.76" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -649,7 +649,13 @@ var anthropicProviderOptions = import_v43.z.object({
649
649
  thinking: import_v43.z.discriminatedUnion("type", [
650
650
  import_v43.z.object({
651
651
  /** for Sonnet 4.6, Opus 4.6, and newer models */
652
- type: import_v43.z.literal("adaptive")
652
+ type: import_v43.z.literal("adaptive"),
653
+ /**
654
+ * Controls whether thinking content is included in the response.
655
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
656
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
657
+ */
658
+ display: import_v43.z.enum(["omitted", "summarized"]).optional()
653
659
  }),
654
660
  import_v43.z.object({
655
661
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
@@ -705,12 +711,33 @@ var anthropicProviderOptions = import_v43.z.object({
705
711
  /**
706
712
  * @default 'high'
707
713
  */
708
- effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
714
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
715
+ /**
716
+ * Task budget for agentic turns. Informs the model of the total token budget
717
+ * available for the current task, allowing it to prioritize work and wind down
718
+ * gracefully as the budget is consumed.
719
+ *
720
+ * Advisory only — does not enforce a hard token limit.
721
+ */
722
+ taskBudget: import_v43.z.object({
723
+ type: import_v43.z.literal("tokens"),
724
+ total: import_v43.z.number().int().min(2e4),
725
+ remaining: import_v43.z.number().int().min(0).optional()
726
+ }).optional(),
709
727
  /**
710
728
  * Enable fast mode for faster inference (2.5x faster output token speeds).
711
729
  * Only supported with claude-opus-4-6.
712
730
  */
713
731
  speed: import_v43.z.enum(["fast", "standard"]).optional(),
732
+ /**
733
+ * Controls where model inference runs for this request.
734
+ *
735
+ * - `"global"`: Inference may run in any available geography (default).
736
+ * - `"us"`: Inference runs only in US-based infrastructure.
737
+ *
738
+ * See https://platform.claude.com/docs/en/build-with-claude/data-residency
739
+ */
740
+ inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
714
741
  /**
715
742
  * Context management configuration for automatic context window management.
716
743
  * Enables features like automatic compaction and clearing of tool uses/thinking blocks.
@@ -1972,7 +1999,7 @@ var AnthropicMessagesLanguageModel = class {
1972
1999
  toolChoice,
1973
2000
  providerOptions
1974
2001
  }) {
1975
- var _a, _b, _c, _d, _e, _f, _g;
2002
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1976
2003
  const warnings = [];
1977
2004
  if (frequencyPenalty != null) {
1978
2005
  warnings.push({
@@ -2030,8 +2057,36 @@ var AnthropicMessagesLanguageModel = class {
2030
2057
  const {
2031
2058
  maxOutputTokens: maxOutputTokensForModel,
2032
2059
  supportsStructuredOutput,
2060
+ rejectsSamplingParameters,
2033
2061
  isKnownModel
2034
2062
  } = getModelCapabilities(this.modelId);
2063
+ if (rejectsSamplingParameters) {
2064
+ if (temperature != null) {
2065
+ warnings.push({
2066
+ type: "unsupported-setting",
2067
+ setting: "temperature",
2068
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2069
+ });
2070
+ temperature = void 0;
2071
+ }
2072
+ if (topK != null) {
2073
+ warnings.push({
2074
+ type: "unsupported-setting",
2075
+ setting: "topK",
2076
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2077
+ });
2078
+ topK = void 0;
2079
+ }
2080
+ if (topP != null) {
2081
+ warnings.push({
2082
+ type: "unsupported-setting",
2083
+ setting: "topP",
2084
+ details: `topP is not supported by ${this.modelId} and will be ignored`
2085
+ });
2086
+ topP = void 0;
2087
+ }
2088
+ }
2089
+ const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2035
2090
  const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
2036
2091
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2037
2092
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
@@ -2050,6 +2105,7 @@ var AnthropicMessagesLanguageModel = class {
2050
2105
  const thinkingType = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type;
2051
2106
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2052
2107
  let thinkingBudget = thinkingType === "enabled" ? (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens : void 0;
2108
+ const thinkingDisplay = thinkingType === "adaptive" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.display : void 0;
2053
2109
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2054
2110
  const baseArgs = {
2055
2111
  // model id:
@@ -2064,19 +2120,42 @@ var AnthropicMessagesLanguageModel = class {
2064
2120
  ...isThinking && {
2065
2121
  thinking: {
2066
2122
  type: thinkingType,
2067
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
2123
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2124
+ ...thinkingDisplay != null && { display: thinkingDisplay }
2068
2125
  }
2069
2126
  },
2070
- ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
2071
- output_config: { effort: anthropicOptions.effort }
2127
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
2128
+ output_config: {
2129
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
2130
+ effort: anthropicOptions.effort
2131
+ },
2132
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
2133
+ task_budget: {
2134
+ type: anthropicOptions.taskBudget.type,
2135
+ total: anthropicOptions.taskBudget.total,
2136
+ ...anthropicOptions.taskBudget.remaining != null && {
2137
+ remaining: anthropicOptions.taskBudget.remaining
2138
+ }
2139
+ }
2140
+ },
2141
+ ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
2142
+ format: {
2143
+ type: "json_schema",
2144
+ schema: responseFormat.schema
2145
+ }
2146
+ }
2147
+ }
2072
2148
  },
2073
2149
  ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
2074
2150
  speed: anthropicOptions.speed
2075
2151
  },
2152
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
2153
+ inference_geo: anthropicOptions.inferenceGeo
2154
+ },
2076
2155
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2077
2156
  cache_control: anthropicOptions.cacheControl
2078
2157
  },
2079
- ...((_e = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _e.userId) != null && {
2158
+ ...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
2080
2159
  metadata: { user_id: anthropicOptions.metadata.userId }
2081
2160
  },
2082
2161
  // structured output:
@@ -2090,7 +2169,7 @@ var AnthropicMessagesLanguageModel = class {
2090
2169
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2091
2170
  container: {
2092
2171
  id: anthropicOptions.container.id,
2093
- skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2172
+ skills: (_g = anthropicOptions.container.skills) == null ? void 0 : _g.map((skill) => ({
2094
2173
  type: skill.type,
2095
2174
  skill_id: skill.skillId,
2096
2175
  version: skill.version
@@ -2210,6 +2289,9 @@ var AnthropicMessagesLanguageModel = class {
2210
2289
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2211
2290
  betas.add("effort-2025-11-24");
2212
2291
  }
2292
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
2293
+ betas.add("task-budgets-2026-03-13");
2294
+ }
2213
2295
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
2214
2296
  betas.add("fast-mode-2026-02-01");
2215
2297
  }
@@ -2253,7 +2335,7 @@ var AnthropicMessagesLanguageModel = class {
2253
2335
  ...betas,
2254
2336
  ...toolsBetas,
2255
2337
  ...userSuppliedBetas,
2256
- ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
2338
+ ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
2257
2339
  ]),
2258
2340
  usesJsonResponseTool: jsonResponseTool != null
2259
2341
  };
@@ -3217,52 +3299,67 @@ var AnthropicMessagesLanguageModel = class {
3217
3299
  }
3218
3300
  };
3219
3301
  function getModelCapabilities(modelId) {
3220
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
3302
+ if (modelId.includes("claude-opus-4-7")) {
3303
+ return {
3304
+ maxOutputTokens: 128e3,
3305
+ supportsStructuredOutput: true,
3306
+ rejectsSamplingParameters: true,
3307
+ isKnownModel: true
3308
+ };
3309
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
3221
3310
  return {
3222
3311
  maxOutputTokens: 128e3,
3223
3312
  supportsStructuredOutput: true,
3313
+ rejectsSamplingParameters: false,
3224
3314
  isKnownModel: true
3225
3315
  };
3226
3316
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
3227
3317
  return {
3228
3318
  maxOutputTokens: 64e3,
3229
3319
  supportsStructuredOutput: true,
3320
+ rejectsSamplingParameters: false,
3230
3321
  isKnownModel: true
3231
3322
  };
3232
3323
  } else if (modelId.includes("claude-opus-4-1")) {
3233
3324
  return {
3234
3325
  maxOutputTokens: 32e3,
3235
3326
  supportsStructuredOutput: true,
3327
+ rejectsSamplingParameters: false,
3236
3328
  isKnownModel: true
3237
3329
  };
3238
3330
  } else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet")) {
3239
3331
  return {
3240
3332
  maxOutputTokens: 64e3,
3241
3333
  supportsStructuredOutput: false,
3334
+ rejectsSamplingParameters: false,
3242
3335
  isKnownModel: true
3243
3336
  };
3244
3337
  } else if (modelId.includes("claude-opus-4-")) {
3245
3338
  return {
3246
3339
  maxOutputTokens: 32e3,
3247
3340
  supportsStructuredOutput: false,
3341
+ rejectsSamplingParameters: false,
3248
3342
  isKnownModel: true
3249
3343
  };
3250
3344
  } else if (modelId.includes("claude-3-5-haiku")) {
3251
3345
  return {
3252
3346
  maxOutputTokens: 8192,
3253
3347
  supportsStructuredOutput: false,
3348
+ rejectsSamplingParameters: false,
3254
3349
  isKnownModel: true
3255
3350
  };
3256
3351
  } else if (modelId.includes("claude-3-haiku")) {
3257
3352
  return {
3258
3353
  maxOutputTokens: 4096,
3259
3354
  supportsStructuredOutput: false,
3355
+ rejectsSamplingParameters: false,
3260
3356
  isKnownModel: true
3261
3357
  };
3262
3358
  } else {
3263
3359
  return {
3264
3360
  maxOutputTokens: 4096,
3265
3361
  supportsStructuredOutput: false,
3362
+ rejectsSamplingParameters: false,
3266
3363
  isKnownModel: false
3267
3364
  };
3268
3365
  }