@ai-sdk/anthropic 4.0.45 → 4.0.46

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 * as _ai_sdk_provider from '@ai-sdk/provider';
2
2
  import { FilesV4, FilesV4UploadFileCallOptions, FilesV4UploadFileResult, JSONSchema7, LanguageModelV4, JSONObject, LanguageModelV4CallOptions, SharedV4Warning, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, SharedV4ProviderMetadata, SkillsV4 } from '@ai-sdk/provider';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction, InferSchema, Resolvable, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, ToolExecuteFunction, Tool, Experimental_SandboxSession, ProviderDefinedTool } from '@ai-sdk/provider-utils';
5
+ import { z } from 'zod/v4';
5
6
 
6
7
  interface AnthropicFilesConfig {
7
8
  provider: string;
@@ -328,6 +329,7 @@ interface AnthropicMcpToolResultContent {
328
329
  content: string | Array<{
329
330
  type: 'text';
330
331
  text: string;
332
+ citations?: Citation[] | null;
331
333
  }>;
332
334
  cache_control: AnthropicCacheControl | undefined;
333
335
  }
@@ -451,7 +453,7 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
451
453
  type: "web_search_result_location";
452
454
  cited_text: string;
453
455
  url: string;
454
- title: string;
456
+ title: string | null;
455
457
  encrypted_index: string;
456
458
  } | {
457
459
  type: "page_location";
@@ -460,6 +462,7 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
460
462
  document_title: string | null;
461
463
  start_page_number: number;
462
464
  end_page_number: number;
465
+ file_id?: string | null | undefined;
463
466
  } | {
464
467
  type: "char_location";
465
468
  cited_text: string;
@@ -467,7 +470,24 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
467
470
  document_title: string | null;
468
471
  start_char_index: number;
469
472
  end_char_index: number;
470
- })[] | undefined;
473
+ file_id?: string | null | undefined;
474
+ } | {
475
+ type: "content_block_location";
476
+ cited_text: string;
477
+ document_index: number;
478
+ document_title: string | null;
479
+ start_block_index: number;
480
+ end_block_index: number;
481
+ file_id: string | null;
482
+ } | {
483
+ type: "search_result_location";
484
+ cited_text: string;
485
+ search_result_index: number;
486
+ source: string;
487
+ title: string | null;
488
+ start_block_index: number;
489
+ end_block_index: number;
490
+ })[] | null | undefined;
471
491
  } | {
472
492
  type: "thinking";
473
493
  thinking: string;
@@ -516,9 +536,10 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
516
536
  type: "mcp_tool_result";
517
537
  tool_use_id: string;
518
538
  is_error: boolean;
519
- content: (string | {
539
+ content: string | (string | {
520
540
  type: "text";
521
541
  text: string;
542
+ citations?: z.core.util.JSONType[] | null | undefined;
522
543
  })[];
523
544
  } | {
524
545
  type: "web_fetch_tool_result";
@@ -526,7 +547,7 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
526
547
  content: {
527
548
  type: "web_fetch_result";
528
549
  url: string;
529
- retrieved_at: string;
550
+ retrieved_at: string | null;
530
551
  content: {
531
552
  type: "document";
532
553
  title: string | null;
@@ -562,7 +583,7 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
562
583
  content: {
563
584
  type: "web_search_result";
564
585
  url: string;
565
- title: string;
586
+ title: string | null;
566
587
  encrypted_content: string;
567
588
  page_age?: string | null | undefined;
568
589
  }[] | {
@@ -656,6 +677,9 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
656
677
  type: "tool_search_tool_result_error";
657
678
  error_code: string;
658
679
  };
680
+ } | {
681
+ type: "container_upload";
682
+ file_id: string;
659
683
  } | {
660
684
  type: "advisor_tool_result";
661
685
  tool_use_id: string;
@@ -754,7 +778,7 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
754
778
  readonly specificationVersion = "v4";
755
779
  readonly modelId: AnthropicModelId;
756
780
  protected readonly config: AnthropicLanguageModelConfig;
757
- private readonly generateId;
781
+ protected readonly generateId: () => string;
758
782
  static [WORKFLOW_SERIALIZE](model: AnthropicLanguageModel): {
759
783
  modelId: string;
760
784
  config: JSONObject;
@@ -851,6 +875,7 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
851
875
  speed?: "fast" | "standard" | undefined;
852
876
  }[] | undefined;
853
877
  inference_geo?: "us" | "global" | undefined;
878
+ service_tier?: "auto" | "standard_only" | undefined;
854
879
  speed?: "fast" | "standard" | undefined;
855
880
  output_config?: {
856
881
  format?: {
@@ -149,6 +149,66 @@ var anthropicToolCallCallerSchema = z3.union([
149
149
  type: z3.literal("direct")
150
150
  })
151
151
  ]);
152
+ var anthropicCitationSchema = z3.discriminatedUnion("type", [
153
+ z3.object({
154
+ type: z3.literal("web_search_result_location"),
155
+ cited_text: z3.string(),
156
+ url: z3.string(),
157
+ title: z3.string().nullable(),
158
+ encrypted_index: z3.string()
159
+ }),
160
+ z3.object({
161
+ type: z3.literal("page_location"),
162
+ cited_text: z3.string(),
163
+ document_index: z3.number(),
164
+ document_title: z3.string().nullable(),
165
+ start_page_number: z3.number(),
166
+ end_page_number: z3.number(),
167
+ file_id: z3.string().nullish()
168
+ }),
169
+ z3.object({
170
+ type: z3.literal("char_location"),
171
+ cited_text: z3.string(),
172
+ document_index: z3.number(),
173
+ document_title: z3.string().nullable(),
174
+ start_char_index: z3.number(),
175
+ end_char_index: z3.number(),
176
+ file_id: z3.string().nullish()
177
+ }),
178
+ z3.object({
179
+ type: z3.literal("content_block_location"),
180
+ cited_text: z3.string(),
181
+ document_index: z3.number(),
182
+ document_title: z3.string().nullable(),
183
+ start_block_index: z3.number(),
184
+ end_block_index: z3.number(),
185
+ file_id: z3.string().nullable()
186
+ }),
187
+ z3.object({
188
+ type: z3.literal("search_result_location"),
189
+ cited_text: z3.string(),
190
+ search_result_index: z3.number(),
191
+ source: z3.string(),
192
+ title: z3.string().nullable(),
193
+ start_block_index: z3.number(),
194
+ end_block_index: z3.number()
195
+ })
196
+ ]);
197
+ var anthropicMcpToolResultContentSchema = z3.union([
198
+ z3.string(),
199
+ z3.array(
200
+ z3.union([
201
+ z3.string(),
202
+ z3.object({
203
+ type: z3.literal("text"),
204
+ text: z3.string(),
205
+ // MCP tool-result citations are opaque third-party pass-through data.
206
+ // Keep them permissive so new shapes do not reject whole responses.
207
+ citations: z3.array(z3.json()).nullable().optional()
208
+ })
209
+ ])
210
+ )
211
+ ]);
152
212
  var anthropicResponseSchema = lazySchema3(
153
213
  () => zodSchema3(
154
214
  z3.object({
@@ -160,33 +220,7 @@ var anthropicResponseSchema = lazySchema3(
160
220
  z3.object({
161
221
  type: z3.literal("text"),
162
222
  text: z3.string(),
163
- citations: z3.array(
164
- z3.discriminatedUnion("type", [
165
- z3.object({
166
- type: z3.literal("web_search_result_location"),
167
- cited_text: z3.string(),
168
- url: z3.string(),
169
- title: z3.string(),
170
- encrypted_index: z3.string()
171
- }),
172
- z3.object({
173
- type: z3.literal("page_location"),
174
- cited_text: z3.string(),
175
- document_index: z3.number(),
176
- document_title: z3.string().nullable(),
177
- start_page_number: z3.number(),
178
- end_page_number: z3.number()
179
- }),
180
- z3.object({
181
- type: z3.literal("char_location"),
182
- cited_text: z3.string(),
183
- document_index: z3.number(),
184
- document_title: z3.string().nullable(),
185
- start_char_index: z3.number(),
186
- end_char_index: z3.number()
187
- })
188
- ])
189
- ).optional()
223
+ citations: z3.array(anthropicCitationSchema).nullable().optional()
190
224
  }),
191
225
  z3.object({
192
226
  type: z3.literal("thinking"),
@@ -227,12 +261,7 @@ var anthropicResponseSchema = lazySchema3(
227
261
  type: z3.literal("mcp_tool_result"),
228
262
  tool_use_id: z3.string(),
229
263
  is_error: z3.boolean(),
230
- content: z3.array(
231
- z3.union([
232
- z3.string(),
233
- z3.object({ type: z3.literal("text"), text: z3.string() })
234
- ])
235
- )
264
+ content: anthropicMcpToolResultContentSchema
236
265
  }),
237
266
  z3.object({
238
267
  type: z3.literal("web_fetch_tool_result"),
@@ -242,7 +271,7 @@ var anthropicResponseSchema = lazySchema3(
242
271
  z3.object({
243
272
  type: z3.literal("web_fetch_result"),
244
273
  url: z3.string(),
245
- retrieved_at: z3.string(),
274
+ retrieved_at: z3.string().nullable(),
246
275
  content: z3.object({
247
276
  type: z3.literal("document"),
248
277
  title: z3.string().nullable(),
@@ -276,7 +305,7 @@ var anthropicResponseSchema = lazySchema3(
276
305
  z3.object({
277
306
  type: z3.literal("web_search_result"),
278
307
  url: z3.string(),
279
- title: z3.string(),
308
+ title: z3.string().nullable(),
280
309
  encrypted_content: z3.string(),
281
310
  page_age: z3.string().nullish()
282
311
  })
@@ -398,6 +427,10 @@ var anthropicResponseSchema = lazySchema3(
398
427
  })
399
428
  ])
400
429
  }),
430
+ z3.object({
431
+ type: z3.literal("container_upload"),
432
+ file_id: z3.string()
433
+ }),
401
434
  // advisor results for advisor_20260301:
402
435
  z3.object({
403
436
  type: z3.literal("advisor_tool_result"),
@@ -567,12 +600,7 @@ var anthropicChunkSchema = lazySchema3(
567
600
  type: z3.literal("mcp_tool_result"),
568
601
  tool_use_id: z3.string(),
569
602
  is_error: z3.boolean(),
570
- content: z3.array(
571
- z3.union([
572
- z3.string(),
573
- z3.object({ type: z3.literal("text"), text: z3.string() })
574
- ])
575
- )
603
+ content: anthropicMcpToolResultContentSchema
576
604
  }),
577
605
  z3.object({
578
606
  type: z3.literal("web_fetch_tool_result"),
@@ -582,7 +610,7 @@ var anthropicChunkSchema = lazySchema3(
582
610
  z3.object({
583
611
  type: z3.literal("web_fetch_result"),
584
612
  url: z3.string(),
585
- retrieved_at: z3.string(),
613
+ retrieved_at: z3.string().nullable(),
586
614
  content: z3.object({
587
615
  type: z3.literal("document"),
588
616
  title: z3.string().nullable(),
@@ -616,7 +644,7 @@ var anthropicChunkSchema = lazySchema3(
616
644
  z3.object({
617
645
  type: z3.literal("web_search_result"),
618
646
  url: z3.string(),
619
- title: z3.string(),
647
+ title: z3.string().nullable(),
620
648
  encrypted_content: z3.string(),
621
649
  page_age: z3.string().nullish()
622
650
  })
@@ -792,31 +820,7 @@ var anthropicChunkSchema = lazySchema3(
792
820
  }),
793
821
  z3.object({
794
822
  type: z3.literal("citations_delta"),
795
- citation: z3.discriminatedUnion("type", [
796
- z3.object({
797
- type: z3.literal("web_search_result_location"),
798
- cited_text: z3.string(),
799
- url: z3.string(),
800
- title: z3.string(),
801
- encrypted_index: z3.string()
802
- }),
803
- z3.object({
804
- type: z3.literal("page_location"),
805
- cited_text: z3.string(),
806
- document_index: z3.number(),
807
- document_title: z3.string().nullable(),
808
- start_page_number: z3.number(),
809
- end_page_number: z3.number()
810
- }),
811
- z3.object({
812
- type: z3.literal("char_location"),
813
- cited_text: z3.string(),
814
- document_index: z3.number(),
815
- document_title: z3.string().nullable(),
816
- start_char_index: z3.number(),
817
- end_char_index: z3.number()
818
- })
819
- ])
823
+ citation: anthropicCitationSchema
820
824
  })
821
825
  ])
822
826
  }),
@@ -1112,6 +1116,8 @@ var anthropicLanguageModelOptions = z4.object({
1112
1116
  * Only supported with claude-opus-4-6.
1113
1117
  */
1114
1118
  speed: z4.enum(["fast", "standard"]).optional(),
1119
+ /** Selects Anthropic's service tier for the request. */
1120
+ serviceTier: z4.enum(["auto", "standard_only"]).optional(),
1115
1121
  /**
1116
1122
  * Controls where model inference runs for this request.
1117
1123
  *
@@ -3615,14 +3621,14 @@ function getAnthropicStreamErrorMetadata(type) {
3615
3621
  }
3616
3622
  }
3617
3623
  function createCitationSource(citation, citationDocuments, generateId2) {
3618
- var _a;
3624
+ var _a, _b;
3619
3625
  if (citation.type === "web_search_result_location") {
3620
3626
  return {
3621
3627
  type: "source",
3622
3628
  sourceType: "url",
3623
3629
  id: generateId2(),
3624
3630
  url: citation.url,
3625
- title: citation.title,
3631
+ title: (_a = citation.title) != null ? _a : void 0,
3626
3632
  providerMetadata: {
3627
3633
  anthropic: {
3628
3634
  citedText: citation.cited_text,
@@ -3643,7 +3649,7 @@ function createCitationSource(citation, citationDocuments, generateId2) {
3643
3649
  sourceType: "document",
3644
3650
  id: generateId2(),
3645
3651
  mediaType: documentInfo.mediaType,
3646
- title: (_a = citation.document_title) != null ? _a : documentInfo.title,
3652
+ title: (_b = citation.document_title) != null ? _b : documentInfo.title,
3647
3653
  filename: documentInfo.filename,
3648
3654
  providerMetadata: {
3649
3655
  anthropic: citation.type === "page_location" ? {
@@ -3940,6 +3946,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3940
3946
  ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
3941
3947
  speed: anthropicOptions.speed
3942
3948
  },
3949
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.serviceTier) && {
3950
+ service_tier: anthropicOptions.serviceTier
3951
+ },
3943
3952
  ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3944
3953
  inference_geo: anthropicOptions.inferenceGeo
3945
3954
  },
@@ -4327,6 +4336,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4327
4336
  });
4328
4337
  break;
4329
4338
  }
4339
+ case "container_upload": {
4340
+ content.push({
4341
+ type: "custom",
4342
+ kind: "anthropic.container_upload",
4343
+ providerMetadata: { anthropic: { fileId: part.file_id } }
4344
+ });
4345
+ break;
4346
+ }
4330
4347
  case "compaction": {
4331
4348
  content.push({
4332
4349
  type: "text",
@@ -4493,7 +4510,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4493
4510
  var _a2;
4494
4511
  return {
4495
4512
  url: result.url,
4496
- title: result.title,
4513
+ ...result.title != null ? { title: result.title } : {},
4497
4514
  pageAge: (_a2 = result.page_age) != null ? _a2 : null,
4498
4515
  encryptedContent: result.encrypted_content,
4499
4516
  type: result.type
@@ -4507,7 +4524,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4507
4524
  sourceType: "url",
4508
4525
  id: this.generateId(),
4509
4526
  url: result.url,
4510
- title: result.title,
4527
+ ...result.title != null ? { title: result.title } : {},
4511
4528
  providerMetadata: {
4512
4529
  anthropic: {
4513
4530
  pageAge: (_c = result.page_age) != null ? _c : null
@@ -5045,7 +5062,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5045
5062
  var _a3;
5046
5063
  return {
5047
5064
  url: result.url,
5048
- title: result.title,
5065
+ ...result.title != null ? { title: result.title } : {},
5049
5066
  pageAge: (_a3 = result.page_age) != null ? _a3 : null,
5050
5067
  encryptedContent: result.encrypted_content,
5051
5068
  type: result.type
@@ -5059,7 +5076,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5059
5076
  sourceType: "url",
5060
5077
  id: generateId2(),
5061
5078
  url: result.url,
5062
- title: result.title,
5079
+ ...result.title != null ? { title: result.title } : {},
5063
5080
  providerMetadata: {
5064
5081
  anthropic: {
5065
5082
  pageAge: (_b2 = result.page_age) != null ? _b2 : null
@@ -5774,7 +5791,7 @@ function hasWebTool20260209WithoutCodeExecution(tools) {
5774
5791
  hasWebTool20260209 = true;
5775
5792
  continue;
5776
5793
  }
5777
- if (tool.name === "code_execution") {
5794
+ if ("type" in tool && (tool.type === "code_execution_20250522" || tool.type === "code_execution_20250825" || tool.type === "code_execution_20260120")) {
5778
5795
  hasCodeExecutionTool = true;
5779
5796
  break;
5780
5797
  }