@ai-sdk/anthropic 4.0.97 → 4.0.99

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.
@@ -2,6 +2,7 @@ import {
2
2
  APICallError,
3
3
  InvalidArgumentError,
4
4
  InvalidResponseDataError,
5
+ UnsupportedFunctionalityError,
5
6
  type JSONObject,
6
7
  type LanguageModelV4,
7
8
  type LanguageModelV4CallOptions,
@@ -31,6 +32,7 @@ import {
31
32
  parseProviderOptions,
32
33
  postJsonToApi,
33
34
  resolve,
35
+ resolveProviderOptions,
34
36
  resolveProviderReference,
35
37
  secureJsonParse,
36
38
  serializeModelOptions,
@@ -72,12 +74,40 @@ import {
72
74
  } from './convert-anthropic-usage';
73
75
  import {
74
76
  convertToAnthropicPrompt,
77
+ getInlineToolsFromPrompt,
75
78
  type AnthropicMediaPartConverter,
76
79
  } from './convert-to-anthropic-prompt';
77
80
  import { CacheControlValidator } from './get-cache-control';
78
81
  import { mapAnthropicStopReason } from './map-anthropic-stop-reason';
79
82
  import { sanitizeJsonSchema } from './sanitize-json-schema';
80
83
  import { supportsNativeStructuredOutputSchema } from './supports-native-structured-output-schema';
84
+ import { computerToolset_20260801Members } from './tool/computer-toolset_20260801';
85
+
86
+ function validateToolsetMember({
87
+ toolsetName,
88
+ memberName,
89
+ tools,
90
+ }: {
91
+ toolsetName: string;
92
+ memberName: string;
93
+ tools: AnthropicTool[] | undefined;
94
+ }): void {
95
+ const toolset = tools?.find(
96
+ tool => 'type' in tool && tool.type === 'computer_toolset_20260801',
97
+ );
98
+
99
+ if (
100
+ toolsetName !== 'computer' ||
101
+ toolset == null ||
102
+ !computerToolset_20260801Members.some(member => member === memberName) ||
103
+ toolset.configs?.[memberName]?.enabled === false
104
+ ) {
105
+ throw new InvalidResponseDataError({
106
+ data: { toolsetName, memberName },
107
+ message: `Received an unavailable toolset member: ${toolsetName}.${memberName}.`,
108
+ });
109
+ }
110
+ }
81
111
 
82
112
  function createAnthropicStreamError(error: {
83
113
  message: string;
@@ -237,11 +267,16 @@ function toToolsetMemberInput({
237
267
  memberName: string;
238
268
  input: unknown;
239
269
  }): JSONObject {
270
+ if (typeof input !== 'object' || input === null || Array.isArray(input)) {
271
+ throw new InvalidResponseDataError({
272
+ data: input,
273
+ message: 'Invalid toolset member input: expected an object.',
274
+ });
275
+ }
276
+
240
277
  return {
278
+ ...(input as JSONObject),
241
279
  action: memberName,
242
- ...(typeof input === 'object' && input !== null && !Array.isArray(input)
243
- ? (input as JSONObject)
244
- : {}),
245
280
  };
246
281
  }
247
282
 
@@ -272,6 +307,8 @@ export type AnthropicLanguageModelConfig = {
272
307
  generateId?: () => string;
273
308
  supportsNativeStructuredOutput?: boolean;
274
309
  supportsStrictTools?: boolean;
310
+ /** Opt in only for platforms that support Anthropic message threads. */
311
+ supportsMessageThreads?: boolean;
275
312
  /** Maximum temperature for compatible providers. Defaults to 1. */
276
313
  maxTemperature?: number;
277
314
  /** Preserve temperature and topP with thinking for compatible providers. */
@@ -280,6 +317,16 @@ export type AnthropicLanguageModelConfig = {
280
317
  cacheControlProviderOptionsName?: string;
281
318
  };
282
319
 
320
+ /**
321
+ * Legacy names of custom providerOptions keys, read when the current key is
322
+ * absent.
323
+ */
324
+ const LEGACY_PROVIDER_OPTIONS_NAMES: Record<string, readonly string[]> = {
325
+ // The Google Vertex Anthropic provider was renamed from `vertex` to
326
+ // `googleVertex`, which silently changed its custom providerOptions key.
327
+ googleVertex: ['vertex'],
328
+ };
329
+
283
330
  const TEXT_OR_THINKING_BLOCK_TYPES = new Set<string>([
284
331
  'redacted_thinking',
285
332
  'text',
@@ -447,17 +494,32 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
447
494
  schema: anthropicLanguageModelOptions,
448
495
  });
449
496
 
450
- const customProviderOptions =
451
- providerOptionsName !== 'anthropic'
452
- ? await parseProviderOptions({
453
- provider: providerOptionsName,
454
- providerOptions,
455
- schema: anthropicLanguageModelOptions,
456
- })
457
- : null;
497
+ // The custom key and its legacy aliases are alternatives: the first
498
+ // present one is used.
499
+ const {
500
+ options: customProviderOptions,
501
+ namespaces: [customProviderOptionsName],
502
+ } = await resolveProviderOptions({
503
+ providerOptions,
504
+ namespaces:
505
+ providerOptionsName !== 'anthropic'
506
+ ? [
507
+ providerOptionsName,
508
+ ...(Object.hasOwn(
509
+ LEGACY_PROVIDER_OPTIONS_NAMES,
510
+ providerOptionsName,
511
+ )
512
+ ? LEGACY_PROVIDER_OPTIONS_NAMES[providerOptionsName]
513
+ : []),
514
+ ]
515
+ : [],
516
+ resolution: 'first',
517
+ schema: anthropicLanguageModelOptions,
518
+ });
458
519
 
459
520
  // Track if custom key was explicitly used
460
- const usedCustomProviderKey = customProviderOptions != null;
521
+ const usedCustomProviderKey =
522
+ customProviderOptionsName === providerOptionsName;
461
523
 
462
524
  // Merge options
463
525
  const anthropicOptions = Object.assign(
@@ -618,13 +680,44 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
618
680
  });
619
681
  }
620
682
 
683
+ const thread = anthropicOptions?.thread;
684
+ if (thread != null && config.supportsMessageThreads !== true) {
685
+ throw new UnsupportedFunctionalityError({
686
+ functionality: 'Anthropic message threads',
687
+ message: `${config.provider} does not support Anthropic message threads.`,
688
+ });
689
+ }
690
+ if (
691
+ thread != null &&
692
+ (compaction != null ||
693
+ contextManagement?.edits.some(
694
+ edit =>
695
+ edit.type !== 'clear_thinking_20251015' || edit.keep !== 'all',
696
+ ))
697
+ ) {
698
+ throw new InvalidArgumentError({
699
+ argument: 'providerOptions.anthropic.thread',
700
+ message:
701
+ 'Anthropic message threads do not support compaction or context editing, except clear_thinking_20251015 with keep: "all".',
702
+ });
703
+ }
704
+
621
705
  // Create a shared cache control validator to track breakpoints across tools and messages
622
706
  const cacheControlValidator = new CacheControlValidator(
623
707
  config.cacheControlProviderOptionsName,
708
+ thread != null && anthropicOptions?.cacheControl != null ? 1 : 0,
624
709
  );
625
710
 
711
+ const defaultEagerInputStreaming =
712
+ stream && (anthropicOptions?.toolStreaming ?? true);
713
+
714
+ // Tools that tool changes add by value are only known from the prompt.
715
+ const inlineTools = await getInlineToolsFromPrompt(prompt);
716
+
626
717
  const toolNameMapping = createToolNameMapping({
627
- tools,
718
+ // later entries win when provider tool names collide, so the declared
719
+ // tools go last and an inline tool cannot take over their mapping:
720
+ tools: [...inlineTools, ...(tools ?? [])],
628
721
  providerToolNames: {
629
722
  'anthropic.code_execution_20250522': 'code_execution',
630
723
  'anthropic.code_execution_20250825': 'code_execution',
@@ -653,6 +746,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
653
746
  });
654
747
 
655
748
  const toolsetNames = getAnthropicToolsetNames(tools);
749
+ const inlineToolDefinitions: Array<{
750
+ sdkName: string;
751
+ definition: AnthropicTool;
752
+ }> = [];
656
753
 
657
754
  const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
658
755
  prompt,
@@ -662,8 +759,66 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
662
759
  toolNameMapping,
663
760
  toolsetNames,
664
761
  convertMediaPart: config.convertMediaPart,
762
+ convertInlineTool: async tool => {
763
+ const {
764
+ tools: definitions,
765
+ toolWarnings,
766
+ betas,
767
+ } = await prepareTools({
768
+ tools: [tool],
769
+ toolChoice: undefined,
770
+ cacheControlValidator,
771
+ supportsStructuredOutput,
772
+ supportsStrictTools,
773
+ // no stream-dependent defaults (eager input streaming): the
774
+ // definition is replayed on every request and has to stay identical
775
+ // between streaming and non-streaming calls to keep the cache.
776
+ });
777
+
778
+ if (definitions?.[0] != null) {
779
+ inlineToolDefinitions.push({
780
+ sdkName: tool.name,
781
+ definition: definitions[0],
782
+ });
783
+ }
784
+
785
+ return {
786
+ definition: definitions?.[0],
787
+ warnings: toolWarnings,
788
+ betas,
789
+ };
790
+ },
665
791
  });
666
792
 
793
+ if (thread != null) {
794
+ const unpinnedBetas = [...betas].filter(
795
+ beta =>
796
+ !userSuppliedBetas.has(beta) &&
797
+ !anthropicOptions?.anthropicBeta?.includes(beta),
798
+ );
799
+ if (unpinnedBetas.length > 0) {
800
+ warnings.push({
801
+ type: 'compatibility',
802
+ feature: 'providerOptions.anthropic.thread',
803
+ details:
804
+ `Message content enabled beta headers: ${unpinnedBetas.join(', ')}. ` +
805
+ 'Thread requests require the same beta set on every turn. Pin these values with anthropicBeta on every request, or start a new thread when the set changes.',
806
+ });
807
+ }
808
+ if (
809
+ thread.type === 'continue' &&
810
+ (messagesPrompt.system != null || (tools?.length ?? 0) > 0)
811
+ ) {
812
+ warnings.push({
813
+ type: 'compatibility',
814
+ feature: 'providerOptions.anthropic.thread',
815
+ details:
816
+ 'Continuation uses the system prompt and tool definitions stored by the create request; supplied definitions are omitted from the wire request. ' +
817
+ 'Supply identical tools for local tool handling and fixed request settings. To change system instructions or tools, start a new thread.',
818
+ });
819
+ }
820
+ }
821
+
667
822
  /*
668
823
  * Map top-level `reasoning` to Anthropic thinking/effort when provider
669
824
  * options don't already specify them. Provider options always take precedence.
@@ -917,7 +1072,16 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
917
1072
  }),
918
1073
 
919
1074
  // prompt:
920
- system: messagesPrompt.system,
1075
+ system: thread?.type === 'continue' ? undefined : messagesPrompt.system,
1076
+ ...(thread != null && {
1077
+ thread:
1078
+ thread.type === 'create'
1079
+ ? { type: 'create' as const }
1080
+ : {
1081
+ type: 'continue' as const,
1082
+ previous_message_id: thread.previousMessageId,
1083
+ },
1084
+ }),
921
1085
  messages: messagesPrompt.messages,
922
1086
 
923
1087
  ...(anthropicOptions?.safeguards &&
@@ -1150,9 +1314,6 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1150
1314
  betas.add('server-side-fallback-2026-06-01');
1151
1315
  }
1152
1316
 
1153
- const defaultEagerInputStreaming =
1154
- stream && (anthropicOptions?.toolStreaming ?? true);
1155
-
1156
1317
  const {
1157
1318
  tools: anthropicTools,
1158
1319
  toolChoice: anthropicToolChoice,
@@ -1182,6 +1343,9 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1182
1343
  : {
1183
1344
  tools: tools ?? [],
1184
1345
  toolChoice,
1346
+ // tool changes can add tools when `tools` is empty, so the tool
1347
+ // choice and parallel tool use settings still apply:
1348
+ hasInlineTools: inlineTools.length > 0,
1185
1349
  disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
1186
1350
  cacheControlValidator,
1187
1351
  supportsStructuredOutput,
@@ -1192,26 +1356,96 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1192
1356
  },
1193
1357
  );
1194
1358
 
1359
+ // Forced-choice and JSON-tool fallbacks restrict the declared tools.
1360
+ // MCP connectors and inline definitions, including those replayed from
1361
+ // history, must not restore other tools before the provider executes the request.
1362
+ if (
1363
+ (toolChoice?.type === 'tool' &&
1364
+ (anthropicToolChoice?.type === 'auto' || jsonResponseTool != null)) ||
1365
+ (toolChoice?.type === 'none' && jsonResponseTool != null)
1366
+ ) {
1367
+ for (const server of baseArgs.mcp_servers ?? []) {
1368
+ server.tool_configuration = {
1369
+ allowed_tools: server.tool_configuration?.allowed_tools,
1370
+ enabled: false,
1371
+ };
1372
+ }
1373
+
1374
+ // Initial system tool changes are ignored by the prompt converter.
1375
+ // Validate only definitions that remain in the outgoing messages.
1376
+ const emittedInlineDefinitions = new Set(
1377
+ messagesPrompt.messages.flatMap(message =>
1378
+ message.role === 'system'
1379
+ ? message.content.flatMap(part =>
1380
+ part.type === 'tool_addition' &&
1381
+ part.tool.type === 'tool_definition'
1382
+ ? [part.tool.definition]
1383
+ : [],
1384
+ )
1385
+ : [],
1386
+ ),
1387
+ );
1388
+ const selectedSdkName =
1389
+ toolChoice.type === 'tool' ? toolChoice.toolName : undefined;
1390
+ const selectedTool = tools?.find(tool => tool.name === selectedSdkName);
1391
+ const selectedProviderName =
1392
+ jsonResponseTool != null &&
1393
+ selectedSdkName != null &&
1394
+ selectedTool?.type !== 'function'
1395
+ ? toolNameMapping.toProviderToolName(selectedSdkName)
1396
+ : selectedSdkName;
1397
+ const conflictingTool = inlineToolDefinitions.find(
1398
+ ({ sdkName, definition }) =>
1399
+ emittedInlineDefinitions.has(definition) &&
1400
+ (toolChoice.type === 'none' ||
1401
+ // The JSON-tool path filters application tools by SDK name before
1402
+ // conversion; the forced-choice fallback filters by provider name.
1403
+ (jsonResponseTool != null && sdkName !== selectedSdkName) ||
1404
+ !('name' in definition) ||
1405
+ definition.name !== selectedProviderName),
1406
+ );
1407
+ if (conflictingTool != null) {
1408
+ const toolName =
1409
+ 'name' in conflictingTool.definition
1410
+ ? conflictingTool.definition.name
1411
+ : conflictingTool.definition.type;
1412
+ const choice =
1413
+ toolChoice.type === 'tool'
1414
+ ? `named tool choice '${toolChoice.toolName}'`
1415
+ : `tool choice 'none'`;
1416
+ throw new InvalidArgumentError({
1417
+ argument: 'toolChoice',
1418
+ message:
1419
+ `Inline tool '${toolName}' conflicts with ${choice}. ` +
1420
+ 'Inline definitions must respect the tool choice when forced tool use falls back or the JSON response tool is used.',
1421
+ });
1422
+ }
1423
+ }
1424
+
1195
1425
  // Extract cache control warnings once at the end
1196
1426
  const cacheWarnings = cacheControlValidator.getWarnings();
1197
1427
 
1198
1428
  return {
1199
1429
  args: {
1200
1430
  ...baseArgs,
1201
- tools: anthropicTools,
1431
+ tools: thread?.type === 'continue' ? undefined : anthropicTools,
1202
1432
  tool_choice: anthropicToolChoice,
1203
1433
  stream: stream === true ? true : undefined, // do not send when not streaming
1204
1434
  },
1205
1435
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
1206
1436
  betas: new Set([
1437
+ ...(thread != null ? ['message-threads-2026-08-12'] : []),
1207
1438
  ...betas,
1208
1439
  ...toolsBetas,
1209
1440
  ...userSuppliedBetas,
1210
1441
  ...(anthropicOptions?.anthropicBeta ?? []),
1211
1442
  ]),
1443
+ markCodeExecutionDynamic:
1444
+ hasDynamicFilteringWebToolWithoutCodeExecution(anthropicTools),
1212
1445
  usesJsonResponseTool: jsonResponseTool != null,
1213
1446
  includePings: stream === true && anthropicOptions?.includePings === true,
1214
1447
  toolNameMapping,
1448
+ preparedTools: anthropicTools,
1215
1449
  providerOptionsName,
1216
1450
  usedCustomProviderKey,
1217
1451
  };
@@ -1338,7 +1572,9 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1338
1572
  warnings,
1339
1573
  betas,
1340
1574
  usesJsonResponseTool,
1575
+ markCodeExecutionDynamic,
1341
1576
  toolNameMapping,
1577
+ preparedTools,
1342
1578
  providerOptionsName,
1343
1579
  usedCustomProviderKey,
1344
1580
  } = await this.getArgs({
@@ -1355,9 +1591,6 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1355
1591
  ...this.extractCitationDocuments(options.prompt),
1356
1592
  ];
1357
1593
 
1358
- const markCodeExecutionDynamic =
1359
- hasDynamicFilteringWebToolWithoutCodeExecution(args.tools);
1360
-
1361
1594
  const {
1362
1595
  responseHeaders,
1363
1596
  value: response,
@@ -1510,6 +1743,11 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1510
1743
  text: JSON.stringify(part.input),
1511
1744
  });
1512
1745
  } else if (part.toolset_name != null) {
1746
+ validateToolsetMember({
1747
+ toolsetName: part.toolset_name,
1748
+ memberName: part.name,
1749
+ tools: preparedTools,
1750
+ });
1513
1751
  // toolset member calls (e.g. the computer toolset) are mapped to
1514
1752
  // the toolset tool with the member name as the `action`:
1515
1753
  content.push({
@@ -2005,8 +2243,10 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
2005
2243
  warnings,
2006
2244
  betas,
2007
2245
  usesJsonResponseTool,
2246
+ markCodeExecutionDynamic,
2008
2247
  includePings,
2009
2248
  toolNameMapping,
2249
+ preparedTools,
2010
2250
  providerOptionsName,
2011
2251
  usedCustomProviderKey,
2012
2252
  } = await this.getArgs({
@@ -2023,9 +2263,6 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
2023
2263
  ...this.extractCitationDocuments(options.prompt),
2024
2264
  ];
2025
2265
 
2026
- const markCodeExecutionDynamic =
2027
- hasDynamicFilteringWebToolWithoutCodeExecution(body.tools);
2028
-
2029
2266
  const url = this.buildRequestUrl(true);
2030
2267
  const { responseHeaders, value: response } = await postJsonToApi({
2031
2268
  url,
@@ -2301,6 +2538,11 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
2301
2538
  id: String(value.index),
2302
2539
  });
2303
2540
  } else if (part.toolset_name != null) {
2541
+ validateToolsetMember({
2542
+ toolsetName: part.toolset_name,
2543
+ memberName: part.name,
2544
+ tools: preparedTools,
2545
+ });
2304
2546
  const callerInfo = getAnthropicCallerInfo(part.caller);
2305
2547
  const customToolName = toolNameMapping.toCustomToolName(
2306
2548
  part.toolset_name,
@@ -2824,19 +3066,18 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
2824
3066
  ? {}
2825
3067
  : secureJsonParse(contentBlock.input);
2826
3068
  } catch {
2827
- // ignore parse errors, fall back to the raw input
2828
- memberInput = undefined;
3069
+ throw new InvalidResponseDataError({
3070
+ data: contentBlock.input,
3071
+ message: 'Invalid toolset member input JSON.',
3072
+ });
2829
3073
  }
2830
3074
 
2831
- contentBlock.input =
2832
- memberInput === undefined
2833
- ? contentBlock.input
2834
- : JSON.stringify(
2835
- toToolsetMemberInput({
2836
- memberName: contentBlock.toolset.memberName,
2837
- input: memberInput,
2838
- }),
2839
- );
3075
+ contentBlock.input = JSON.stringify(
3076
+ toToolsetMemberInput({
3077
+ memberName: contentBlock.toolset.memberName,
3078
+ input: memberInput,
3079
+ }),
3080
+ );
2840
3081
 
2841
3082
  controller.enqueue({
2842
3083
  type: 'tool-input-delta',
@@ -15,6 +15,7 @@ type AnthropicLanguageProviderOption = keyof AnthropicLanguageModelOptions;
15
15
  */
16
16
  export const anthropicProviderOptions = {
17
17
  language: {
18
+ thread: { description: 'Create or continue a short-lived message thread.' },
18
19
  sendReasoning: { description: 'Whether to send reasoning to the model.' },
19
20
  includePings: { description: 'Include transient ping events in streams.' },
20
21
  structuredOutputMode: {
@@ -406,3 +407,6 @@ export function getAnthropicModelCapabilities(modelId: string) {
406
407
  isKnownModel: requestConfig.knownModel,
407
408
  };
408
409
  }
410
+
411
+ // Compatibility name also exported by the Anthropic runtime adapter.
412
+ export { getAnthropicModelCapabilities as getModelCapabilities };
@@ -27,6 +27,7 @@ export interface AnthropicToolOptions {
27
27
  export async function prepareTools({
28
28
  tools,
29
29
  toolChoice,
30
+ hasInlineTools = false,
30
31
  disableParallelToolUse,
31
32
  cacheControlValidator,
32
33
  supportsStructuredOutput,
@@ -36,6 +37,13 @@ export async function prepareTools({
36
37
  }: {
37
38
  tools: LanguageModelV4CallOptions['tools'];
38
39
  toolChoice: LanguageModelV4CallOptions['toolChoice'] | undefined;
40
+
41
+ /**
42
+ * Whether tools are added by value in the prompt (mid-conversation tool
43
+ * changes). The model has tools even when `tools` is empty, so the tool
44
+ * choice and parallel tool use settings still need to be sent.
45
+ */
46
+ hasInlineTools?: boolean;
39
47
  disableParallelToolUse?: boolean;
40
48
  cacheControlValidator?: CacheControlValidator;
41
49
 
@@ -74,13 +82,13 @@ export async function prepareTools({
74
82
  const betas = new Set<string>();
75
83
  const validator = cacheControlValidator || new CacheControlValidator();
76
84
 
77
- if (tools == null) {
85
+ if (tools == null && !hasInlineTools) {
78
86
  return { tools: undefined, toolChoice: undefined, toolWarnings, betas };
79
87
  }
80
88
 
81
89
  const anthropicTools: AnthropicTool[] = [];
82
90
 
83
- for (const tool of tools) {
91
+ for (const tool of tools ?? []) {
84
92
  switch (tool.type) {
85
93
  case 'function': {
86
94
  const cacheControl = validator.getCacheControl(tool.providerOptions, {
@@ -464,9 +472,13 @@ export async function prepareTools({
464
472
  }
465
473
  }
466
474
 
475
+ // when the user passed no tools (they exist only in tool changes inside the
476
+ // messages), omit `tools` instead of sending an empty array
477
+ const declaredTools = tools == null ? undefined : anthropicTools;
478
+
467
479
  if (toolChoice == null) {
468
480
  return {
469
- tools: anthropicTools,
481
+ tools: declaredTools,
470
482
  toolChoice: disableParallelToolUse
471
483
  ? { type: 'auto', disable_parallel_tool_use: disableParallelToolUse }
472
484
  : undefined,
@@ -480,7 +492,7 @@ export async function prepareTools({
480
492
  switch (type) {
481
493
  case 'auto':
482
494
  return {
483
- tools: anthropicTools,
495
+ tools: declaredTools,
484
496
  toolChoice: {
485
497
  type: 'auto',
486
498
  disable_parallel_tool_use: disableParallelToolUse,
@@ -498,7 +510,7 @@ export async function prepareTools({
498
510
  `Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made.`,
499
511
  });
500
512
  return {
501
- tools: anthropicTools,
513
+ tools: declaredTools,
502
514
  toolChoice: {
503
515
  type: 'auto',
504
516
  disable_parallel_tool_use: disableParallelToolUse,
@@ -508,7 +520,7 @@ export async function prepareTools({
508
520
  };
509
521
  }
510
522
  return {
511
- tools: anthropicTools,
523
+ tools: declaredTools,
512
524
  toolChoice: {
513
525
  type: 'any',
514
526
  disable_parallel_tool_use: disableParallelToolUse,
@@ -518,7 +530,7 @@ export async function prepareTools({
518
530
  };
519
531
  case 'none':
520
532
  return {
521
- tools: anthropicTools,
533
+ tools: declaredTools,
522
534
  toolChoice: { type: 'none' },
523
535
  toolWarnings,
524
536
  betas,
@@ -534,7 +546,7 @@ export async function prepareTools({
534
546
  `Instruct the model to use the tool in the prompt and verify that a tool call was made.`,
535
547
  });
536
548
  return {
537
- tools: anthropicTools.filter(
549
+ tools: declaredTools?.filter(
538
550
  tool => 'name' in tool && tool.name === toolChoice.toolName,
539
551
  ),
540
552
  toolChoice: {
@@ -546,7 +558,7 @@ export async function prepareTools({
546
558
  };
547
559
  }
548
560
  return {
549
- tools: anthropicTools,
561
+ tools: declaredTools,
550
562
  toolChoice: {
551
563
  type: 'tool',
552
564
  name: toolChoice.toolName,
@@ -195,6 +195,7 @@ export function createAnthropic(
195
195
 
196
196
  const languageModelConfig = {
197
197
  provider: providerName,
198
+ supportsMessageThreads: true,
198
199
  baseURL,
199
200
  headers: getHeaders,
200
201
  fetch: options.fetch,