@ai-sdk/anthropic 3.0.69 → 3.0.71

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.71
4
+
5
+ ### Patch Changes
6
+
7
+ - 95b4fe0: fix(provider/anthropic): stop adding `fine-grained-tool-streaming-2025-05-14` beta for `claude-opus-4-7`
8
+
9
+ ## 3.0.70
10
+
11
+ ### Patch Changes
12
+
13
+ - 2ff8d57: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
14
+
3
15
  ## 3.0.69
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,8 +179,14 @@ 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";
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,8 +179,14 @@ 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";
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.69" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.71" : "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 */
@@ -914,10 +920,11 @@ var anthropicLanguageModelOptions = import_v43.z.object({
914
920
  ).optional()
915
921
  }).optional(),
916
922
  /**
917
- * Whether to enable tool streaming (and structured output streaming).
918
- *
919
- * When set to false, the model will return all tool calls and results
920
- * at once after a delay.
923
+ * Whether to enable fine-grained (eager) streaming of tool call inputs
924
+ * and structured outputs for every function tool in the request. When
925
+ * true (the default), each function tool receives a default of
926
+ * `eager_input_streaming: true` unless it explicitly sets
927
+ * `providerOptions.anthropic.eagerInputStreaming`.
921
928
  *
922
929
  * @default true
923
930
  */
