@ai-sdk/anthropic 4.0.0-beta.1 → 4.0.0-beta.10

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,69 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.0-beta.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
8
+ - Updated dependencies [3887c70]
9
+ - @ai-sdk/provider-utils@5.0.0-beta.6
10
+ - @ai-sdk/provider@4.0.0-beta.4
11
+
12
+ ## 4.0.0-beta.9
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [776b617]
17
+ - @ai-sdk/provider-utils@5.0.0-beta.5
18
+ - @ai-sdk/provider@4.0.0-beta.3
19
+
20
+ ## 4.0.0-beta.8
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [61753c3]
25
+ - @ai-sdk/provider-utils@5.0.0-beta.4
26
+
27
+ ## 4.0.0-beta.7
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [f7d4f01]
32
+ - @ai-sdk/provider-utils@5.0.0-beta.3
33
+ - @ai-sdk/provider@4.0.0-beta.2
34
+
35
+ ## 4.0.0-beta.6
36
+
37
+ ### Patch Changes
38
+
39
+ - 21d1ee3: fix(anthropic): skip passing beta header for tool search tools
40
+
41
+ ## 4.0.0-beta.5
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [5c2a5a2]
46
+ - @ai-sdk/provider@4.0.0-beta.1
47
+ - @ai-sdk/provider-utils@5.0.0-beta.2
48
+
49
+ ## 4.0.0-beta.4
50
+
51
+ ### Patch Changes
52
+
53
+ - f05a40d: fix(vertex): throw warning when strict: true for vertexAnthropic
54
+
55
+ ## 4.0.0-beta.3
56
+
57
+ ### Patch Changes
58
+
59
+ - e748b35: chore: update v3 specs to v4
60
+
61
+ ## 4.0.0-beta.2
62
+
63
+ ### Patch Changes
64
+
65
+ - 1fe058b: fix(anthropic): preserve the error code returned by model
66
+
3
67
  ## 4.0.0-beta.1
4
68
 
5
69
  ### Patch Changes
@@ -434,13 +498,13 @@
434
498
  Before
435
499
 
436
500
  ```ts
437
- model.textEmbeddingModel('my-model-id');
501
+ model.textEmbeddingModel("my-model-id");
438
502
  ```
439
503
 
440
504
  After
441
505
 
442
506
  ```ts
443
- model.embeddingModel('my-model-id');
507
+ model.embeddingModel("my-model-id");
444
508
  ```
445
509
 
446
510
  - f33a018: chore: add model ID for Haiku 4.5
@@ -780,13 +844,13 @@
780
844
  Before
781
845
 
782
846
  ```ts
783
- model.textEmbeddingModel('my-model-id');
847
+ model.textEmbeddingModel("my-model-id");
784
848
  ```
785
849
 
786
850
  After
787
851
 
788
852
  ```ts
789
- model.embeddingModel('my-model-id');
853
+ model.embeddingModel("my-model-id");
790
854
  ```
791
855
 
792
856
  - Updated dependencies [8d9e8ad]
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONObject, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
1
+ import { JSONObject, ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
2
2
  import { z } from 'zod/v4';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
@@ -1007,17 +1007,17 @@ declare const anthropicTools: {
1007
1007
  }[]>;
1008
1008
  };
1009
1009
 
