@ai-sdk/anthropic 4.0.0-beta.29 → 4.0.0-beta.31

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,18 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.0-beta.31
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [083947b]
8
+ - @ai-sdk/provider-utils@5.0.0-beta.22
9
+
10
+ ## 4.0.0-beta.30
11
+
12
+ ### Patch Changes
13
+
14
+ - 0d8f107: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
15
+
3
16
  ## 4.0.0-beta.29
4
17
 
5
18
  ### Patch Changes
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>;
@@ -179,8 +183,14 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
179
183
  low: "low";
180
184
  medium: "medium";
181
185
  high: "high";
186
+ xhigh: "xhigh";
182
187
  max: "max";
183
188
  }>>;
189
+ taskBudget: z.ZodOptional<z.ZodObject<{
190
+ type: z.ZodLiteral<"tokens">;
191
+ total: z.ZodNumber;
192
+ remaining: z.ZodOptional<z.ZodNumber>;
193
+ }, z.core.$strip>>;
184
194
  speed: z.ZodOptional<z.ZodEnum<{
185
195
  fast: "fast";
186
196
  standard: "standard";
package/dist/index.js CHANGED
@@ -921,7 +921,13 @@ var anthropicLanguageModelOptions = z4.object({
921
921
  thinking: z4.discriminatedUnion("type", [
922
922
  z4.object({
923
923
  /** for Sonnet 4.6, Opus 4.6, and newer models */
924
- type: z4.literal("adaptive")
924
+ type: z4.literal("adaptive"),
925
+ /**
926
+ * Controls whether thinking content is included in the response.
927
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
928
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
929
+ */
930
+ display: z4.enum(["omitted", "summarized"]).optional()
925
931
  }),
926
932
  z4.object({
927
933
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
@@ -1008,7 +1014,19 @@ var anthropicLanguageModelOptions = z4.object({
1008
1014
  /**
1009
1015
  * @default 'high'
1010
1016
  */
1011
- effort: z4.enum(["low", "medium", "high", "max"]).optional(),
1017
+ effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
1018
+ /**
1019
+ * Task budget for agentic turns. Informs the model of the total token budget
1020
+ * available for the current task, allowing it to prioritize work and wind down
1021
+ * gracefully as the budget is consumed.
1022
+ *
1023
+ * Advisory only — does not enforce a hard token limit.
1024
+ */
1025
+ taskBudget: z4.object({
1026
+ type: z4.literal("tokens"),
1027
+ total: z4.number().int().min(2e4),
1028
+ remaining: z4.number().int().min(0).optional()
1029
+ }).optional(),
1012
1030
  /**
1013
1031
  * Enable fast mode for faster inference (2.5x faster output token speeds).
1014
1032
  * Only supported with claude-opus-4-6.
@@ -3057,7 +3075,7 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3057
3075
  providerOptions,
3058
3076
  stream
3059
3077
  }) {
3060
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3078
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3061
3079
  const warnings = [];
3062
3080
  if (frequencyPenalty != null) {
3063
3081
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3113,8 +3131,36 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3113
3131
  maxOutputTokens: maxOutputTokensForModel,
3114
3132
  supportsStructuredOutput: modelSupportsStructuredOutput,
3115
3133
  supportsAdaptiveThinking,
3134
+ rejectsSamplingParameters,
3135
+ supportsXhighEffort,
3116
3136
  isKnownModel
3117
3137
  } = getModelCapabilities(this.modelId);
3138
+ if (rejectsSamplingParameters) {
3139
+ if (temperature != null) {
3140
+ warnings.push({
3141
+ type: "unsupported",
3142
+ feature: "temperature",
3143
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
3144
+ });
3145
+ temperature = void 0;
3146
+ }
3147
+ if (topK != null) {
3148
+ warnings.push({
3149
+ type: "unsupported",
3150
+ feature: "topK",
3151
+ details: `topK is not supported by ${this.modelId} and will be ignored`
3152
+ });
3153
+ topK = void 0;
3154
+ }
3155
+ if (topP != null) {
3156
+ warnings.push({
3157
+ type: "unsupported",
3158
+ feature: "topP",
3159
+ details: `topP is not supported by ${this.modelId} and will be ignored`
3160
+ });
3161
+ topP = void 0;
3162
+ }
3163
+ }
3118
3164
  const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
3119
3165
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
3120
3166
  const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
@@ -3158,23 +3204,27 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3158
3204
  cacheControlValidator,
3159
3205
  toolNameMapping
3160
3206
  });
3161
- if (isCustomReasoning(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null && (anthropicOptions == null ? void 0 : anthropicOptions.effort) == null) {
3207
+ if (isCustomReasoning(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.effort) == null) {
3162
3208
  const reasoningConfig = resolveAnthropicReasoningConfig({
3163
3209
  reasoning,
3164
3210
  supportsAdaptiveThinking,
3211
+ supportsXhighEffort,
3165
3212
  maxOutputTokensForModel,
3166
3213
  warnings
3167
3214
  });
3168
3215
  if (reasoningConfig != null) {
3169
- anthropicOptions.thinking = reasoningConfig.thinking;
3170
- if (reasoningConfig.effort != null) {
3216
+ if (anthropicOptions.thinking == null) {
3217
+ anthropicOptions.thinking = reasoningConfig.thinking;
3218
+ }
3219
+ if (reasoningConfig.effort != null && ((_e = anthropicOptions.thinking) == null ? void 0 : _e.type) !== "disabled") {
3171
3220
  anthropicOptions.effort = reasoningConfig.effort;
3172
3221
  }
3173
3222
  }
3174
3223
  }
3175
- const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3224
+ const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
3176
3225
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3177
- let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3226
+ let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
3227
+ const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
3178
3228
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3179
3229
  const baseArgs = {
3180
3230
  // model id:
@@ -3189,14 +3239,24 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3189
3239
  ...isThinking && {
3190
3240
  thinking: {
3191
3241
  type: thinkingType,
3192
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
3242
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3243
+ ...thinkingDisplay != null && { display: thinkingDisplay }
3193
3244
  }
3194
3245
  },
3195
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3246
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3196
3247
  output_config: {
3197
3248
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
3198
3249
  effort: anthropicOptions.effort
3199
3250
  },
3251
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
3252
+ task_budget: {
3253
+ type: anthropicOptions.taskBudget.type,
3254
+ total: anthropicOptions.taskBudget.total,
3255
+ ...anthropicOptions.taskBudget.remaining != null && {
3256
+ remaining: anthropicOptions.taskBudget.remaining
3257
+ }
3258
+ }
3259
+ },
3200
3260
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
3201
3261
  format: {
3202
3262
  type: "json_schema",
@@ -3214,7 +3274,7 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3214
3274
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3215
3275
  cache_control: anthropicOptions.cacheControl
3216
3276
  },
3217
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
3277
+ ...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
3218
3278
  metadata: { user_id: anthropicOptions.metadata.userId }
3219
3279
  },
3220
3280
  // mcp servers:
@@ -3387,10 +3447,13 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3387
3447
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
3388
3448
  betas.add("effort-2025-11-24");
3389
3449
  }
3450
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3451
+ betas.add("task-budgets-2026-03-13");
3452
+ }
3390
3453
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3391
3454
  betas.add("fast-mode-2026-02-01");
3392
3455
  }
3393
- if (stream && ((_h = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _h : true)) {
3456
+ if (stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true)) {
3394
3457
  betas.add("fine-grained-tool-streaming-2025-05-14");
3395
3458
  }
3396
3459
  const {
@@ -3429,7 +3492,7 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
3429
3492
  ...betas,
3430
3493
  ...toolsBetas,
3431
3494
  ...userSuppliedBetas,
3432
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
3495
+ ...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
3433
3496
  ]),
3434
3497
  usesJsonResponseTool: jsonResponseTool != null,
3435
3498
  toolNameMapping,
@@ -4689,11 +4752,22 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
4689
4752
  }
4690
4753
  };
4691
4754
  function getModelCapabilities(modelId) {
4692
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4755
+ if (modelId.includes("claude-opus-4-7")) {
4756
+ return {
4757
+ maxOutputTokens: 128e3,
4758
+ supportsStructuredOutput: true,
4759
+ supportsAdaptiveThinking: true,
4760
+ rejectsSamplingParameters: true,
4761
+ supportsXhighEffort: true,
4762
+ isKnownModel: true
4763
+ };
4764
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4693
4765
  return {
4694
4766
  maxOutputTokens: 128e3,
4695
4767
  supportsStructuredOutput: true,
4696
4768
  supportsAdaptiveThinking: true,
4769
+ rejectsSamplingParameters: false,
4770
+ supportsXhighEffort: false,
4697
4771
  isKnownModel: true
4698
4772
  };
4699
4773
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -4701,6 +4775,8 @@ function getModelCapabilities(modelId) {
4701
4775
  maxOutputTokens: 64e3,
4702
4776
  supportsStructuredOutput: true,
4703
4777
  supportsAdaptiveThinking: false,
4778
+ rejectsSamplingParameters: false,
4779
+ supportsXhighEffort: false,
4704
4780
  isKnownModel: true
4705
4781
  };
4706
4782
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -4708,6 +4784,8 @@ function getModelCapabilities(modelId) {
4708
4784
  maxOutputTokens: 32e3,
4709
4785
  supportsStructuredOutput: true,
4710
4786
  supportsAdaptiveThinking: false,
4787
+ rejectsSamplingParameters: false,
4788
+ supportsXhighEffort: false,
4711
4789
  isKnownModel: true
4712
4790
  };
4713
4791
  } else if (modelId.includes("claude-sonnet-4-")) {
@@ -4715,6 +4793,8 @@ function getModelCapabilities(modelId) {
4715
4793
  maxOutputTokens: 64e3,
4716
4794
  supportsStructuredOutput: false,
4717
4795
  supportsAdaptiveThinking: false,
4796
+ rejectsSamplingParameters: false,
4797
+ supportsXhighEffort: false,
4718
4798
  isKnownModel: true
4719
4799
  };
4720
4800
  } else if (modelId.includes("claude-opus-4-")) {
@@ -4722,6 +4802,8 @@ function getModelCapabilities(modelId) {
4722
4802
  maxOutputTokens: 32e3,
4723
4803
  supportsStructuredOutput: false,
4724
4804
  supportsAdaptiveThinking: false,
4805
+ rejectsSamplingParameters: false,
4806
+ supportsXhighEffort: false,
4725
4807
  isKnownModel: true
4726
4808
  };
4727
4809
  } else if (modelId.includes("claude-3-haiku")) {
@@ -4729,6 +4811,8 @@ function getModelCapabilities(modelId) {
4729
4811
  maxOutputTokens: 4096,
4730
4812
  supportsStructuredOutput: false,
4731
4813
  supportsAdaptiveThinking: false,
4814
+ rejectsSamplingParameters: false,
4815
+ supportsXhighEffort: false,
4732
4816
  isKnownModel: true
4733
4817
  };
4734
4818
  } else {
@@ -4736,6 +4820,8 @@ function getModelCapabilities(modelId) {
4736
4820
  maxOutputTokens: 4096,
4737
4821
  supportsStructuredOutput: false,
4738
4822
  supportsAdaptiveThinking: false,
4823
+ rejectsSamplingParameters: false,
4824
+ supportsXhighEffort: false,
4739
4825
  isKnownModel: false
4740
4826
  };
4741
4827
  }
@@ -4761,6 +4847,7 @@ function hasWebTool20260209WithoutCodeExecution(tools) {
4761
4847
  function resolveAnthropicReasoningConfig({
4762
4848
  reasoning,
4763
4849
  supportsAdaptiveThinking,
4850
+ supportsXhighEffort,
4764
4851
  maxOutputTokensForModel,
4765
4852
  warnings
4766
4853
  }) {
@@ -4778,7 +4865,7 @@ function resolveAnthropicReasoningConfig({
4778
4865
  low: "low",
4779
4866
  medium: "medium",
4780
4867
  high: "high",
4781
- xhigh: "max"
4868
+ xhigh: supportsXhighEffort ? "xhigh" : "max"
4782
4869
  },
4783
4870
  warnings
4784
4871
  });
@@ -5485,7 +5572,7 @@ var AnthropicSkills = class {
5485
5572
  };
5486
5573
 
5487
5574
  // src/version.ts
5488
- var VERSION = true ? "4.0.0-beta.29" : "0.0.0-test";
5575
+ var VERSION = true ? "4.0.0-beta.31" : "0.0.0-test";
5489
5576
 
5490
5577
  // src/anthropic-provider.ts
5491
5578
  function createAnthropic(options = {}) {