@ai-sdk/anthropic 4.0.83 → 4.0.85

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.
@@ -1,4 +1,4 @@
1
- import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, validateTypes, zodSchema } from "@ai-sdk/provider-utils";
1
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, validateTypes, zodSchema } from "@ai-sdk/provider-utils";
2
2
  import { z } from "zod/v4";
3
3
  import { APICallError, InvalidArgumentError, InvalidResponseDataError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
4
4
  //#region src/anthropic-error.ts
@@ -95,18 +95,19 @@ function mapAnthropicCitation(citation, documents) {
95
95
  }
96
96
  //#endregion
97
97
  //#region src/anthropic-api.ts
98
- const anthropicFallbackContentSchema = z.object({
98
+ const anthropicFallbackContentSchema = () => z.object({
99
99
  type: z.literal("fallback"),
100
100
  from: z.object({ model: z.string() }),
101
101
  to: z.object({ model: z.string() })
102
102
  });
103
- const anthropicStopDetailsSchema = z.object({
103
+ const anthropicFallbackContentSchemaValidator = lazySchema(() => zodSchema(anthropicFallbackContentSchema()));
104
+ const anthropicStopDetailsSchema = () => z.object({
104
105
  type: z.string(),
105
106
  category: z.string().nullish(),
106
107
  explanation: z.string().nullish(),
107
108
  recommended_model: z.string().nullish()
108
109
  });
109
- const anthropicSafeguardResultSchema = z.object({
110
+ const anthropicSafeguardResultSchema = () => z.object({
110
111
  type: z.string(),
111
112
  status: z.object({
112
113
  type: z.string(),
@@ -117,7 +118,7 @@ const anthropicSafeguardResultSchema = z.object({
117
118
  })).nullish()
118
119
  })
119
120
  });
120
- const anthropicToolCallCallerSchema = z.union([
121
+ const anthropicToolCallCallerSchema = () => z.union([
121
122
  z.object({
122
123
  type: z.literal("code_execution_20250825"),
123
124
  tool_id: z.string()
@@ -128,7 +129,7 @@ const anthropicToolCallCallerSchema = z.union([
128
129
  }),
129
130
  z.object({ type: z.literal("direct") })
130
131
  ]);
131
- const anthropicCitationSchema = z.discriminatedUnion("type", [
132
+ const anthropicCitationSchema = () => z.discriminatedUnion("type", [
132
133
  z.object({
133
134
  type: z.literal("web_search_result_location"),
134
135
  cited_text: z.string(),
@@ -173,12 +174,12 @@ const anthropicCitationSchema = z.discriminatedUnion("type", [
173
174
  end_block_index: z.number()
174
175
  })
175
176
  ]);
176
- const anthropicMcpToolResultContentSchema = z.union([z.string(), z.array(z.union([z.string(), z.object({
177
+ const anthropicMcpToolResultContentSchema = () => z.union([z.string(), z.array(z.union([z.string(), z.object({
177
178
  type: z.literal("text"),
178
179
  text: z.string(),
179
180
  citations: z.array(z.json()).nullable().optional()
180
181
  })]))]);
181
- const anthropicInputTransformationSchema = z.object({
182
+ const anthropicInputTransformationSchema = () => z.object({
182
183
  type: z.string(),
183
184
  path: z.string(),
184
185
  reason: z.string()
@@ -191,7 +192,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
191
192
  z.object({
192
193
  type: z.literal("text"),
193
194
  text: z.string(),
194
- citations: z.array(anthropicCitationSchema).nullable().optional()
195
+ citations: z.array(anthropicCitationSchema()).nullable().optional()
195
196
  }),
196
197
  z.object({
197
198
  type: z.literal("thinking"),
@@ -212,7 +213,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
212
213
  id: z.string(),
213
214
  name: z.string(),
214
215
  input: z.unknown(),
215
- caller: anthropicToolCallCallerSchema.optional(),
216
+ caller: anthropicToolCallCallerSchema().optional(),
216
217
  toolset_name: z.string().nullish()
217
218
  }),
218
219
  z.object({
@@ -220,7 +221,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
220
221
  id: z.string(),
221
222
  name: z.string(),
222
223
  input: z.record(z.string(), z.unknown()).nullish(),
223
- caller: anthropicToolCallCallerSchema.optional()
224
+ caller: anthropicToolCallCallerSchema().optional()
224
225
  }),
225
226
  z.object({
226
227
  type: z.literal("mcp_tool_use"),
@@ -233,12 +234,12 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
233
234
  type: z.literal("mcp_tool_result"),
234
235
  tool_use_id: z.string(),
235
236
  is_error: z.boolean(),
236
- content: anthropicMcpToolResultContentSchema
237
+ content: anthropicMcpToolResultContentSchema()
237
238
  }),
238
239
  z.object({
239
240
  type: z.literal("web_fetch_tool_result"),
240
241
  tool_use_id: z.string(),
241
- caller: anthropicToolCallCallerSchema.optional(),
242
+ caller: anthropicToolCallCallerSchema().optional(),
242
243
  content: z.union([z.object({
243
244
  type: z.literal("web_fetch_result"),
244
245
  url: z.string(),
@@ -265,7 +266,7 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
265
266
  z.object({
266
267
  type: z.literal("web_search_tool_result"),
267
268
  tool_use_id: z.string(),
268
- caller: anthropicToolCallCallerSchema.optional(),
269
+ caller: anthropicToolCallCallerSchema().optional(),
269
270
  content: z.union([z.array(z.object({
270
271
  type: z.literal("web_search_result"),
271
272
  url: z.string(),
@@ -392,13 +393,13 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
392
393
  })
393
394
  ])
394
395
  }),
395
- anthropicFallbackContentSchema
396
+ anthropicFallbackContentSchema()
396
397
  ])),
397
398
  stop_reason: z.string().nullish(),
398
399
  stop_sequence: z.string().nullish(),
399
- stop_details: anthropicStopDetailsSchema.nullish(),
400
- input_transformations: z.array(anthropicInputTransformationSchema).nullish(),
401
- safeguard_results: z.array(anthropicSafeguardResultSchema).nullish(),
400
+ stop_details: anthropicStopDetailsSchema().nullish(),
401
+ input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
402
+ safeguard_results: z.array(anthropicSafeguardResultSchema()).nullish(),
402
403
  usage: z.looseObject({
403
404
  input_tokens: z.number(),
404
405
  output_tokens: z.number(),
@@ -459,11 +460,11 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
459
460
  id: z.string(),
460
461
  name: z.string(),
461
462
  input: z.unknown(),
462
- caller: anthropicToolCallCallerSchema.optional(),
463
+ caller: anthropicToolCallCallerSchema().optional(),
463
464
  toolset_name: z.string().nullish()
464
465
  })])).nullish(),
465
466
  stop_reason: z.string().nullish(),
466
- input_transformations: z.array(anthropicInputTransformationSchema).nullish(),
467
+ input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
467
468
  container: z.object({
468
469
  expires_at: z.string(),
469
470
  id: z.string()
@@ -487,7 +488,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
487
488
  id: z.string(),
488
489
  name: z.string(),
489
490
  input: z.record(z.string(), z.unknown()).optional(),
490
- caller: anthropicToolCallCallerSchema.optional(),
491
+ caller: anthropicToolCallCallerSchema().optional(),
491
492
  toolset_name: z.string().nullish()
492
493
  }),
493
494
  z.object({
@@ -504,7 +505,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
504
505
  id: z.string(),
505
506
  name: z.string(),
506
507
  input: z.record(z.string(), z.unknown()).nullish(),
507
- caller: anthropicToolCallCallerSchema.optional()
508
+ caller: anthropicToolCallCallerSchema().optional()
508
509
  }),
509
510
  z.object({
510
511
  type: z.literal("mcp_tool_use"),
@@ -517,12 +518,12 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
517
518
  type: z.literal("mcp_tool_result"),
518
519
  tool_use_id: z.string(),
519
520
  is_error: z.boolean(),
520
- content: anthropicMcpToolResultContentSchema
521
+ content: anthropicMcpToolResultContentSchema()
521
522
  }),
522
523
  z.object({
523
524
  type: z.literal("web_fetch_tool_result"),
524
525
  tool_use_id: z.string(),
525
- caller: anthropicToolCallCallerSchema.optional(),
526
+ caller: anthropicToolCallCallerSchema().optional(),
526
527
  content: z.union([z.object({
527
528
  type: z.literal("web_fetch_result"),
528
529
  url: z.string(),
@@ -549,7 +550,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
549
550
  z.object({
550
551
  type: z.literal("web_search_tool_result"),
551
552
  tool_use_id: z.string(),
552
- caller: anthropicToolCallCallerSchema.optional(),
553
+ caller: anthropicToolCallCallerSchema().optional(),
553
554
  content: z.union([z.array(z.object({
554
555
  type: z.literal("web_search_result"),
555
556
  url: z.string(),
@@ -672,7 +673,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
672
673
  })
673
674
  ])
674
675
  }),
675
- anthropicFallbackContentSchema
676
+ anthropicFallbackContentSchema()
676
677
  ])
677
678
  }),
678
679
  z.object({
@@ -701,7 +702,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
701
702
  }),
702
703
  z.object({
703
704
  type: z.literal("citations_delta"),
704
- citation: anthropicCitationSchema
705
+ citation: anthropicCitationSchema()
705
706
  })
706
707
  ])
707
708
  }),
@@ -725,8 +726,8 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
725
726
  delta: z.object({
726
727
  stop_reason: z.string().nullish(),
727
728
  stop_sequence: z.string().nullish(),
728
- stop_details: anthropicStopDetailsSchema.nullish(),
729
- safeguard_results: z.array(anthropicSafeguardResultSchema).nullish(),
729
+ stop_details: anthropicStopDetailsSchema().nullish(),
730
+ safeguard_results: z.array(anthropicSafeguardResultSchema()).nullish(),
730
731
  container: z.object({
731
732
  expires_at: z.string(),
732
733
  id: z.string(),
@@ -757,7 +758,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
757
758
  cache_read_input_tokens: z.number().nullish()
758
759
  })).nullish()
759
760
  }),
760
- input_transformations: z.array(anthropicInputTransformationSchema).nullish(),
761
+ input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
761
762
  context_management: z.object({ applied_edits: z.array(z.union([
762
763
  z.object({
763
764
  type: z.literal("clear_tool_uses_20250919"),
@@ -785,7 +786,7 @@ const anthropicReasoningMetadataSchema = lazySchema(() => zodSchema(z.object({
785
786
  * Anthropic file part provider options for document-specific features.
786
787
  * These options apply to individual file parts (documents).
787
788
  */
788
- const anthropicFilePartProviderOptions = z.object({
789
+ const anthropicFilePartProviderOptions = lazySchema(() => zodSchema(z.object({
789
790
  /**
790
791
  * Upload this file into the code execution container instead of sending it as
791
792
  * a normal document or image content block.
@@ -811,11 +812,11 @@ enabled: z.boolean() }).optional(),
811
812
  * Useful for storing document metadata as text or stringified JSON.
812
813
  */
813
814
  context: z.string().optional()
814
- });
815
+ })));
815
816
  /**
816
817
  * Anthropic provider options for system messages.
817
818
  */
818
- const anthropicSystemMessageProviderOptions = z.object({
819
+ const anthropicSystemMessageProviderOptions = lazySchema(() => zodSchema(z.object({
819
820
  /**
820
821
  * Controls when an ephemeral mid-conversation system message is cleared.
821
822
  *
@@ -858,8 +859,8 @@ const anthropicSystemMessageProviderOptions = z.object({
858
859
  type: z.literal("tool_removal"),
859
860
  toolName: z.string()
860
861
  })])).optional()
861
- });
862
- const anthropicLanguageModelOptions = z.object({
862
+ })));
863
+ const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
863
864
  /**
864
865
  * Whether to send reasoning to the model.
865
866
  *
@@ -1130,21 +1131,23 @@ userId: z.string().optional() }).optional(),
1130
1131
  instructions: z.string().optional()
1131
1132
  })
1132
1133
  ])) }).optional()
1133
- });
1134
+ })));
1134
1135
  //#endregion
1135
1136
  //#region src/get-cache-control.ts
1136
1137
  const MAX_CACHE_BREAKPOINTS = 4;
1137
- function getCacheControl(providerMetadata) {
1138
+ function getCacheControl(providerMetadata, providerOptionsName) {
1139
+ const custom = providerMetadata?.[providerOptionsName];
1138
1140
  const anthropic = providerMetadata?.anthropic;
1139
- return anthropic?.cacheControl ?? anthropic?.cache_control;
1141
+ return custom?.cacheControl ?? custom?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
1140
1142
  }
1141
1143
  var CacheControlValidator = class {
1142
- constructor() {
1144
+ constructor(providerOptionsName = "anthropic") {
1145
+ this.providerOptionsName = providerOptionsName;
1143
1146
  this.breakpointCount = 0;
1144
1147
  this.warnings = [];
1145
1148
  }
1146
1149
  getCacheControl(providerMetadata, context) {
1147
- const cacheControlValue = getCacheControl(providerMetadata);
1150
+ const cacheControlValue = getCacheControl(providerMetadata, this.providerOptionsName);
1148
1151
  if (!cacheControlValue) return;
1149
1152
  if (!context.canCache) {
1150
1153
  this.warnings.push({
@@ -2265,7 +2268,7 @@ function extractErrorValue(value) {
2265
2268
  }
2266
2269
  return {};
2267
2270
  }
2268
- async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {} }) {
2271
+ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart }) {
2269
2272
  const betas = /* @__PURE__ */ new Set();
2270
2273
  const blocks = groupIntoBlocks(prompt);
2271
2274
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2394,107 +2397,118 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
2394
2397
  cache_control: cacheControl
2395
2398
  });
2396
2399
  break;
2397
- case "file": switch (part.data.type) {
2398
- case "reference": {
2399
- const fileId = resolveProviderReference({
2400
- reference: part.data.reference,
2401
- provider: "anthropic"
2402
- });
2403
- betas.add("files-api-2025-04-14");
2404
- if (await shouldUseContainerUpload(part.providerOptions)) anthropicContent.push({
2405
- type: "container_upload",
2406
- file_id: fileId
2407
- });
2408
- else if (getTopLevelMediaType(part.mediaType) === "image") anthropicContent.push({
2409
- type: "image",
2410
- source: {
2411
- type: "file",
2412
- file_id: fileId
2413
- },
2414
- cache_control: cacheControl
2415
- });
2416
- else anthropicContent.push({
2417
- type: "document",
2418
- source: {
2419
- type: "file",
2420
- file_id: fileId
2421
- },
2422
- cache_control: cacheControl
2423
- });
2424
- break;
2425
- }
2426
- case "text": {
2427
- const enableCitations = await shouldEnableCitations(part.providerOptions);
2428
- const metadata = await getDocumentMetadata(part.providerOptions);
2400
+ case "file": {
2401
+ const convertedPart = await convertMediaPart?.(part);
2402
+ if (convertedPart != null) {
2429
2403
  anthropicContent.push({
2430
- type: "document",
2431
- source: {
2432
- type: "text",
2433
- media_type: "text/plain",
2434
- data: part.data.text
2435
- },
2436
- title: metadata.title ?? part.filename,
2437
- ...metadata.context && { context: metadata.context },
2438
- ...enableCitations && { citations: { enabled: true } },
2404
+ ...convertedPart,
2439
2405
  cache_control: cacheControl
2440
2406
  });
2441
2407
  break;
2442
2408
  }
2443
- case "url":
2444
- case "data": {
2445
- const topLevel = getTopLevelMediaType(part.mediaType);
2446
- if (topLevel === "image") anthropicContent.push({
2447
- type: "image",
2448
- source: part.data.type === "url" ? {
2449
- type: "url",
2450
- url: part.data.url.toString()
2451
- } : {
2452
- type: "base64",
2453
- media_type: resolveFullMediaType({ part }),
2454
- data: convertToBase64(part.data.data)
2455
- },
2456
- cache_control: cacheControl
2457
- });
2458
- else if (topLevel === "application" && (part.data.type === "url" ? part.mediaType === "application/pdf" : resolveFullMediaType({ part }) === "application/pdf")) {
2459
- betas.add("pdfs-2024-09-25");
2409
+ switch (part.data.type) {
2410
+ case "reference": {
2411
+ const fileId = resolveProviderReference({
2412
+ reference: part.data.reference,
2413
+ provider: "anthropic"
2414
+ });
2415
+ betas.add("files-api-2025-04-14");
2416
+ if (await shouldUseContainerUpload(part.providerOptions)) anthropicContent.push({
2417
+ type: "container_upload",
2418
+ file_id: fileId
2419
+ });
2420
+ else if (getTopLevelMediaType(part.mediaType) === "image") anthropicContent.push({
2421
+ type: "image",
2422
+ source: {
2423
+ type: "file",
2424
+ file_id: fileId
2425
+ },
2426
+ cache_control: cacheControl
2427
+ });
2428
+ else anthropicContent.push({
2429
+ type: "document",
2430
+ source: {
2431
+ type: "file",
2432
+ file_id: fileId
2433
+ },
2434
+ cache_control: cacheControl
2435
+ });
2436
+ break;
2437
+ }
2438
+ case "text": {
2460
2439
  const enableCitations = await shouldEnableCitations(part.providerOptions);
2461
2440
  const metadata = await getDocumentMetadata(part.providerOptions);
2462
2441
  anthropicContent.push({
2463
2442
  type: "document",
2464
- source: part.data.type === "url" ? {
2465
- type: "url",
2466
- url: part.data.url.toString()
2467
- } : {
2468
- type: "base64",
2469
- media_type: "application/pdf",
2470
- data: convertToBase64(part.data.data)
2443
+ source: {
2444
+ type: "text",
2445
+ media_type: "text/plain",
2446
+ data: part.data.text
2471
2447
  },
2472
2448
  title: metadata.title ?? part.filename,
2473
2449
  ...metadata.context && { context: metadata.context },
2474
2450
  ...enableCitations && { citations: { enabled: true } },
2475
2451
  cache_control: cacheControl
2476
2452
  });
2477
- } else if (part.mediaType === "text/plain") {
2478
- const enableCitations = await shouldEnableCitations(part.providerOptions);
2479
- const metadata = await getDocumentMetadata(part.providerOptions);
2480
- anthropicContent.push({
2481
- type: "document",
2453
+ break;
2454
+ }
2455
+ case "url":
2456
+ case "data": {
2457
+ const topLevel = getTopLevelMediaType(part.mediaType);
2458
+ if (topLevel === "image") anthropicContent.push({
2459
+ type: "image",
2482
2460
  source: part.data.type === "url" ? {
2483
2461
  type: "url",
2484
2462
  url: part.data.url.toString()
2485
2463
  } : {
2486
- type: "text",
2487
- media_type: "text/plain",
2488
- data: convertBytesDataToString(part.data.data)
2464
+ type: "base64",
2465
+ media_type: resolveFullMediaType({ part }),
2466
+ data: convertToBase64(part.data.data)
2489
2467
  },
2490
- title: metadata.title ?? part.filename,
2491
- ...metadata.context && { context: metadata.context },
2492
- ...enableCitations && { citations: { enabled: true } },
2493
2468
  cache_control: cacheControl
2494
2469
  });
2495
- } else throw new UnsupportedFunctionalityError({ functionality: `media type: ${part.mediaType}` });
2496
- break;
2470
+ else if (topLevel === "application" && (part.data.type === "url" ? part.mediaType === "application/pdf" : resolveFullMediaType({ part }) === "application/pdf")) {
2471
+ betas.add("pdfs-2024-09-25");
2472
+ const enableCitations = await shouldEnableCitations(part.providerOptions);
2473
+ const metadata = await getDocumentMetadata(part.providerOptions);
2474
+ anthropicContent.push({
2475
+ type: "document",
2476
+ source: part.data.type === "url" ? {
2477
+ type: "url",
2478
+ url: part.data.url.toString()
2479
+ } : {
2480
+ type: "base64",
2481
+ media_type: "application/pdf",
2482
+ data: convertToBase64(part.data.data)
2483
+ },
2484
+ title: metadata.title ?? part.filename,
2485
+ ...metadata.context && { context: metadata.context },
2486
+ ...enableCitations && { citations: { enabled: true } },
2487
+ cache_control: cacheControl
2488
+ });
2489
+ } else if (part.mediaType === "text/plain") {
2490
+ const enableCitations = await shouldEnableCitations(part.providerOptions);
2491
+ const metadata = await getDocumentMetadata(part.providerOptions);
2492
+ anthropicContent.push({
2493
+ type: "document",
2494
+ source: part.data.type === "url" ? {
2495
+ type: "url",
2496
+ url: part.data.url.toString()
2497
+ } : {
2498
+ type: "text",
2499
+ media_type: "text/plain",
2500
+ data: convertBytesDataToString(part.data.data)
2501
+ },
2502
+ title: metadata.title ?? part.filename,
2503
+ ...metadata.context && { context: metadata.context },
2504
+ ...enableCitations && { citations: { enabled: true } },
2505
+ cache_control: cacheControl
2506
+ });
2507
+ } else throw new UnsupportedFunctionalityError({ functionality: `media type: ${part.mediaType}` });
2508
+ break;
2509
+ }
2497
2510
  }
2511
+ break;
2498
2512
  }
2499
2513
  }
2500
2514
  }
@@ -2731,7 +2745,7 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
2731
2745
  if (part.kind !== "anthropic.fallback") break;
2732
2746
  const fallbackMetadata = await safeValidateTypes({
2733
2747
  value: part.providerOptions?.anthropic,
2734
- schema: anthropicFallbackContentSchema
2748
+ schema: anthropicFallbackContentSchemaValidator
2735
2749
  });
2736
2750
  if (!fallbackMetadata.success) {
2737
2751
  warnings.push({
@@ -3564,18 +3578,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3564
3578
  type: "unsupported",
3565
3579
  feature: "seed"
3566
3580
  });
3567
- if (temperature != null && temperature > 1) {
3581
+ const maxTemperature = config.maxTemperature ?? 1;
3582
+ const temperatureProvider = config.maxTemperature == null ? "anthropic" : getProviderOptionsName(config.provider);
3583
+ if (temperature != null && temperature > maxTemperature) {
3568
3584
  warnings.push({
3569
3585
  type: "unsupported",
3570
3586
  feature: "temperature",
3571
- details: `${temperature} exceeds anthropic maximum of 1.0. clamped to 1.0`
3587
+ details: `${temperature} exceeds ${temperatureProvider} maximum of ${maxTemperature.toFixed(1)}. clamped to ${maxTemperature.toFixed(1)}`
3572
3588
  });
3573
- temperature = 1;
3589
+ temperature = maxTemperature;
3574
3590
  } else if (temperature != null && temperature < 0) {
3575
3591
  warnings.push({
3576
3592
  type: "unsupported",
3577
3593
  feature: "temperature",
3578
- details: `${temperature} is below anthropic minimum of 0. clamped to 0`
3594
+ details: `${temperature} is below ${temperatureProvider} minimum of 0. clamped to 0`
3579
3595
  });
3580
3596
  temperature = 0;
3581
3597
  }
@@ -3661,7 +3677,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3661
3677
  argument: "providerOptions",
3662
3678
  message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
3663
3679
  });
3664
- const cacheControlValidator = new CacheControlValidator();
3680
+ const cacheControlValidator = new CacheControlValidator(config.cacheControlProviderOptionsName);
3665
3681
  const toolNameMapping = createToolNameMapping({
3666
3682
  tools,
3667
3683
  providerToolNames: {
@@ -3697,7 +3713,8 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3697
3713
  warnings,
3698
3714
  cacheControlValidator,
3699
3715
  toolNameMapping,
3700
- toolsetNames
3716
+ toolsetNames,
3717
+ convertMediaPart: config.convertMediaPart
3701
3718
  });
3702
3719
  if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
3703
3720
  const reasoningConfig = resolveAnthropicReasoningConfig({
@@ -3869,7 +3886,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3869
3886
  };
3870
3887
  thinkingBudget = 1024;
3871
3888
  }
3872
- if (baseArgs.temperature != null) {
3889
+ if (baseArgs.temperature != null && !config.supportsTemperatureAndTopPWithThinking) {
3873
3890
  baseArgs.temperature = void 0;
3874
3891
  warnings.push({
3875
3892
  type: "unsupported",
@@ -3885,7 +3902,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
3885
3902
  details: "topK is not supported when thinking is enabled"
3886
3903
  });
3887
3904
  }
3888
- if (topP != null) {
3905
+ if (topP != null && !config.supportsTemperatureAndTopPWithThinking) {
3889
3906
  baseArgs.top_p = void 0;
3890
3907
  warnings.push({
3891
3908
  type: "unsupported",
@@ -6156,10 +6173,6 @@ const anthropicSkillVersionResponseSchema = lazySchema(() => zodSchema(z.object(
6156
6173
  })));
6157
6174
  //#endregion
6158
6175
  //#region src/skills/anthropic-skills.ts
6159
- function encodePathSegment(value) {
6160
- const encodedValue = encodeURIComponent(value);
6161
- return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
6162
- }
6163
6176
  var AnthropicSkills = class {
6164
6177
  get provider() {
6165
6178
  return this.config.provider;