1010
- interface AnthropicProvider extends ProviderV3 {
1010
+ interface AnthropicProvider extends ProviderV4 {
1011
1011
  /**
1012
1012
  * Creates a model for text generation.
1013
1013
  */
1014
- (modelId: AnthropicMessagesModelId): LanguageModelV3;
1014
+ (modelId: AnthropicMessagesModelId): LanguageModelV4;
1015
1015
  /**
1016
1016
  * Creates a model for text generation.
1017
1017
  */
1018
- languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
1019
- chat(modelId: AnthropicMessagesModelId): LanguageModelV3;
1020
- messages(modelId: AnthropicMessagesModelId): LanguageModelV3;
1018
+ languageModel(modelId: AnthropicMessagesModelId): LanguageModelV4;
1019
+ chat(modelId: AnthropicMessagesModelId): LanguageModelV4;
1020
+ messages(modelId: AnthropicMessagesModelId): LanguageModelV4;
1021
1021
  /**
1022
1022
  * @deprecated Use `embeddingModel` instead.
1023
1023
  */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONObject, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
1
+ import { JSONObject, ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
2
2
  import { z } from 'zod/v4';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
@@ -1007,17 +1007,17 @@ declare const anthropicTools: {
1007
1007
  }[]>;
1008
1008
  };
1009
1009
 
1010
- interface AnthropicProvider extends ProviderV3 {
1010
+ interface AnthropicProvider extends ProviderV4 {
1011
1011
  /**
1012
1012
  * Creates a model for text generation.
1013
1013
  */
1014
- (modelId: AnthropicMessagesModelId): LanguageModelV3;
1014
+ (modelId: AnthropicMessagesModelId): LanguageModelV4;
1015
1015
  /**
1016
1016
  * Creates a model for text generation.
1017
1017
  */
1018
- languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
1019
- chat(modelId: AnthropicMessagesModelId): LanguageModelV3;
1020
- messages(modelId: AnthropicMessagesModelId): LanguageModelV3;
1018
+ languageModel(modelId: AnthropicMessagesModelId): LanguageModelV4;
1019
+ chat(modelId: AnthropicMessagesModelId): LanguageModelV4;
1020
+ messages(modelId: AnthropicMessagesModelId): LanguageModelV4;
1021
1021
  /**
1022
1022
  * @deprecated Use `embeddingModel` instead.
1023
1023
  */
package/dist/index.js CHANGED
@@ -18,21 +18,21 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  VERSION: () => VERSION,
24
24
  anthropic: () => anthropic,
25
25
  createAnthropic: () => createAnthropic,
26
26
  forwardAnthropicContainerIdFromLastStep: () => forwardAnthropicContainerIdFromLastStep
27
27
  });
28
- module.exports = __toCommonJS(src_exports);
28
+ module.exports = __toCommonJS(index_exports);
29
29
 
30
30
  // src/anthropic-provider.ts
31
31
  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 ? "4.0.0-beta.1" : "0.0.0-test";
35
+ var VERSION = true ? "4.0.0-beta.10" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -1269,7 +1269,8 @@ async function prepareTools({
1269
1269
  toolChoice,
1270
1270
  disableParallelToolUse,
1271
1271
  cacheControlValidator,
1272
- supportsStructuredOutput
1272
+ supportsStructuredOutput,
1273
+ supportsStrictTools
1273
1274
  }) {
1274
1275
  var _a;
1275
1276
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -1291,13 +1292,20 @@ async function prepareTools({
1291
1292
  const eagerInputStreaming = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming;
1292
1293
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1293
1294
  const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1295
+ if (!supportsStrictTools && tool.strict != null) {
1296
+ toolWarnings.push({
1297
+ type: "unsupported",
1298
+ feature: "strict",
1299
+ details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`
1300
+ });
1301
+ }
1294
1302
  anthropicTools2.push({
1295
1303
  name: tool.name,
1296
1304
  description: tool.description,
1297
1305
  input_schema: tool.inputSchema,
1298
1306
  cache_control: cacheControl,
1299
1307
  ...eagerInputStreaming ? { eager_input_streaming: true } : {},
1300
- ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
1308
+ ...supportsStrictTools === true && tool.strict != null ? { strict: tool.strict } : {},
1301
1309
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
1302
1310
  ...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
1303
1311
  ...tool.inputExamples != null ? {
@@ -1513,7 +1521,6 @@ async function prepareTools({
1513
1521
  break;
1514
1522
  }
1515
1523
  case "anthropic.tool_search_regex_20251119": {
1516
- betas.add("advanced-tool-use-2025-11-20");
1517
1524
  anthropicTools2.push({
1518
1525
  type: "tool_search_tool_regex_20251119",
1519
1526
  name: "tool_search_tool_regex"
@@ -1521,7 +1528,6 @@ async function prepareTools({
1521
1528
  break;
1522
1529
  }
1523
1530
  case "anthropic.tool_search_bm25_20251119": {
1524
- betas.add("advanced-tool-use-2025-11-20");
1525
1531
  anthropicTools2.push({
1526
1532
  type: "tool_search_tool_bm25_20251119",
1527
1533
  name: "tool_search_tool_bm25"
@@ -2587,7 +2593,7 @@ async function convertToAnthropicMessagesPrompt({
2587
2593
  } catch (e) {
2588
2594
  const extractedErrorCode = (_r = output.value) == null ? void 0 : _r.errorCode;
2589
2595
  errorValue = {
2590
- errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unknown"
2596
+ errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
2591
2597
  };
2592
2598
  }
2593
2599
  anthropicContent.push({
@@ -2595,7 +2601,7 @@ async function convertToAnthropicMessagesPrompt({
2595
2601
  tool_use_id: part.toolCallId,
2596
2602
  content: {
2597
2603
  type: "web_fetch_tool_result_error",
2598
- error_code: (_s = errorValue.errorCode) != null ? _s : "unknown"
2604
+ error_code: (_s = errorValue.errorCode) != null ? _s : "unavailable"
2599
2605
  },
2600
2606
  cache_control: cacheControl
2601
2607
  });
@@ -2830,7 +2836,7 @@ function createCitationSource(citation, citationDocuments, generateId3) {
2830
2836
  }
2831
2837
  var AnthropicMessagesLanguageModel = class {
2832
2838
  constructor(modelId, config) {
2833
- this.specificationVersion = "v3";
2839
+ this.specificationVersion = "v4";
2834
2840
  var _a;
2835
2841
  this.modelId = modelId;
2836
2842
  this.config = config;
@@ -2869,10 +2875,11 @@ var AnthropicMessagesLanguageModel = class {
2869
2875
  seed,
2870
2876
  tools,
2871
2877
  toolChoice,
2878
+ reasoning,
2872
2879
  providerOptions,
2873
2880
  stream
2874
2881
  }) {
2875
- var _a, _b, _c, _d, _e, _f, _g;
2882
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2876
2883
  const warnings = [];
2877
2884
  if (frequencyPenalty != null) {
2878
2885
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2927,10 +2934,12 @@ var AnthropicMessagesLanguageModel = class {
2927
2934
  const {
2928
2935
  maxOutputTokens: maxOutputTokensForModel,
2929
2936
  supportsStructuredOutput: modelSupportsStructuredOutput,
2937
+ supportsAdaptiveThinking,
2930
2938
  isKnownModel
2931
2939
  } = getModelCapabilities(this.modelId);
2932
2940
  const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
2933
- const structureOutputMode = (_b = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _b : "auto";
2941
+ const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
2942
+ const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
2934
2943
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2935
2944
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
2936
2945
  type: "function",
@@ -2965,14 +2974,28 @@ var AnthropicMessagesLanguageModel = class {
2965
2974
  });
2966
2975
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
2967
2976
  prompt,
2968
- sendReasoning: (_c = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _c : true,
2977
+ sendReasoning: (_d = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _d : true,
2969
2978
  warnings,
2970
2979
  cacheControlValidator,
2971
2980
  toolNameMapping
2972
2981
  });
2973
- const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2982
+ if ((0, import_provider_utils15.isCustomReasoning)(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null && (anthropicOptions == null ? void 0 : anthropicOptions.effort) == null) {
2983
+ const reasoningConfig = resolveAnthropicReasoningConfig({
2984
+ reasoning,
2985
+ supportsAdaptiveThinking,
2986
+ maxOutputTokensForModel,
2987
+ warnings
2988
+ });
2989
+ if (reasoningConfig != null) {
2990
+ anthropicOptions.thinking = reasoningConfig.thinking;
2991
+ if (reasoningConfig.effort != null) {
2992
+ anthropicOptions.effort = reasoningConfig.effort;
2993
+ }
2994
+ }
2995
+ }
2996
+ const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
2974
2997
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2975
- let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2998
+ let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
2976
2999
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2977
3000
  const baseArgs = {
2978
3001
  // model id:
@@ -3179,7 +3202,7 @@ var AnthropicMessagesLanguageModel = class {
3179
3202
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3180
3203
  betas.add("fast-mode-2026-02-01");
3181
3204
  }
3182
- if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
3205
+ if (stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true)) {
3183
3206
  betas.add("fine-grained-tool-streaming-2025-05-14");
3184
3207
  }
3185
3208
  const {
@@ -3193,13 +3216,15 @@ var AnthropicMessagesLanguageModel = class {
3193
3216
  toolChoice: { type: "required" },
3194
3217
  disableParallelToolUse: true,
3195
3218
  cacheControlValidator,
3196
- supportsStructuredOutput: false
3219
+ supportsStructuredOutput: false,
3220
+ supportsStrictTools
3197
3221
  } : {
3198
3222
  tools: tools != null ? tools : [],
3199
3223
  toolChoice,
3200
3224
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
3201
3225
  cacheControlValidator,
3202
- supportsStructuredOutput
3226
+ supportsStructuredOutput,
3227
+ supportsStrictTools
3203
3228
  }
3204
3229
  );
3205
3230
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -3216,7 +3241,7 @@ var AnthropicMessagesLanguageModel = class {
3216
3241
  ...betas,
3217
3242
  ...toolsBetas,
3218
3243
  ...userSuppliedBetas,
3219
- ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
3244
+ ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
3220
3245
  ]),
3221
3246
  usesJsonResponseTool: jsonResponseTool != null,
3222
3247
  toolNameMapping,
@@ -4479,42 +4504,49 @@ function getModelCapabilities(modelId) {
4479
4504
  return {
4480
4505
  maxOutputTokens: 128e3,
4481
4506
  supportsStructuredOutput: true,
4507
+ supportsAdaptiveThinking: true,
4482
4508
  isKnownModel: true
4483
4509
  };
4484
4510
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
4485
4511
  return {
4486
4512
  maxOutputTokens: 64e3,
4487
4513
  supportsStructuredOutput: true,
4514
+ supportsAdaptiveThinking: false,
4488
4515
  isKnownModel: true
4489
4516
  };
4490
4517
  } else if (modelId.includes("claude-opus-4-1")) {
4491
4518
  return {
4492
4519
  maxOutputTokens: 32e3,
4493
4520
  supportsStructuredOutput: true,
4521
+ supportsAdaptiveThinking: false,
4494
4522
  isKnownModel: true
4495
4523
  };
4496
4524
  } else if (modelId.includes("claude-sonnet-4-")) {
4497
4525
  return {
4498
4526
  maxOutputTokens: 64e3,
4499
4527
  supportsStructuredOutput: false,
4528
+ supportsAdaptiveThinking: false,
4500
4529
  isKnownModel: true
4501
4530
  };
4502
4531
  } else if (modelId.includes("claude-opus-4-")) {
4503
4532
  return {
4504
4533
  maxOutputTokens: 32e3,
4505
4534
  supportsStructuredOutput: false,
4535
+ supportsAdaptiveThinking: false,
4506
4536
  isKnownModel: true
4507
4537
  };
4508
4538
  } else if (modelId.includes("claude-3-haiku")) {
4509
4539
  return {
4510
4540
  maxOutputTokens: 4096,
4511
4541
  supportsStructuredOutput: false,
4542
+ supportsAdaptiveThinking: false,
4512
4543
  isKnownModel: true
4513
4544
  };
4514
4545
  } else {
4515
4546
  return {
4516
4547
  maxOutputTokens: 4096,
4517
4548
  supportsStructuredOutput: false,
4549
+ supportsAdaptiveThinking: false,
4518
4550
  isKnownModel: false
4519
4551
  };
4520
4552
  }
@@ -4537,6 +4569,43 @@ function hasWebTool20260209WithoutCodeExecution(tools) {
4537
4569
  }
4538
4570
  return hasWebTool20260209 && !hasCodeExecutionTool;
4539
4571
  }
4572
+ function resolveAnthropicReasoningConfig({
4573
+ reasoning,
4574
+ supportsAdaptiveThinking,
4575
+ maxOutputTokensForModel,
4576
+ warnings
4577
+ }) {
4578
+ if (!(0, import_provider_utils15.isCustomReasoning)(reasoning)) {
4579
+ return void 0;
4580
+ }
4581
+ if (reasoning === "none") {
4582
+ return { thinking: { type: "disabled" } };
4583
+ }
4584
+ if (supportsAdaptiveThinking) {
4585
+ const effort = (0, import_provider_utils15.mapReasoningToProviderEffort)({
4586
+ reasoning,
4587
+ effortMap: {
4588
+ minimal: "low",
4589
+ low: "low",
4590
+ medium: "medium",
4591
+ high: "high",
4592
+ xhigh: "max"
4593
+ },
4594
+ warnings
4595
+ });
4596
+ return { thinking: { type: "adaptive" }, effort };
4597
+ }
4598
+ const budgetTokens = (0, import_provider_utils15.mapReasoningToProviderBudget)({
4599
+ reasoning,
4600
+ maxOutputTokens: maxOutputTokensForModel,
4601
+ maxReasoningBudget: maxOutputTokensForModel,
4602
+ warnings
4603
+ });
4604
+ if (budgetTokens == null) {
4605
+ return void 0;
4606
+ }
4607
+ return { thinking: { type: "enabled", budgetTokens } };
4608
+ }
4540
4609
  function mapAnthropicResponseContextManagement(contextManagement) {
4541
4610
  return contextManagement ? {
4542
4611
  appliedEdits: contextManagement.applied_edits.map((edit) => {
@@ -5112,7 +5181,7 @@ function createAnthropic(options = {}) {
5112
5181
  }
5113
5182
  return createChatModel(modelId);
5114
5183
  };
5115
- provider.specificationVersion = "v3";
5184
+ provider.specificationVersion = "v4";
5116
5185
  provider.languageModel = createChatModel;
5117
5186
  provider.chat = createChatModel;
5118
5187
  provider.messages = createChatModel;