@ai-sdk/anthropic 2.0.74 → 2.0.75

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,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.75
4
+
5
+ ### Patch Changes
6
+
7
+ - 4b40033: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
8
+
3
9
  ## 2.0.74
4
10
 
5
11
  ### 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,8 +166,14 @@ 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";
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,8 +166,14 @@ 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";
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.75" : "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,7 +711,19 @@ 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.
@@ -1972,7 +1990,7 @@ var AnthropicMessagesLanguageModel = class {
1972
1990
  toolChoice,
1973
1991
  providerOptions
1974
1992
  }) {
1975
- var _a, _b, _c, _d, _e, _f, _g;
1993
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1976
1994
  const warnings = [];
1977
1995
  if (frequencyPenalty != null) {
1978
1996
  warnings.push({
@@ -2030,8 +2048,36 @@ var AnthropicMessagesLanguageModel = class {
2030
2048
  const {
2031
2049
  maxOutputTokens: maxOutputTokensForModel,
2032
2050
  supportsStructuredOutput,
2051
+ rejectsSamplingParameters,
2033
2052
  isKnownModel
2034
2053
  } = getModelCapabilities(this.modelId);
2054
+ if (rejectsSamplingParameters) {
2055
+ if (temperature != null) {
2056
+ warnings.push({
2057
+ type: "unsupported-setting",
2058
+ setting: "temperature",
2059
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2060
+ });
2061
+ temperature = void 0;
2062
+ }
2063
+ if (topK != null) {
2064
+ warnings.push({
2065
+ type: "unsupported-setting",
2066
+ setting: "topK",
2067
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2068
+ });
2069
+ topK = void 0;
2070
+ }
2071
+ if (topP != null) {
2072
+ warnings.push({
2073
+ type: "unsupported-setting",
2074
+ setting: "topP",
2075
+ details: `topP is not supported by ${this.modelId} and will be ignored`
2076
+ });
2077
+ topP = void 0;
2078
+ }
2079
+ }
2080
+ const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2035
2081
  const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
2036
2082
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2037
2083
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
@@ -2050,6 +2096,7 @@ var AnthropicMessagesLanguageModel = class {
2050
2096
  const thinkingType = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type;
2051
2097
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2052
2098
  let thinkingBudget = thinkingType === "enabled" ? (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens : void 0;
2099
+ const thinkingDisplay = thinkingType === "adaptive" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.display : void 0;
2053
2100
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2054
2101
  const baseArgs = {
2055
2102
  // model id:
@@ -2064,11 +2111,31 @@ var AnthropicMessagesLanguageModel = class {
2064
2111
  ...isThinking && {
2065
2112
  thinking: {
2066
2113
  type: thinkingType,
2067
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
2114
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2115
+ ...thinkingDisplay != null && { display: thinkingDisplay }
2068
2116
  }
2069
2117
  },
2070
- ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
2071
- output_config: { effort: anthropicOptions.effort }
2118
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
2119
+ output_config: {
2120
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
2121
+ effort: anthropicOptions.effort
2122
+ },
2123
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
2124
+ task_budget: {
2125
+ type: anthropicOptions.taskBudget.type,
2126
+ total: anthropicOptions.taskBudget.total,
2127
+ ...anthropicOptions.taskBudget.remaining != null && {
2128
+ remaining: anthropicOptions.taskBudget.remaining
2129
+ }
2130
+ }
2131
+ },
2132
+ ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
2133
+ format: {
2134
+ type: "json_schema",
2135
+ schema: responseFormat.schema
2136
+ }
2137
+ }
2138
+ }
2072
2139
  },
2073
2140
  ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
2074
2141
  speed: anthropicOptions.speed
@@ -2076,7 +2143,7 @@ var AnthropicMessagesLanguageModel = class {
2076
2143
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2077
2144
  cache_control: anthropicOptions.cacheControl
2078
2145
  },
2079
- ...((_e = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _e.userId) != null && {
2146
+ ...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
2080
2147
  metadata: { user_id: anthropicOptions.metadata.userId }
2081
2148
  },
2082
2149
  // structured output:
@@ -2090,7 +2157,7 @@ var AnthropicMessagesLanguageModel = class {
2090
2157
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2091
2158
  container: {
2092
2159
  id: anthropicOptions.container.id,
2093
- skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2160
+ skills: (_g = anthropicOptions.container.skills) == null ? void 0 : _g.map((skill) => ({
2094
2161
  type: skill.type,
2095
2162
  skill_id: skill.skillId,
2096
2163
  version: skill.version
@@ -2210,6 +2277,9 @@ var AnthropicMessagesLanguageModel = class {
2210
2277
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2211
2278
  betas.add("effort-2025-11-24");
2212
2279
  }
2280
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
2281
+ betas.add("task-budgets-2026-03-13");
2282
+ }
2213
2283
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
2214
2284
  betas.add("fast-mode-2026-02-01");
2215
2285
  }
@@ -2253,7 +2323,7 @@ var AnthropicMessagesLanguageModel = class {
2253
2323
  ...betas,
2254
2324
  ...toolsBetas,
2255
2325
  ...userSuppliedBetas,
2256
- ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
2326
+ ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
2257
2327
  ]),
2258
2328
  usesJsonResponseTool: jsonResponseTool != null
2259
2329
  };
@@ -3217,52 +3287,67 @@ var AnthropicMessagesLanguageModel = class {
3217
3287
  }
3218
3288
  };
3219
3289
  function getModelCapabilities(modelId) {
3220
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
3290
+ if (modelId.includes("claude-opus-4-7")) {
3291
+ return {
3292
+ maxOutputTokens: 128e3,
3293
+ supportsStructuredOutput: true,
3294
+ rejectsSamplingParameters: true,
3295
+ isKnownModel: true
3296
+ };
3297
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
3221
3298
  return {
3222
3299
  maxOutputTokens: 128e3,
3223
3300
  supportsStructuredOutput: true,
3301
+ rejectsSamplingParameters: false,
3224
3302
  isKnownModel: true
3225
3303
  };
3226
3304
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
3227
3305
  return {
3228
3306
  maxOutputTokens: 64e3,
3229
3307
  supportsStructuredOutput: true,
3308
+ rejectsSamplingParameters: false,
3230
3309
  isKnownModel: true
3231
3310
  };
3232
3311
  } else if (modelId.includes("claude-opus-4-1")) {
3233
3312
  return {
3234
3313
  maxOutputTokens: 32e3,
3235
3314
  supportsStructuredOutput: true,
3315
+ rejectsSamplingParameters: false,
3236
3316
  isKnownModel: true
3237
3317
  };
3238
3318
  } else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet")) {
3239
3319
  return {
3240
3320
  maxOutputTokens: 64e3,
3241
3321
  supportsStructuredOutput: false,
3322
+ rejectsSamplingParameters: false,
3242
3323
  isKnownModel: true
3243
3324
  };
3244
3325
  } else if (modelId.includes("claude-opus-4-")) {
3245
3326
  return {
3246
3327
  maxOutputTokens: 32e3,
3247
3328
  supportsStructuredOutput: false,
3329
+ rejectsSamplingParameters: false,
3248
3330
  isKnownModel: true
3249
3331
  };
3250
3332
  } else if (modelId.includes("claude-3-5-haiku")) {
3251
3333
  return {
3252
3334
  maxOutputTokens: 8192,
3253
3335
  supportsStructuredOutput: false,
3336
+ rejectsSamplingParameters: false,
3254
3337
  isKnownModel: true
3255
3338
  };
3256
3339
  } else if (modelId.includes("claude-3-haiku")) {
3257
3340
  return {
3258
3341
  maxOutputTokens: 4096,
3259
3342
  supportsStructuredOutput: false,
3343
+ rejectsSamplingParameters: false,
3260
3344
  isKnownModel: true
3261
3345
  };
3262
3346
  } else {
3263
3347
  return {
3264
3348
  maxOutputTokens: 4096,
3265
3349
  supportsStructuredOutput: false,
3350
+ rejectsSamplingParameters: false,
3266
3351
  isKnownModel: false
3267
3352
  };
3268
3353
  }