@@ -925,7 +932,19 @@ var anthropicLanguageModelOptions = import_v43.z.object({
925
932
  /**
926
933
  * @default 'high'
927
934
  */
928
- effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
935
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
936
+ /**
937
+ * Task budget for agentic turns. Informs the model of the total token budget
938
+ * available for the current task, allowing it to prioritize work and wind down
939
+ * gracefully as the budget is consumed.
940
+ *
941
+ * Advisory only — does not enforce a hard token limit.
942
+ */
943
+ taskBudget: import_v43.z.object({
944
+ type: import_v43.z.literal("tokens"),
945
+ total: import_v43.z.number().int().min(2e4),
946
+ remaining: import_v43.z.number().int().min(0).optional()
947
+ }).optional(),
929
948
  /**
930
949
  * Enable fast mode for faster inference (2.5x faster output token speeds).
931
950
  * Only supported with claude-opus-4-6.
@@ -1293,9 +1312,10 @@ async function prepareTools({
1293
1312
  disableParallelToolUse,
1294
1313
  cacheControlValidator,
1295
1314
  supportsStructuredOutput,
1296
- supportsStrictTools
1315
+ supportsStrictTools,
1316
+ defaultEagerInputStreaming = false
1297
1317
  }) {
1298
- var _a;
1318
+ var _a, _b;
1299
1319
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1300
1320
  const toolWarnings = [];
1301
1321
  const betas = /* @__PURE__ */ new Set();
@@ -1312,7 +1332,7 @@ async function prepareTools({
1312
1332
  canCache: true
1313
1333
  });
1314
1334
  const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1315
- const eagerInputStreaming = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming;
1335
+ const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
1316
1336
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1317
1337
  const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1318
1338
  if (!supportsStrictTools && tool.strict != null) {
@@ -2901,7 +2921,7 @@ var AnthropicMessagesLanguageModel = class {
2901
2921
  providerOptions,
2902
2922
  stream
2903
2923
  }) {
2904
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2924
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2905
2925
  const warnings = [];
2906
2926
  if (frequencyPenalty != null) {
2907
2927
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2956,8 +2976,35 @@ var AnthropicMessagesLanguageModel = class {
2956
2976
  const {
2957
2977
  maxOutputTokens: maxOutputTokensForModel,
2958
2978
  supportsStructuredOutput: modelSupportsStructuredOutput,
2979
+ rejectsSamplingParameters,
2959
2980
  isKnownModel
2960
2981
  } = getModelCapabilities(this.modelId);
2982
+ if (rejectsSamplingParameters) {
2983
+ if (temperature != null) {
2984
+ warnings.push({
2985
+ type: "unsupported",
2986
+ feature: "temperature",
2987
+ details: `temperature is not supported by ${this.modelId} and will be ignored`
2988
+ });
2989
+ temperature = void 0;
2990
+ }
2991
+ if (topK != null) {
2992
+ warnings.push({
2993
+ type: "unsupported",
2994
+ feature: "topK",
2995
+ details: `topK is not supported by ${this.modelId} and will be ignored`
2996
+ });
2997
+ topK = void 0;
2998
+ }
2999
+ if (topP != null) {
3000
+ warnings.push({
3001
+ type: "unsupported",
3002
+ feature: "topP",
3003
+ details: `topP is not supported by ${this.modelId} and will be ignored`
3004
+ });
3005
+ topP = void 0;
3006
+ }
3007
+ }
2961
3008
  const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
2962
3009
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2963
3010
  const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
@@ -3004,6 +3051,7 @@ var AnthropicMessagesLanguageModel = class {
3004
3051
  const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3005
3052
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3006
3053
  let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3054
+ const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
3007
3055
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3008
3056
  const baseArgs = {
3009
3057
  // model id:
@@ -3018,14 +3066,24 @@ var AnthropicMessagesLanguageModel = class {
3018
3066
  ...isThinking && {
3019
3067
  thinking: {
3020
3068
  type: thinkingType,
3021
- ...thinkingBudget != null && { budget_tokens: thinkingBudget }
3069
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3070
+ ...thinkingDisplay != null && { display: thinkingDisplay }
3022
3071
  }
3023
3072
  },
3024
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3073
+ ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
3025
3074
  output_config: {
3026
3075
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
3027
3076
  effort: anthropicOptions.effort
3028
3077
  },
3078
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
3079
+ task_budget: {
3080
+ type: anthropicOptions.taskBudget.type,
3081
+ total: anthropicOptions.taskBudget.total,
3082
+ ...anthropicOptions.taskBudget.remaining != null && {
3083
+ remaining: anthropicOptions.taskBudget.remaining
3084
+ }
3085
+ }
3086
+ },
3029
3087
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
3030
3088
  format: {
3031
3089
  type: "json_schema",
@@ -3043,7 +3101,7 @@ var AnthropicMessagesLanguageModel = class {
3043
3101
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3044
3102
  cache_control: anthropicOptions.cacheControl
3045
3103
  },
3046
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
3104
+ ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3047
3105
  metadata: { user_id: anthropicOptions.metadata.userId }
3048
3106
  },
3049
3107
  // mcp servers:
@@ -3213,12 +3271,13 @@ var AnthropicMessagesLanguageModel = class {
3213
3271
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
3214
3272
  betas.add("effort-2025-11-24");
3215
3273
  }
3274
+ if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3275
+ betas.add("task-budgets-2026-03-13");
3276
+ }
3216
3277
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3217
3278
  betas.add("fast-mode-2026-02-01");
3218
3279
  }
3219
- if (stream && ((_h = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _h : true)) {
3220
- betas.add("fine-grained-tool-streaming-2025-05-14");
3221
- }
3280
+ const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
3222
3281
  const {
3223
3282
  tools: anthropicTools2,
3224
3283
  toolChoice: anthropicToolChoice,
@@ -3231,14 +3290,16 @@ var AnthropicMessagesLanguageModel = class {
3231
3290
  disableParallelToolUse: true,
3232
3291
  cacheControlValidator,
3233
3292
  supportsStructuredOutput: false,
3234
- supportsStrictTools
3293
+ supportsStrictTools,
3294
+ defaultEagerInputStreaming
3235
3295
  } : {
3236
3296
  tools: tools != null ? tools : [],
3237
3297
  toolChoice,
3238
3298
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
3239
3299
  cacheControlValidator,
3240
3300
  supportsStructuredOutput,
3241
- supportsStrictTools
3301
+ supportsStrictTools,
3302
+ defaultEagerInputStreaming
3242
3303
  }
3243
3304
  );
3244
3305
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -3255,7 +3316,7 @@ var AnthropicMessagesLanguageModel = class {
3255
3316
  ...betas,
3256
3317
  ...toolsBetas,
3257
3318
  ...userSuppliedBetas,
3258
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
3319
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3259
3320
  ]),
3260
3321
  usesJsonResponseTool: jsonResponseTool != null,
3261
3322
  toolNameMapping,
@@ -4514,46 +4575,60 @@ var AnthropicMessagesLanguageModel = class {
4514
4575
  }
4515
4576
  };
4516
4577
  function getModelCapabilities(modelId) {
4517
- if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4578
+ if (modelId.includes("claude-opus-4-7")) {
4579
+ return {
4580
+ maxOutputTokens: 128e3,
4581
+ supportsStructuredOutput: true,
4582
+ rejectsSamplingParameters: true,
4583
+ isKnownModel: true
4584
+ };
4585
+ } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
4518
4586
  return {
4519
4587
  maxOutputTokens: 128e3,
4520
4588
  supportsStructuredOutput: true,
4589
+ rejectsSamplingParameters: false,
4521
4590
  isKnownModel: true
4522
4591
  };
4523
4592
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
4524
4593
  return {
4525
4594
  maxOutputTokens: 64e3,
4526
4595
  supportsStructuredOutput: true,
4596
+ rejectsSamplingParameters: false,
4527
4597
  isKnownModel: true
4528
4598
  };
4529
4599
  } else if (modelId.includes("claude-opus-4-1")) {
4530
4600
  return {
4531
4601
  maxOutputTokens: 32e3,
4532
4602
  supportsStructuredOutput: true,
4603
+ rejectsSamplingParameters: false,
4533
4604
  isKnownModel: true
4534
4605
  };
4535
4606
  } else if (modelId.includes("claude-sonnet-4-")) {
4536
4607
  return {
4537
4608
  maxOutputTokens: 64e3,
4538
4609
  supportsStructuredOutput: false,
4610
+ rejectsSamplingParameters: false,
4539
4611
  isKnownModel: true
4540
4612
  };
4541
4613
  } else if (modelId.includes("claude-opus-4-")) {
4542
4614
  return {
4543
4615
  maxOutputTokens: 32e3,
4544
4616
  supportsStructuredOutput: false,
4617
+ rejectsSamplingParameters: false,
4545
4618
  isKnownModel: true
4546
4619
  };
4547
4620
  } else if (modelId.includes("claude-3-haiku")) {
4548
4621
  return {
4549
4622
  maxOutputTokens: 4096,
4550
4623
  supportsStructuredOutput: false,
4624
+ rejectsSamplingParameters: false,
4551
4625
  isKnownModel: true
4552
4626
  };
4553
4627
  } else {
4554
4628
  return {
4555
4629
  maxOutputTokens: 4096,
4556
4630
  supportsStructuredOutput: false,
4631
+ rejectsSamplingParameters: false,
4557
4632
  isKnownModel: false
4558
4633
  };
4559
4634
  }