@ai-sdk/provider 2.0.0-canary.4 → 2.0.0-canary.6

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/dist/index.d.ts CHANGED
@@ -1,11 +1,63 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
2
  export { JSONSchema7, JSONSchema7Definition } from 'json-schema';
3
3
 
4
+ type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
5
+ type JSONObject = {
6
+ [key: string]: JSONValue;
7
+ };
8
+ type JSONArray = JSONValue[];
9
+
10
+ /**
11
+ * Additional provider-specific metadata.
12
+ * Metadata are additional outputs from the provider.
13
+ * They are passed through to the provider from the AI SDK
14
+ * and enable provider-specific functionality
15
+ * that can be fully encapsulated in the provider.
16
+ *
17
+ * This enables us to quickly ship provider-specific functionality
18
+ * without affecting the core AI SDK.
19
+ *
20
+ * The outer record is keyed by the provider name, and the inner
21
+ * record is keyed by the provider-specific metadata key.
22
+ *
23
+ * ```ts
24
+ * {
25
+ * "anthropic": {
26
+ * "cacheControl": { "type": "ephemeral" }
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
32
+
33
+ /**
34
+ * Additional provider-specific options.
35
+ * Options are additional input to the provider.
36
+ * They are passed through to the provider from the AI SDK
37
+ * and enable provider-specific functionality
38
+ * that can be fully encapsulated in the provider.
39
+ *
40
+ * This enables us to quickly ship provider-specific functionality
41
+ * without affecting the core AI SDK.
42
+ *
43
+ * The outer record is keyed by the provider name, and the inner
44
+ * record is keyed by the provider-specific metadata key.
45
+ *
46
+ * ```ts
47
+ * {
48
+ * "anthropic": {
49
+ * "cacheControl": { "type": "ephemeral" }
50
+ * }
51
+ * }
52
+ * ```
53
+ */
54
+ type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>;
55
+
4
56
  /**
5
57
  An embedding is a vector, i.e. an array of numbers.
6
58
  It is e.g. used to represent a text as a vector of word embeddings.
7
59
  */
8
- type EmbeddingModelV1Embedding = Array<number>;
60
+ type EmbeddingModelV2Embedding = Array<number>;
9
61
 
10
62
  /**
11
63
  Specification for an embedding model that implements the embedding model
@@ -15,7 +67,7 @@ VALUE is the type of the values that the model can embed.
15
67
  This will allow us to go beyond text embeddings in the future,
16
68
  e.g. to support image embeddings
17
69
  */
18
- type EmbeddingModelV1<VALUE> = {
70
+ type EmbeddingModelV2<VALUE> = {
19
71
  /**
20
72
  The embedding model must specify which embedding model interface
21
73
  version it implements. This will allow us to evolve the embedding
@@ -23,7 +75,7 @@ type EmbeddingModelV1<VALUE> = {
23
75
  implementation versions can be handled as a discriminated union
24
76
  on our side.
25
77
  */
26
- readonly specificationVersion: 'v1';
78
+ readonly specificationVersion: 'v2';
27
79
  /**
28
80
  Name of the provider for logging purposes.
29
81
  */
@@ -56,6 +108,12 @@ type EmbeddingModelV1<VALUE> = {
56
108
  */
57
109
  abortSignal?: AbortSignal;
58
110
  /**
111
+ Additional provider-specific options. They are passed through
112
+ to the provider from the AI SDK and enable provider-specific
113
+ functionality that can be fully encapsulated in the provider.
114
+ */
115
+ providerOptions?: SharedV2ProviderOptions;
116
+ /**
59
117
  Additional HTTP headers to be sent with the request.
60
118
  Only applicable for HTTP-based providers.
61
119
  */
@@ -64,7 +122,7 @@ type EmbeddingModelV1<VALUE> = {
64
122
  /**
65
123
  Generated embeddings. They are in the same order as the input values.
66
124
  */
67
- embeddings: Array<EmbeddingModelV1Embedding>;
125
+ embeddings: Array<EmbeddingModelV2Embedding>;
68
126
  /**
69
127
  Token usage. We only have input tokens for embeddings.
70
128
  */
@@ -72,13 +130,17 @@ type EmbeddingModelV1<VALUE> = {
72
130
  tokens: number;
73
131
  };
74
132
  /**
75
- Optional raw response information for debugging purposes.
133
+ Optional response information for debugging purposes.
76
134
  */
77
- rawResponse?: {
135
+ response?: {
78
136
  /**
79
137
  Response headers.
80
138
  */
81
139
  headers?: Record<string, string>;
140
+ /**
141
+ The response body.
142
+ */
143
+ body?: unknown;
82
144
  };
83
145
  }>;
84
146
  };
@@ -305,12 +367,6 @@ declare class UnsupportedFunctionalityError extends AISDKError {
305
367
  static isInstance(error: unknown): error is UnsupportedFunctionalityError;
306
368
  }
307
369
 
308
- type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
309
- type JSONObject = {
310
- [key: string]: JSONValue;
311
- };
312
- type JSONArray = JSONValue[];
313
-
314
370
  type ImageModelV1CallOptions = {
315
371
  /**
316
372
  Prompt for the image generation.
@@ -441,138 +497,13 @@ declare function isJSONValue(value: unknown): value is JSONValue;
441
497
  declare function isJSONArray(value: unknown): value is JSONArray;
442
498
  declare function isJSONObject(value: unknown): value is JSONObject;
443
499
 
444
- /**
445
- * Additional provider-specific metadata. They are passed through
446
- * to the provider from the AI SDK and enable provider-specific
447
- * functionality that can be fully encapsulated in the provider.
448
- *
449
- * This enables us to quickly ship provider-specific functionality
450
- * without affecting the core AI SDK.
451
- *
452
- * The outer record is keyed by the provider name, and the inner
453
- * record is keyed by the provider-specific metadata key.
454
- *
455
- * ```ts
456
- * {
457
- * "anthropic": {
458
- * "cacheControl": { "type": "ephemeral" }
459
- * }
460
- * }
461
- * ```
462
- */
463
- type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>;
464
-
465
- /**
466
- * A source that has been used as input to generate the response.
467
- */
468
- type LanguageModelV1Source = {
469
- /**
470
- * A URL source. This is return by web search RAG models.
471
- */
472
- sourceType: 'url';
473
- /**
474
- * The ID of the source.
475
- */
476
- id: string;
477
- /**
478
- * The URL of the source.
479
- */
480
- url: string;
481
- /**
482
- * The title of the source.
483
- */
484
- title?: string;
485
- /**
486
- * Additional provider metadata for the source.
487
- */
488
- providerMetadata?: LanguageModelV1ProviderMetadata;
489
- };
490
-
491
- type LanguageModelV1CallSettings = {
492
- /**
493
- Maximum number of tokens to generate.
494
- */
495
- maxTokens?: number;
496
- /**
497
- Temperature setting.
498
-
499
- It is recommended to set either `temperature` or `topP`, but not both.
500
- */
501
- temperature?: number;
502
- /**
503
- Stop sequences.
504
- If set, the model will stop generating text when one of the stop sequences is generated.
505
- Providers may have limits on the number of stop sequences.
506
- */
507
- stopSequences?: string[];
508
- /**
509
- Nucleus sampling.
510
-
511
- It is recommended to set either `temperature` or `topP`, but not both.
512
- */
513
- topP?: number;
514
- /**
515
- Only sample from the top K options for each subsequent token.
516
-
517
- Used to remove "long tail" low probability responses.
518
- Recommended for advanced use cases only. You usually only need to use temperature.
519
- */
520
- topK?: number;
521
- /**
522
- Presence penalty setting. It affects the likelihood of the model to
523
- repeat information that is already in the prompt.
524
- */
525
- presencePenalty?: number;
526
- /**
527
- Frequency penalty setting. It affects the likelihood of the model
528
- to repeatedly use the same words or phrases.
529
- */
530
- frequencyPenalty?: number;
531
- /**
532
- Response format. The output can either be text or JSON. Default is text.
533
-
534
- If JSON is selected, a schema can optionally be provided to guide the LLM.
535
- */
536
- responseFormat?: {
537
- type: 'text';
538
- } | {
539
- type: 'json';
540
- /**
541
- * JSON schema that the generated output should conform to.
542
- */
543
- schema?: JSONSchema7;
544
- /**
545
- * Name of output that should be generated. Used by some providers for additional LLM guidance.
546
- */
547
- name?: string;
548
- /**
549
- * Description of the output that should be generated. Used by some providers for additional LLM guidance.
550
- */
551
- description?: string;
552
- };
553
- /**
554
- The seed (integer) to use for random sampling. If set and supported
555
- by the model, calls will generate deterministic results.
556
- */
557
- seed?: number;
558
- /**
559
- Abort signal for cancelling the operation.
560
- */
561
- abortSignal?: AbortSignal;
562
- /**
563
- Additional HTTP headers to be sent with the request.
564
- Only applicable for HTTP-based providers.
565
- */
566
- headers?: Record<string, string | undefined>;
567
- };
568
-
569
500
  /**
570
501
  A tool has a name, a description, and a set of parameters.
571
502
 
572
503
  Note: this is **not** the user-facing tool definition. The AI SDK methods will
573
504
  map the user-facing tool definitions to this format.
574
505
  */
575
- type LanguageModelV1FunctionTool = {
506
+ type LanguageModelV2FunctionTool = {
576
507
  /**
577
508
  The type of the tool (always 'function').
578
509
  */
@@ -593,6 +524,11 @@ type LanguageModelV1FunctionTool = {
593
524
  parameters: JSONSchema7;
594
525
  };
595
526
 
527
+ /**
528
+ Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
529
+ */
530
+ type LanguageModelV2DataContent = Uint8Array | string | URL;
531
+
596
532
  /**
597
533
  A prompt is a list of messages.
598
534
 
@@ -602,47 +538,47 @@ tool calls. The validation happens at runtime.
602
538
  Note: This is not a user-facing prompt. The AI SDK methods will map the
603
539
  user-facing prompt types such as chat or instruction prompts to this format.
604
540
  */
605
- type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
606
- type LanguageModelV1Message = ({
541
+ type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
542
+ type LanguageModelV2Message = ({
607
543
  role: 'system';
608
544
  content: string;
609
545
  } | {
610
546
  role: 'user';
611
- content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
547
+ content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
612
548
  } | {
613
549
  role: 'assistant';
614
- content: Array<LanguageModelV1TextPart | LanguageModelV1FilePart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
550
+ content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2RedactedReasoningPart | LanguageModelV2ToolCallPart>;
615
551
  } | {
616
552
  role: 'tool';
617
- content: Array<LanguageModelV1ToolResultPart>;
553
+ content: Array<LanguageModelV2ToolResultPart>;
618
554
  }) & {
619
555
  /**
620
- * Additional provider-specific metadata. They are passed through
556
+ * Additional provider-specific options. They are passed through
621
557
  * to the provider from the AI SDK and enable provider-specific
622
558
  * functionality that can be fully encapsulated in the provider.
623
559
  */
624
- providerMetadata?: LanguageModelV1ProviderMetadata;
560
+ providerOptions?: SharedV2ProviderOptions;
625
561
  };
626
562
  /**
627
563
  Text content part of a prompt. It contains a string of text.
628
564
  */
629
- interface LanguageModelV1TextPart {
565
+ interface LanguageModelV2TextPart {
630
566
  type: 'text';
631
567
  /**
632
568
  The text content.
633
569
  */
634
570
  text: string;
635
571
  /**
636
- * Additional provider-specific metadata. They are passed through
572
+ * Additional provider-specific options. They are passed through
637
573
  * to the provider from the AI SDK and enable provider-specific
638
574
  * functionality that can be fully encapsulated in the provider.
639
575
  */
640
- providerMetadata?: LanguageModelV1ProviderMetadata;
576
+ providerOptions?: SharedV2ProviderOptions;
641
577
  }
642
578
  /**
643
579
  Reasoning content part of a prompt. It contains a string of reasoning text.
644
580
  */
645
- interface LanguageModelV1ReasoningPart {
581
+ interface LanguageModelV2ReasoningPart {
646
582
  type: 'reasoning';
647
583
  /**
648
584
  The reasoning text.
@@ -653,76 +589,60 @@ interface LanguageModelV1ReasoningPart {
653
589
  */
654
590
  signature?: string;
655
591
  /**
656
- Additional provider-specific metadata. They are passed through
657
- to the provider from the AI SDK and enable provider-specific
658
- functionality that can be fully encapsulated in the provider.
592
+ * Additional provider-specific options. They are passed through
593
+ * to the provider from the AI SDK and enable provider-specific
594
+ * functionality that can be fully encapsulated in the provider.
659
595
  */
660
- providerMetadata?: LanguageModelV1ProviderMetadata;
596
+ providerOptions?: SharedV2ProviderOptions;
661
597
  }
662
598
  /**
663
599
  Redacted reasoning content part of a prompt.
664
600
  */
665
- interface LanguageModelV1RedactedReasoningPart {
601
+ interface LanguageModelV2RedactedReasoningPart {
666
602
  type: 'redacted-reasoning';
667
603
  /**
668
604
  Redacted reasoning data.
669
605
  */
670
606
  data: string;
671
607
  /**
672
- Additional provider-specific metadata. They are passed through
673
- to the provider from the AI SDK and enable provider-specific
674
- functionality that can be fully encapsulated in the provider.
608
+ * Additional provider-specific options. They are passed through
609
+ * to the provider from the AI SDK and enable provider-specific
610
+ * functionality that can be fully encapsulated in the provider.
675
611
  */
676
- providerMetadata?: LanguageModelV1ProviderMetadata;
612
+ providerOptions?: SharedV2ProviderOptions;
677
613
  }
678
614
  /**
679
- Image content part of a prompt. It contains an image.
615
+ File content part of a prompt. It contains a file.
680
616
  */
681
- interface LanguageModelV1ImagePart {
682
- type: 'image';
617
+ interface LanguageModelV2FilePart {
618
+ type: 'file';
683
619
  /**
684
- Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
620
+ * Optional filename of the file.
685
621
  */
686
- image: Uint8Array | URL;
622
+ filename?: string;
687
623
  /**
688
- Optional mime type of the image.
624
+ File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
625
+ */
626
+ data: LanguageModelV2DataContent;
627
+ /**
628
+ IANA media type of the file.
629
+
630
+ Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
631
+
632
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
689
633
  */
690
- mimeType?: string;
634
+ mediaType: string;
691
635
  /**
692
- * Additional provider-specific metadata. They are passed through
636
+ * Additional provider-specific options. They are passed through
693
637
  * to the provider from the AI SDK and enable provider-specific
694
638
  * functionality that can be fully encapsulated in the provider.
695
639
  */
696
- providerMetadata?: LanguageModelV1ProviderMetadata;
640
+ providerOptions?: SharedV2ProviderOptions;
697
641
  }
698
642
  /**
699
- File content part of a prompt. It contains a file.
643
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
700
644
  */
701
- interface LanguageModelV1FilePart {
702
- type: 'file';
703
- /**
704
- * Optional filename of the file.
705
- */
706
- filename?: string;
707
- /**
708
- File data as base64 encoded string or as a URL.
709
- */
710
- data: string | URL;
711
- /**
712
- Mime type of the file.
713
- */
714
- mimeType: string;
715
- /**
716
- * Additional provider-specific metadata. They are passed through
717
- * to the provider from the AI SDK and enable provider-specific
718
- * functionality that can be fully encapsulated in the provider.
719
- */
720
- providerMetadata?: LanguageModelV1ProviderMetadata;
721
- }
722
- /**
723
- Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
724
- */
725
- interface LanguageModelV1ToolCallPart {
645
+ interface LanguageModelV2ToolCallPart {
726
646
  type: 'tool-call';
727
647
  /**
728
648
  ID of the tool call. This ID is used to match the tool call with the tool result.
@@ -737,16 +657,16 @@ interface LanguageModelV1ToolCallPart {
737
657
  */
738
658
  args: unknown;
739
659
  /**
740
- * Additional provider-specific metadata. They are passed through
660
+ * Additional provider-specific options. They are passed through
741
661
  * to the provider from the AI SDK and enable provider-specific
742
662
  * functionality that can be fully encapsulated in the provider.
743
663
  */
744
- providerMetadata?: LanguageModelV1ProviderMetadata;
664
+ providerOptions?: SharedV2ProviderOptions;
745
665
  }
746
666
  /**
747
667
  Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
748
668
  */
749
- interface LanguageModelV1ToolResultPart {
669
+ interface LanguageModelV2ToolResultPart {
750
670
  type: 'tool-result';
751
671
  /**
752
672
  ID of the tool call that this result is associated with.
@@ -781,22 +701,24 @@ base-64 encoded image data
781
701
  */
782
702
  data: string;
783
703
  /**
784
- Mime type of the image.
704
+ IANA media type of the image.
705
+
706
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
785
707
  */
786
- mimeType?: string;
708
+ mediaType?: string;
787
709
  }>;
788
710
  /**
789
- * Additional provider-specific metadata. They are passed through
711
+ * Additional provider-specific options. They are passed through
790
712
  * to the provider from the AI SDK and enable provider-specific
791
713
  * functionality that can be fully encapsulated in the provider.
792
714
  */
793
- providerMetadata?: LanguageModelV1ProviderMetadata;
715
+ providerOptions?: SharedV2ProviderOptions;
794
716
  }
795
717
 
796
718
  /**
797
719
  The configuration of a tool that is defined by the provider.
798
720
  */
799
- type LanguageModelV1ProviderDefinedTool = {
721
+ type LanguageModelV2ProviderDefinedTool = {
800
722
  /**
801
723
  The type of the tool (always 'provider-defined').
802
724
  */
@@ -815,7 +737,7 @@ type LanguageModelV1ProviderDefinedTool = {
815
737
  args: Record<string, unknown>;
816
738
  };
817
739
 
818
- type LanguageModelV1ToolChoice = {
740
+ type LanguageModelV2ToolChoice = {
819
741
  type: 'auto';
820
742
  } | {
821
743
  type: 'none';
@@ -826,7 +748,7 @@ type LanguageModelV1ToolChoice = {
826
748
  toolName: string;
827
749
  };
828
750
 
829
- type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
751
+ type LanguageModelV2CallOptions = {
830
752
  /**
831
753
  Whether the user provided the input as messages or as
832
754
  a prompt. This can help guide non-chat models in the
@@ -835,29 +757,62 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
835
757
  */
836
758
  inputFormat: 'messages' | 'prompt';
837
759
  /**
838
- The mode affects the behavior of the language model. It is required to
839
- support provider-independent streaming and generation of structured objects.
840
- The model can take this information and e.g. configure json mode, the correct
841
- low level grammar, etc. It can also be used to optimize the efficiency of the
842
- streaming, e.g. tool-delta stream parts are only needed in the
843
- object-tool mode.
760
+ A language mode prompt is a standardized prompt type.
844
761
 
845
- @deprecated mode will be removed in v2.
846
- All necessary settings will be directly supported through the call settings,
847
- in particular responseFormat, toolChoice, and tools.
762
+ Note: This is **not** the user-facing prompt. The AI SDK methods will map the
763
+ user-facing prompt types such as chat or instruction prompts to this format.
764
+ That approach allows us to evolve the user facing prompts without breaking
765
+ the language model interface.
848
766
  */
849
- mode: {
850
- type: 'regular';
851
- /**
852
- The tools that are available for the model.
853
- */
854
- tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
855
- /**
856
- Specifies how the tool should be selected. Defaults to 'auto'.
857
- */
858
- toolChoice?: LanguageModelV1ToolChoice;
767
+ prompt: LanguageModelV2Prompt;
768
+ /**
769
+ Maximum number of tokens to generate.
770
+ */
771
+ maxOutputTokens?: number;
772
+ /**
773
+ Temperature setting.
774
+
775
+ It is recommended to set either `temperature` or `topP`, but not both.
776
+ */
777
+ temperature?: number;
778
+ /**
779
+ Stop sequences.
780
+ If set, the model will stop generating text when one of the stop sequences is generated.
781
+ Providers may have limits on the number of stop sequences.
782
+ */
783
+ stopSequences?: string[];
784
+ /**
785
+ Nucleus sampling.
786
+
787
+ It is recommended to set either `temperature` or `topP`, but not both.
788
+ */
789
+ topP?: number;
790
+ /**
791
+ Only sample from the top K options for each subsequent token.
792
+
793
+ Used to remove "long tail" low probability responses.
794
+ Recommended for advanced use cases only. You usually only need to use temperature.
795
+ */
796
+ topK?: number;
797
+ /**
798
+ Presence penalty setting. It affects the likelihood of the model to
799
+ repeat information that is already in the prompt.
800
+ */
801
+ presencePenalty?: number;
802
+ /**
803
+ Frequency penalty setting. It affects the likelihood of the model
804
+ to repeatedly use the same words or phrases.
805
+ */
806
+ frequencyPenalty?: number;
807
+ /**
808
+ Response format. The output can either be text or JSON. Default is text.
809
+
810
+ If JSON is selected, a schema can optionally be provided to guide the LLM.
811
+ */
812
+ responseFormat?: {
813
+ type: 'text';
859
814
  } | {
860
- type: 'object-json';
815
+ type: 'json';
861
816
  /**
862
817
  * JSON schema that the generated output should conform to.
863
818
  */
@@ -870,44 +825,76 @@ Specifies how the tool should be selected. Defaults to 'auto'.
870
825
  * Description of the output that should be generated. Used by some providers for additional LLM guidance.
871
826
  */
872
827
  description?: string;
873
- } | {
874
- type: 'object-tool';
875
- tool: LanguageModelV1FunctionTool;
876
828
  };
877
829
  /**
878
- A language mode prompt is a standardized prompt type.
879
-
880
- Note: This is **not** the user-facing prompt. The AI SDK methods will map the
881
- user-facing prompt types such as chat or instruction prompts to this format.
882
- That approach allows us to evolve the user facing prompts without breaking
883
- the language model interface.
884
- */
885
- prompt: LanguageModelV1Prompt;
830
+ The seed (integer) to use for random sampling. If set and supported
831
+ by the model, calls will generate deterministic results.
832
+ */
833
+ seed?: number;
886
834
  /**
887
- Additional provider-specific metadata.
888
- The metadata is passed through to the provider from the AI SDK and enables
889
- provider-specific functionality that can be fully encapsulated in the provider.
835
+ The tools that are available for the model.
836
+ */
837
+ tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
838
+ /**
839
+ Specifies how the tool should be selected. Defaults to 'auto'.
840
+ */
841
+ toolChoice?: LanguageModelV2ToolChoice;
842
+ /**
843
+ Abort signal for cancelling the operation.
844
+ */
845
+ abortSignal?: AbortSignal;
846
+ /**
847
+ Additional HTTP headers to be sent with the request.
848
+ Only applicable for HTTP-based providers.
849
+ */
850
+ headers?: Record<string, string | undefined>;
851
+ /**
852
+ * Additional provider-specific options. They are passed through
853
+ * to the provider from the AI SDK and enable provider-specific
854
+ * functionality that can be fully encapsulated in the provider.
890
855
  */
891
- providerMetadata?: LanguageModelV1ProviderMetadata;
856
+ providerOptions?: SharedV2ProviderOptions;
892
857
  };
893
858
 
894
859
  /**
895
860
  Warning from the model provider for this call. The call will proceed, but e.g.
896
861
  some settings might not be supported, which can lead to suboptimal results.
897
862
  */
898
- type LanguageModelV1CallWarning = {
863
+ type LanguageModelV2CallWarning = {
899
864
  type: 'unsupported-setting';
900
- setting: keyof LanguageModelV1CallSettings;
865
+ setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
901
866
  details?: string;
902
867
  } | {
903
868
  type: 'unsupported-tool';
904
- tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
869
+ tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
905
870
  details?: string;
906
871
  } | {
907
872
  type: 'other';
908
873
  message: string;
909
874
  };
910
875
 
876
+ /**
877
+ A file that has been generated by the model.
878
+ */
879
+ type LanguageModelV2File = {
880
+ type: 'file';
881
+ /**
882
+ The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
883
+
884
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
885
+ */
886
+ mediaType: string;
887
+ /**
888
+ Generated file data as base64 encoded strings or binary data.
889
+
890
+ The file data should be returned without any unnecessary conversion.
891
+ If the API returns base64 encoded strings, the file data should be returned
892
+ as base64 encoded strings. If the API returns binary data, the file data should
893
+ be returned as binary data.
894
+ */
895
+ data: string | Uint8Array;
896
+ };
897
+
911
898
  /**
912
899
  Reason why a language model finished generating a response.
913
900
 
@@ -920,23 +907,12 @@ Can be one of the following:
920
907
  - `other`: model stopped for other reasons
921
908
  - `unknown`: the model has not transmitted a finish reason
922
909
  */
923
- type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
924
-
925
- type LanguageModelV1FunctionToolCall = {
926
- toolCallType: 'function';
927
- toolCallId: string;
928
- toolName: string;
929
- /**
930
- Stringified JSON object with the tool call arguments. Must match the
931
- parameters schema of the tool.
932
- */
933
- args: string;
934
- };
910
+ type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
935
911
 
936
912
  /**
937
913
  Log probabilities for each token and its top log probabilities.
938
914
  */
939
- type LanguageModelV1LogProbs = Array<{
915
+ type LanguageModelV2LogProbs = Array<{
940
916
  token: string;
941
917
  logprob: number;
942
918
  topLogprobs: Array<{
@@ -945,59 +921,142 @@ type LanguageModelV1LogProbs = Array<{
945
921
  }>;
946
922
  }>;
947
923
 
924
+ type LanguageModelV2Reasoning = {
925
+ type: 'reasoning';
926
+ reasoningType: 'text';
927
+ text: string;
928
+ } | {
929
+ type: 'reasoning';
930
+ reasoningType: 'signature';
931
+ signature: string;
932
+ } | {
933
+ type: 'reasoning';
934
+ reasoningType: 'redacted';
935
+ data: string;
936
+ };
937
+
948
938
  /**
949
- Specification for a language model that implements the language model interface version 1.
939
+ * A source that has been used as input to generate the response.
950
940
  */
951
- type LanguageModelV1 = {
941
+ type LanguageModelV2Source = {
942
+ type: 'source';
952
943
  /**
953
- The language model must specify which language model interface
954
- version it implements. This will allow us to evolve the language
955
- model interface and retain backwards compatibility. The different
956
- implementation versions can be handled as a discriminated union
957
- on our side.
944
+ * A URL source. This is return by web search RAG models.
958
945
  */
959
- readonly specificationVersion: 'v1';
946
+ sourceType: 'url';
960
947
  /**
961
- Name of the provider for logging purposes.
948
+ * The ID of the source.
962
949
  */
963
- readonly provider: string;
950
+ id: string;
964
951
  /**
965
- Provider-specific model ID for logging purposes.
952
+ * The URL of the source.
966
953
  */
967
- readonly modelId: string;
954
+ url: string;
968
955
  /**
969
- Default object generation mode that should be used with this model when
970
- no mode is specified. Should be the mode with the best results for this
971
- model. `undefined` can be returned if object generation is not supported.
972
-
973
- This is needed to generate the best objects possible w/o requiring the
974
- user to explicitly specify the object generation mode.
956
+ * The title of the source.
975
957
  */
976
- readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
958
+ title?: string;
977
959
  /**
978
- Flag whether this model supports image URLs. Default is `true`.
979
-
980
- When the flag is set to `false`, the AI SDK will download the image and
981
- pass the image data to the model.
960
+ * Additional provider metadata for the source.
982
961
  */
983
- readonly supportsImageUrls?: boolean;
962
+ providerMetadata?: SharedV2ProviderMetadata;
963
+ };
964
+
965
+ type LanguageModelV2Text = {
966
+ type: 'text';
984
967
  /**
985
- Flag whether this model supports grammar-guided generation,
986
- i.e. follows JSON schemas for object generation
987
- when the response format is set to 'json' or
988
- when the `object-json` mode is used.
989
-
990
- This means that the model guarantees that the generated JSON
991
- will be a valid JSON object AND that the object will match the
992
- JSON schema.
993
-
994
- Please note that `generateObject` and `streamObject` will work
995
- regardless of this flag, but might send different prompts and
996
- use further optimizations if this flag is set to `true`.
997
-
998
- Defaults to `false`.
999
- */
1000
- readonly supportsStructuredOutputs?: boolean;
968
+ The text content.
969
+ */
970
+ text: string;
971
+ };
972
+
973
+ type LanguageModelV2ToolCall = {
974
+ type: 'tool-call';
975
+ toolCallType: 'function';
976
+ toolCallId: string;
977
+ toolName: string;
978
+ /**
979
+ Stringified JSON object with the tool call arguments. Must match the
980
+ parameters schema of the tool.
981
+ */
982
+ args: string;
983
+ };
984
+
985
+ type LanguageModelV2ToolCallDelta = {
986
+ type: 'tool-call-delta';
987
+ toolCallType: 'function';
988
+ toolCallId: string;
989
+ toolName: string;
990
+ argsTextDelta: string;
991
+ };
992
+
993
+ /**
994
+ * Usage information for a language model call.
995
+ */
996
+ type LanguageModelV2Usage = {
997
+ /**
998
+ * The number of input (prompt) tokens used.
999
+ */
1000
+ inputTokens: number | undefined;
1001
+ /**
1002
+ * The number of output (completion) tokens used.
1003
+ */
1004
+ outputTokens: number | undefined;
1005
+ };
1006
+
1007
+ /**
1008
+ Specification for a language model that implements the language model interface version 2.
1009
+ */
1010
+ type LanguageModelV2 = {
1011
+ /**
1012
+ The language model must specify which language model interface
1013
+ version it implements. This will allow us to evolve the language
1014
+ model interface and retain backwards compatibility. The different
1015
+ implementation versions can be handled as a discriminated union
1016
+ on our side.
1017
+ */
1018
+ readonly specificationVersion: 'v2';
1019
+ /**
1020
+ Name of the provider for logging purposes.
1021
+ */
1022
+ readonly provider: string;
1023
+ /**
1024
+ Provider-specific model ID for logging purposes.
1025
+ */
1026
+ readonly modelId: string;
1027
+ /**
1028
+ Default object generation mode that should be used with this model when
1029
+ no mode is specified. Should be the mode with the best results for this
1030
+ model. `undefined` can be returned if object generation is not supported.
1031
+
1032
+ This is needed to generate the best objects possible w/o requiring the
1033
+ user to explicitly specify the object generation mode.
1034
+ */
1035
+ readonly defaultObjectGenerationMode: LanguageModelV2ObjectGenerationMode;
1036
+ /**
1037
+ Flag whether this model supports image URLs. Default is `true`.
1038
+
1039
+ When the flag is set to `false`, the AI SDK will download the image and
1040
+ pass the image data to the model.
1041
+ */
1042
+ readonly supportsImageUrls?: boolean;
1043
+ /**
1044
+ Flag whether this model supports grammar-guided generation,
1045
+ i.e. follows JSON schemas for object generation
1046
+ when the response format is set to 'json' or
1047
+ when the `object-json` mode is used.
1048
+
1049
+ This means that the model guarantees that the generated JSON
1050
+ will be a valid JSON object AND that the object will match the
1051
+ JSON schema.
1052
+
1053
+ Please note that `generateObject` and `streamObject` will work
1054
+ regardless of this flag, but might send different prompts and
1055
+ use further optimizations if this flag is set to `true`.
1056
+
1057
+ Defaults to `false`.
1058
+ */
1059
+ readonly supportsStructuredOutputs?: boolean;
1001
1060
  /**
1002
1061
  Checks if the model supports the given URL for file parts natively.
1003
1062
  If the model does not support the URL,
@@ -1012,91 +1071,60 @@ type LanguageModelV1 = {
1012
1071
  Naming: "do" prefix to prevent accidental direct usage of the method
1013
1072
  by the user.
1014
1073
  */
1015
- doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
1074
+ doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
1016
1075
  /**
1017
1076
  Text that the model has generated.
1018
1077
  Can be undefined if the model did not generate any text.
1019
1078
  */
1020
- text?: string;
1079
+ text?: LanguageModelV2Text;
1021
1080
  /**
1022
1081
  Reasoning that the model has generated.
1023
1082
  Can be undefined if the model does not support reasoning.
1024
1083
  */
1025
- reasoning?: string | Array<{
1026
- type: 'text';
1027
- text: string;
1028
- /**
1029
- An optional signature for verifying that the reasoning originated from the model.
1030
- */
1031
- signature?: string;
1032
- } | {
1033
- type: 'redacted';
1034
- data: string;
1035
- }>;
1084
+ reasoning?: Array<LanguageModelV2Reasoning>;
1036
1085
  /**
1037
1086
  Generated files as base64 encoded strings or binary data.
1038
1087
  The files should be returned without any unnecessary conversion.
1039
- If the API returns base64 encoded strings, the files should be returned
1040
- as base64 encoded strings. If the API returns binary data, the files should
1041
- be returned as binary data.
1042
1088
  */
1043
- files?: Array<{
1044
- data: string | Uint8Array;
1045
- mimeType: string;
1046
- }>;
1089
+ files?: Array<LanguageModelV2File>;
1090
+ /**
1091
+ Sources that have been used as input to generate the response.
1092
+ */
1093
+ sources?: LanguageModelV2Source[];
1047
1094
  /**
1048
1095
  Tool calls that the model has generated.
1049
1096
  Can be undefined if the model did not generate any tool calls.
1050
1097
  */
1051
- toolCalls?: Array<LanguageModelV1FunctionToolCall>;
1098
+ toolCalls?: Array<LanguageModelV2ToolCall>;
1099
+ /**
1100
+ Logprobs for the completion.
1101
+ `undefined` if the mode does not support logprobs or if was not enabled
1102
+
1103
+ @deprecated will be changed into a provider-specific extension in v2
1104
+ */
1105
+ logprobs?: LanguageModelV2LogProbs;
1052
1106
  /**
1053
1107
  Finish reason.
1054
1108
  */
1055
- finishReason: LanguageModelV1FinishReason;
1109
+ finishReason: LanguageModelV2FinishReason;
1056
1110
  /**
1057
1111
  Usage information.
1058
1112
  */
1059
- usage: {
1060
- promptTokens: number;
1061
- completionTokens: number;
1062
- };
1063
- /**
1064
- Raw prompt and setting information for observability provider integration.
1065
- */
1066
- rawCall: {
1067
- /**
1068
- Raw prompt after expansion and conversion to the format that the
1069
- provider uses to send the information to their API.
1070
- */
1071
- rawPrompt: unknown;
1072
- /**
1073
- Raw settings that are used for the API call. Includes provider-specific
1074
- settings.
1075
- */
1076
- rawSettings: Record<string, unknown>;
1077
- };
1113
+ usage: LanguageModelV2Usage;
1078
1114
  /**
1079
- Optional response information for telemetry and debugging purposes.
1115
+ Additional provider-specific metadata. They are passed through
1116
+ from the provider to the AI SDK and enable provider-specific
1117
+ results that can be fully encapsulated in the provider.
1080
1118
  */
1081
- rawResponse?: {
1082
- /**
1083
- Response headers.
1084
- */
1085
- headers?: Record<string, string>;
1086
- /**
1087
- Response body.
1088
- */
1089
- body?: unknown;
1090
- };
1119
+ providerMetadata?: SharedV2ProviderMetadata;
1091
1120
  /**
1092
1121
  Optional request information for telemetry and debugging purposes.
1093
1122
  */
1094
1123
  request?: {
1095
1124
  /**
1096
- Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1097
- Non-HTTP(s) providers should not set this.
1125
+ Request HTTP body that was sent to the provider API.
1098
1126
  */
1099
- body?: string;
1127
+ body?: unknown;
1100
1128
  };
1101
1129
  /**
1102
1130
  Optional response information for telemetry and debugging purposes.
@@ -1114,25 +1142,19 @@ An optional signature for verifying that the reasoning originated from the model
1114
1142
  The ID of the response model that was used to generate the response, if the provider sends one.
1115
1143
  */
1116
1144
  modelId?: string;
1145
+ /**
1146
+ Response headers.
1147
+ */
1148
+ headers?: Record<string, string>;
1149
+ /**
1150
+ Response HTTP body.
1151
+ */
1152
+ body?: unknown;
1117
1153
  };
1118
- warnings?: LanguageModelV1CallWarning[];
1119
- /**
1120
- Additional provider-specific metadata. They are passed through
1121
- from the provider to the AI SDK and enable provider-specific
1122
- results that can be fully encapsulated in the provider.
1123
- */
1124
- providerMetadata?: LanguageModelV1ProviderMetadata;
1125
1154
  /**
1126
- Sources that have been used as input to generate the response.
1127
- */
1128
- sources?: LanguageModelV1Source[];
1129
- /**
1130
- Logprobs for the completion.
1131
- `undefined` if the mode does not support logprobs or if was not enabled
1132
-
1133
- @deprecated will be changed into a provider-specific extension in v2
1155
+ Warnings for the call, e.g. unsupported settings.
1134
1156
  */
1135
- logprobs?: LanguageModelV1LogProbs;
1157
+ warnings?: LanguageModelV2CallWarning[];
1136
1158
  }>;
1137
1159
  /**
1138
1160
  Generates a language model output (streaming).
@@ -1142,105 +1164,233 @@ An optional signature for verifying that the reasoning originated from the model
1142
1164
  *
1143
1165
  @return A stream of higher-level language model output parts.
1144
1166
  */
1145
- doStream(options: LanguageModelV1CallOptions): PromiseLike<{
1146
- stream: ReadableStream<LanguageModelV1StreamPart>;
1167
+ doStream(options: LanguageModelV2CallOptions): PromiseLike<{
1168
+ stream: ReadableStream<LanguageModelV2StreamPart>;
1147
1169
  /**
1148
- Raw prompt and setting information for observability provider integration.
1170
+ Optional request information for telemetry and debugging purposes.
1149
1171
  */
1150
- rawCall: {
1151
- /**
1152
- Raw prompt after expansion and conversion to the format that the
1153
- provider uses to send the information to their API.
1154
- */
1155
- rawPrompt: unknown;
1172
+ request?: {
1156
1173
  /**
1157
- Raw settings that are used for the API call. Includes provider-specific
1158
- settings.
1159
- */
1160
- rawSettings: Record<string, unknown>;
1174
+ Request HTTP body that was sent to the provider API.
1175
+ */
1176
+ body?: unknown;
1161
1177
  };
1162
1178
  /**
1163
- Optional raw response data.
1179
+ Optional response data.
1164
1180
  */
1165
- rawResponse?: {
1181
+ response?: {
1166
1182
  /**
1167
1183
  Response headers.
1168
1184
  */
1169
1185
  headers?: Record<string, string>;
1170
1186
  };
1171
1187
  /**
1172
- Optional request information for telemetry and debugging purposes.
1173
- */
1174
- request?: {
1175
- /**
1176
- Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1177
- Non-HTTP(s) providers should not set this.
1178
- */
1179
- body?: string;
1180
- };
1181
- /**
1182
1188
  Warnings for the call, e.g. unsupported settings.
1183
1189
  */
1184
- warnings?: Array<LanguageModelV1CallWarning>;
1190
+ warnings?: Array<LanguageModelV2CallWarning>;
1185
1191
  }>;
1186
1192
  };
1187
- type LanguageModelV1StreamPart = {
1188
- type: 'text-delta';
1189
- textDelta: string;
1190
- } | {
1191
- type: 'reasoning';
1192
- textDelta: string;
1193
- } | {
1194
- type: 'reasoning-signature';
1195
- signature: string;
1196
- } | {
1197
- type: 'redacted-reasoning';
1198
- data: string;
1193
+ type LanguageModelV2StreamPart = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2Source | LanguageModelV2File | LanguageModelV2ToolCall | LanguageModelV2ToolCallDelta | {
1194
+ type: 'response-metadata';
1195
+ id?: string;
1196
+ timestamp?: Date;
1197
+ modelId?: string;
1199
1198
  } | {
1200
- type: 'source';
1201
- source: LanguageModelV1Source;
1199
+ type: 'finish';
1200
+ finishReason: LanguageModelV2FinishReason;
1201
+ providerMetadata?: SharedV2ProviderMetadata;
1202
+ usage: LanguageModelV2Usage;
1203
+ logprobs?: LanguageModelV2LogProbs;
1202
1204
  } | {
1203
- type: 'file';
1204
- mimeType: string;
1205
+ type: 'error';
1206
+ error: unknown;
1207
+ };
1208
+ /**
1209
+ The object generation modes available for use with a model. `undefined`
1210
+ represents no support for object generation.
1211
+ */
1212
+ type LanguageModelV2ObjectGenerationMode = 'json' | 'tool' | undefined;
1213
+
1214
+ /**
1215
+ * Experimental middleware for LanguageModelV2.
1216
+ * This type defines the structure for middleware that can be used to modify
1217
+ * the behavior of LanguageModelV2 operations.
1218
+ */
1219
+ type LanguageModelV2Middleware = {
1220
+ /**
1221
+ * Middleware specification version. Use `v2` for the current version.
1222
+ */
1223
+ middlewareVersion?: 'v2' | undefined;
1224
+ /**
1225
+ * Transforms the parameters before they are passed to the language model.
1226
+ * @param options - Object containing the type of operation and the parameters.
1227
+ * @param options.type - The type of operation ('generate' or 'stream').
1228
+ * @param options.params - The original parameters for the language model call.
1229
+ * @returns A promise that resolves to the transformed parameters.
1230
+ */
1231
+ transformParams?: (options: {
1232
+ type: 'generate' | 'stream';
1233
+ params: LanguageModelV2CallOptions;
1234
+ }) => PromiseLike<LanguageModelV2CallOptions>;
1235
+ /**
1236
+ * Wraps the generate operation of the language model.
1237
+ * @param options - Object containing the generate function, parameters, and model.
1238
+ * @param options.doGenerate - The original generate function.
1239
+ * @param options.doStream - The original stream function.
1240
+ * @param options.params - The parameters for the generate call. If the
1241
+ * `transformParams` middleware is used, this will be the transformed parameters.
1242
+ * @param options.model - The language model instance.
1243
+ * @returns A promise that resolves to the result of the generate operation.
1244
+ */
1245
+ wrapGenerate?: (options: {
1246
+ doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
1247
+ doStream: () => ReturnType<LanguageModelV2['doStream']>;
1248
+ params: LanguageModelV2CallOptions;
1249
+ model: LanguageModelV2;
1250
+ }) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
1251
+ /**
1252
+ * Wraps the stream operation of the language model.
1253
+ *
1254
+ * @param options - Object containing the stream function, parameters, and model.
1255
+ * @param options.doGenerate - The original generate function.
1256
+ * @param options.doStream - The original stream function.
1257
+ * @param options.params - The parameters for the stream call. If the
1258
+ * `transformParams` middleware is used, this will be the transformed parameters.
1259
+ * @param options.model - The language model instance.
1260
+ * @returns A promise that resolves to the result of the stream operation.
1261
+ */
1262
+ wrapStream?: (options: {
1263
+ doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
1264
+ doStream: () => ReturnType<LanguageModelV2['doStream']>;
1265
+ params: LanguageModelV2CallOptions;
1266
+ model: LanguageModelV2;
1267
+ }) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
1268
+ };
1269
+
1270
+ /**
1271
+ * Additional provider-specific metadata. They are passed through
1272
+ * to the provider from the AI SDK and enable provider-specific
1273
+ * functionality that can be fully encapsulated in the provider.
1274
+ *
1275
+ * This enables us to quickly ship provider-specific functionality
1276
+ * without affecting the core AI SDK.
1277
+ *
1278
+ * The outer record is keyed by the provider name, and the inner
1279
+ * record is keyed by the provider-specific metadata key.
1280
+ *
1281
+ * ```ts
1282
+ * {
1283
+ * "anthropic": {
1284
+ * "cacheControl": { "type": "ephemeral" }
1285
+ * }
1286
+ * }
1287
+ * ```
1288
+ */
1289
+ type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>;
1290
+
1291
+ /**
1292
+ * A source that has been used as input to generate the response.
1293
+ */
1294
+ type LanguageModelV1Source = {
1295
+ /**
1296
+ * A URL source. This is return by web search RAG models.
1297
+ */
1298
+ sourceType: 'url';
1299
+ /**
1300
+ * The ID of the source.
1301
+ */
1302
+ id: string;
1303
+ /**
1304
+ * The URL of the source.
1305
+ */
1306
+ url: string;
1307
+ /**
1308
+ * The title of the source.
1309
+ */
1310
+ title?: string;
1311
+ /**
1312
+ * Additional provider metadata for the source.
1313
+ */
1314
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1315
+ };
1316
+
1317
+ type LanguageModelV1CallSettings = {
1318
+ /**
1319
+ Maximum number of tokens to generate.
1320
+ */
1321
+ maxTokens?: number;
1322
+ /**
1323
+ Temperature setting.
1324
+
1325
+ It is recommended to set either `temperature` or `topP`, but not both.
1326
+ */
1327
+ temperature?: number;
1328
+ /**
1329
+ Stop sequences.
1330
+ If set, the model will stop generating text when one of the stop sequences is generated.
1331
+ Providers may have limits on the number of stop sequences.
1332
+ */
1333
+ stopSequences?: string[];
1334
+ /**
1335
+ Nucleus sampling.
1336
+
1337
+ It is recommended to set either `temperature` or `topP`, but not both.
1338
+ */
1339
+ topP?: number;
1340
+ /**
1341
+ Only sample from the top K options for each subsequent token.
1342
+
1343
+ Used to remove "long tail" low probability responses.
1344
+ Recommended for advanced use cases only. You usually only need to use temperature.
1345
+ */
1346
+ topK?: number;
1347
+ /**
1348
+ Presence penalty setting. It affects the likelihood of the model to
1349
+ repeat information that is already in the prompt.
1350
+ */
1351
+ presencePenalty?: number;
1352
+ /**
1353
+ Frequency penalty setting. It affects the likelihood of the model
1354
+ to repeatedly use the same words or phrases.
1355
+ */
1356
+ frequencyPenalty?: number;
1357
+ /**
1358
+ Response format. The output can either be text or JSON. Default is text.
1359
+
1360
+ If JSON is selected, a schema can optionally be provided to guide the LLM.
1361
+ */
1362
+ responseFormat?: {
1363
+ type: 'text';
1364
+ } | {
1365
+ type: 'json';
1366
+ /**
1367
+ * JSON schema that the generated output should conform to.
1368
+ */
1369
+ schema?: JSONSchema7;
1370
+ /**
1371
+ * Name of output that should be generated. Used by some providers for additional LLM guidance.
1372
+ */
1373
+ name?: string;
1374
+ /**
1375
+ * Description of the output that should be generated. Used by some providers for additional LLM guidance.
1376
+ */
1377
+ description?: string;
1378
+ };
1205
1379
  /**
1206
- Generated file data as base64 encoded strings or binary data.
1207
- The file data should be returned without any unnecessary conversion.
1208
- If the API returns base64 encoded strings, the file data should be returned
1209
- as base64 encoded strings. If the API returns binary data, the file data should
1210
- be returned as binary data.
1380
+ The seed (integer) to use for random sampling. If set and supported
1381
+ by the model, calls will generate deterministic results.
1211
1382
  */
1212
- data: string | Uint8Array;
1213
- } | ({
1214
- type: 'tool-call';
1215
- } & LanguageModelV1FunctionToolCall) | {
1216
- type: 'tool-call-delta';
1217
- toolCallType: 'function';
1218
- toolCallId: string;
1219
- toolName: string;
1220
- argsTextDelta: string;
1221
- } | {
1222
- type: 'response-metadata';
1223
- id?: string;
1224
- timestamp?: Date;
1225
- modelId?: string;
1226
- } | {
1227
- type: 'finish';
1228
- finishReason: LanguageModelV1FinishReason;
1229
- providerMetadata?: LanguageModelV1ProviderMetadata;
1230
- usage: {
1231
- promptTokens: number;
1232
- completionTokens: number;
1233
- };
1234
- logprobs?: LanguageModelV1LogProbs;
1235
- } | {
1236
- type: 'error';
1237
- error: unknown;
1383
+ seed?: number;
1384
+ /**
1385
+ Abort signal for cancelling the operation.
1386
+ */
1387
+ abortSignal?: AbortSignal;
1388
+ /**
1389
+ Additional HTTP headers to be sent with the request.
1390
+ Only applicable for HTTP-based providers.
1391
+ */
1392
+ headers?: Record<string, string | undefined>;
1238
1393
  };
1239
- /**
1240
- The object generation modes available for use with a model. `undefined`
1241
- represents no support for object generation.
1242
- */
1243
- type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
1244
1394
 
1245
1395
  /**
1246
1396
  A tool has a name, a description, and a set of parameters.
@@ -1248,7 +1398,7 @@ A tool has a name, a description, and a set of parameters.
1248
1398
  Note: this is **not** the user-facing tool definition. The AI SDK methods will
1249
1399
  map the user-facing tool definitions to this format.
1250
1400
  */
1251
- type LanguageModelV2FunctionTool = {
1401
+ type LanguageModelV1FunctionTool = {
1252
1402
  /**
1253
1403
  The type of the tool (always 'function').
1254
1404
  */
@@ -1269,29 +1419,6 @@ type LanguageModelV2FunctionTool = {
1269
1419
  parameters: JSONSchema7;
1270
1420
  };
1271
1421
 
1272
- /**
1273
- * Additional provider-specific options.
1274
- * Options are additional input to the provider.
1275
- * They are passed through to the provider from the AI SDK
1276
- * and enable provider-specific functionality
1277
- * that can be fully encapsulated in the provider.
1278
- *
1279
- * This enables us to quickly ship provider-specific functionality
1280
- * without affecting the core AI SDK.
1281
- *
1282
- * The outer record is keyed by the provider name, and the inner
1283
- * record is keyed by the provider-specific metadata key.
1284
- *
1285
- * ```ts
1286
- * {
1287
- * "anthropic": {
1288
- * "cacheControl": { "type": "ephemeral" }
1289
- * }
1290
- * }
1291
- * ```
1292
- */
1293
- type LanguageModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
1294
-
1295
1422
  /**
1296
1423
  A prompt is a list of messages.
1297
1424
 
@@ -1301,47 +1428,47 @@ tool calls. The validation happens at runtime.
1301
1428
  Note: This is not a user-facing prompt. The AI SDK methods will map the
1302
1429
  user-facing prompt types such as chat or instruction prompts to this format.
1303
1430
  */
1304
- type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
1305
- type LanguageModelV2Message = ({
1431
+ type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
1432
+ type LanguageModelV1Message = ({
1306
1433
  role: 'system';
1307
1434
  content: string;
1308
1435
  } | {
1309
1436
  role: 'user';
1310
- content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
1437
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
1311
1438
  } | {
1312
1439
  role: 'assistant';
1313
- content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2RedactedReasoningPart | LanguageModelV2ToolCallPart>;
1440
+ content: Array<LanguageModelV1TextPart | LanguageModelV1FilePart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
1314
1441
  } | {
1315
1442
  role: 'tool';
1316
- content: Array<LanguageModelV2ToolResultPart>;
1443
+ content: Array<LanguageModelV1ToolResultPart>;
1317
1444
  }) & {
1318
1445
  /**
1319
- * Additional provider-specific options. They are passed through
1446
+ * Additional provider-specific metadata. They are passed through
1320
1447
  * to the provider from the AI SDK and enable provider-specific
1321
1448
  * functionality that can be fully encapsulated in the provider.
1322
1449
  */
1323
- providerOptions?: LanguageModelV2ProviderOptions;
1450
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1324
1451
  };
1325
1452
  /**
1326
1453
  Text content part of a prompt. It contains a string of text.
1327
1454
  */
1328
- interface LanguageModelV2TextPart {
1455
+ interface LanguageModelV1TextPart {
1329
1456
  type: 'text';
1330
1457
  /**
1331
1458
  The text content.
1332
1459
  */
1333
1460
  text: string;
1334
1461
  /**
1335
- * Additional provider-specific options. They are passed through
1462
+ * Additional provider-specific metadata. They are passed through
1336
1463
  * to the provider from the AI SDK and enable provider-specific
1337
1464
  * functionality that can be fully encapsulated in the provider.
1338
1465
  */
1339
- providerOptions?: LanguageModelV2ProviderOptions;
1466
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1340
1467
  }
1341
1468
  /**
1342
1469
  Reasoning content part of a prompt. It contains a string of reasoning text.
1343
1470
  */
1344
- interface LanguageModelV2ReasoningPart {
1471
+ interface LanguageModelV1ReasoningPart {
1345
1472
  type: 'reasoning';
1346
1473
  /**
1347
1474
  The reasoning text.
@@ -1352,32 +1479,52 @@ interface LanguageModelV2ReasoningPart {
1352
1479
  */
1353
1480
  signature?: string;
1354
1481
  /**
1355
- * Additional provider-specific options. They are passed through
1356
- * to the provider from the AI SDK and enable provider-specific
1357
- * functionality that can be fully encapsulated in the provider.
1482
+ Additional provider-specific metadata. They are passed through
1483
+ to the provider from the AI SDK and enable provider-specific
1484
+ functionality that can be fully encapsulated in the provider.
1358
1485
  */
1359
- providerOptions?: LanguageModelV2ProviderOptions;
1486
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1360
1487
  }
1361
1488
  /**
1362
1489
  Redacted reasoning content part of a prompt.
1363
1490
  */
1364
- interface LanguageModelV2RedactedReasoningPart {
1491
+ interface LanguageModelV1RedactedReasoningPart {
1365
1492
  type: 'redacted-reasoning';
1366
1493
  /**
1367
1494
  Redacted reasoning data.
1368
1495
  */
1369
1496
  data: string;
1370
1497
  /**
1371
- * Additional provider-specific options. They are passed through
1498
+ Additional provider-specific metadata. They are passed through
1499
+ to the provider from the AI SDK and enable provider-specific
1500
+ functionality that can be fully encapsulated in the provider.
1501
+ */
1502
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1503
+ }
1504
+ /**
1505
+ Image content part of a prompt. It contains an image.
1506
+ */
1507
+ interface LanguageModelV1ImagePart {
1508
+ type: 'image';
1509
+ /**
1510
+ Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
1511
+ */
1512
+ image: Uint8Array | URL;
1513
+ /**
1514
+ Optional mime type of the image.
1515
+ */
1516
+ mimeType?: string;
1517
+ /**
1518
+ * Additional provider-specific metadata. They are passed through
1372
1519
  * to the provider from the AI SDK and enable provider-specific
1373
1520
  * functionality that can be fully encapsulated in the provider.
1374
1521
  */
1375
- providerOptions?: LanguageModelV2ProviderOptions;
1522
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1376
1523
  }
1377
1524
  /**
1378
1525
  File content part of a prompt. It contains a file.
1379
1526
  */
1380
- interface LanguageModelV2FilePart {
1527
+ interface LanguageModelV1FilePart {
1381
1528
  type: 'file';
1382
1529
  /**
1383
1530
  * Optional filename of the file.
@@ -1388,24 +1535,20 @@ interface LanguageModelV2FilePart {
1388
1535
  */
1389
1536
  data: string | URL;
1390
1537
  /**
1391
- IANA media type of the file.
1392
-
1393
- Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
1394
-
1395
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1538
+ Mime type of the file.
1396
1539
  */
1397
- mediaType: string;
1540
+ mimeType: string;
1398
1541
  /**
1399
- * Additional provider-specific options. They are passed through
1542
+ * Additional provider-specific metadata. They are passed through
1400
1543
  * to the provider from the AI SDK and enable provider-specific
1401
1544
  * functionality that can be fully encapsulated in the provider.
1402
1545
  */
1403
- providerOptions?: LanguageModelV2ProviderOptions;
1546
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1404
1547
  }
1405
1548
  /**
1406
1549
  Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
1407
1550
  */
1408
- interface LanguageModelV2ToolCallPart {
1551
+ interface LanguageModelV1ToolCallPart {
1409
1552
  type: 'tool-call';
1410
1553
  /**
1411
1554
  ID of the tool call. This ID is used to match the tool call with the tool result.
@@ -1420,16 +1563,16 @@ interface LanguageModelV2ToolCallPart {
1420
1563
  */
1421
1564
  args: unknown;
1422
1565
  /**
1423
- * Additional provider-specific options. They are passed through
1566
+ * Additional provider-specific metadata. They are passed through
1424
1567
  * to the provider from the AI SDK and enable provider-specific
1425
1568
  * functionality that can be fully encapsulated in the provider.
1426
1569
  */
1427
- providerOptions?: LanguageModelV2ProviderOptions;
1570
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1428
1571
  }
1429
1572
  /**
1430
1573
  Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
1431
1574
  */
1432
- interface LanguageModelV2ToolResultPart {
1575
+ interface LanguageModelV1ToolResultPart {
1433
1576
  type: 'tool-result';
1434
1577
  /**
1435
1578
  ID of the tool call that this result is associated with.
@@ -1464,24 +1607,22 @@ base-64 encoded image data
1464
1607
  */
1465
1608
  data: string;
1466
1609
  /**
1467
- IANA media type of the image.
1468
-
1469
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1610
+ Mime type of the image.
1470
1611
  */
1471
- mediaType?: string;
1612
+ mimeType?: string;
1472
1613
  }>;
1473
1614
  /**
1474
- * Additional provider-specific options. They are passed through
1615
+ * Additional provider-specific metadata. They are passed through
1475
1616
  * to the provider from the AI SDK and enable provider-specific
1476
1617
  * functionality that can be fully encapsulated in the provider.
1477
1618
  */
1478
- providerOptions?: LanguageModelV2ProviderOptions;
1619
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1479
1620
  }
1480
1621
 
1481
1622
  /**
1482
1623
  The configuration of a tool that is defined by the provider.
1483
1624
  */
1484
- type LanguageModelV2ProviderDefinedTool = {
1625
+ type LanguageModelV1ProviderDefinedTool = {
1485
1626
  /**
1486
1627
  The type of the tool (always 'provider-defined').
1487
1628
  */
@@ -1500,7 +1641,7 @@ type LanguageModelV2ProviderDefinedTool = {
1500
1641
  args: Record<string, unknown>;
1501
1642
  };
1502
1643
 
1503
- type LanguageModelV2ToolChoice = {
1644
+ type LanguageModelV1ToolChoice = {
1504
1645
  type: 'auto';
1505
1646
  } | {
1506
1647
  type: 'none';
@@ -1511,7 +1652,7 @@ type LanguageModelV2ToolChoice = {
1511
1652
  toolName: string;
1512
1653
  };
1513
1654
 
1514
- type LanguageModelV2CallOptions = {
1655
+ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
1515
1656
  /**
1516
1657
  Whether the user provided the input as messages or as
1517
1658
  a prompt. This can help guide non-chat models in the
@@ -1520,62 +1661,29 @@ type LanguageModelV2CallOptions = {
1520
1661
  */
1521
1662
  inputFormat: 'messages' | 'prompt';
1522
1663
  /**
1523
- A language mode prompt is a standardized prompt type.
1664
+ The mode affects the behavior of the language model. It is required to
1665
+ support provider-independent streaming and generation of structured objects.
1666
+ The model can take this information and e.g. configure json mode, the correct
1667
+ low level grammar, etc. It can also be used to optimize the efficiency of the
1668
+ streaming, e.g. tool-delta stream parts are only needed in the
1669
+ object-tool mode.
1524
1670
 
1525
- Note: This is **not** the user-facing prompt. The AI SDK methods will map the
1526
- user-facing prompt types such as chat or instruction prompts to this format.
1527
- That approach allows us to evolve the user facing prompts without breaking
1528
- the language model interface.
1529
- */
1530
- prompt: LanguageModelV2Prompt;
1531
- /**
1532
- Maximum number of tokens to generate.
1671
+ @deprecated mode will be removed in v2.
1672
+ All necessary settings will be directly supported through the call settings,
1673
+ in particular responseFormat, toolChoice, and tools.
1533
1674
  */
1534
- maxTokens?: number;
1535
- /**
1536
- Temperature setting.
1537
-
1538
- It is recommended to set either `temperature` or `topP`, but not both.
1539
- */
1540
- temperature?: number;
1541
- /**
1542
- Stop sequences.
1543
- If set, the model will stop generating text when one of the stop sequences is generated.
1544
- Providers may have limits on the number of stop sequences.
1545
- */
1546
- stopSequences?: string[];
1547
- /**
1548
- Nucleus sampling.
1549
-
1550
- It is recommended to set either `temperature` or `topP`, but not both.
1551
- */
1552
- topP?: number;
1553
- /**
1554
- Only sample from the top K options for each subsequent token.
1555
-
1556
- Used to remove "long tail" low probability responses.
1557
- Recommended for advanced use cases only. You usually only need to use temperature.
1558
- */
1559
- topK?: number;
1560
- /**
1561
- Presence penalty setting. It affects the likelihood of the model to
1562
- repeat information that is already in the prompt.
1563
- */
1564
- presencePenalty?: number;
1565
- /**
1566
- Frequency penalty setting. It affects the likelihood of the model
1567
- to repeatedly use the same words or phrases.
1568
- */
1569
- frequencyPenalty?: number;
1570
- /**
1571
- Response format. The output can either be text or JSON. Default is text.
1572
-
1573
- If JSON is selected, a schema can optionally be provided to guide the LLM.
1574
- */
1575
- responseFormat?: {
1576
- type: 'text';
1675
+ mode: {
1676
+ type: 'regular';
1677
+ /**
1678
+ The tools that are available for the model.
1679
+ */
1680
+ tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
1681
+ /**
1682
+ Specifies how the tool should be selected. Defaults to 'auto'.
1683
+ */
1684
+ toolChoice?: LanguageModelV1ToolChoice;
1577
1685
  } | {
1578
- type: 'json';
1686
+ type: 'object-json';
1579
1687
  /**
1580
1688
  * JSON schema that the generated output should conform to.
1581
1689
  */
@@ -1588,48 +1696,38 @@ type LanguageModelV2CallOptions = {
1588
1696
  * Description of the output that should be generated. Used by some providers for additional LLM guidance.
1589
1697
  */
1590
1698
  description?: string;
1591
- };
1592
- /**
1593
- The seed (integer) to use for random sampling. If set and supported
1594
- by the model, calls will generate deterministic results.
1595
- */
1596
- seed?: number;
1597
- /**
1598
- The tools that are available for the model.
1599
- */
1600
- tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
1601
- /**
1602
- Specifies how the tool should be selected. Defaults to 'auto'.
1603
- */
1604
- toolChoice?: LanguageModelV2ToolChoice;
1605
- /**
1606
- Abort signal for cancelling the operation.
1607
- */
1608
- abortSignal?: AbortSignal;
1699
+ } | {
1700
+ type: 'object-tool';
1701
+ tool: LanguageModelV1FunctionTool;
1702
+ };
1609
1703
  /**
1610
- Additional HTTP headers to be sent with the request.
1611
- Only applicable for HTTP-based providers.
1612
- */
1613
- headers?: Record<string, string | undefined>;
1704
+ A language mode prompt is a standardized prompt type.
1705
+
1706
+ Note: This is **not** the user-facing prompt. The AI SDK methods will map the
1707
+ user-facing prompt types such as chat or instruction prompts to this format.
1708
+ That approach allows us to evolve the user facing prompts without breaking
1709
+ the language model interface.
1710
+ */
1711
+ prompt: LanguageModelV1Prompt;
1614
1712
  /**
1615
- * Additional provider-specific options. They are passed through
1616
- * to the provider from the AI SDK and enable provider-specific
1617
- * functionality that can be fully encapsulated in the provider.
1713
+ Additional provider-specific metadata.
1714
+ The metadata is passed through to the provider from the AI SDK and enables
1715
+ provider-specific functionality that can be fully encapsulated in the provider.
1618
1716
  */
1619
- providerOptions?: LanguageModelV2ProviderOptions;
1717
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1620
1718
  };
1621
1719
 
1622
1720
  /**
1623
1721
  Warning from the model provider for this call. The call will proceed, but e.g.
1624
1722
  some settings might not be supported, which can lead to suboptimal results.
1625
1723
  */
1626
- type LanguageModelV2CallWarning = {
1724
+ type LanguageModelV1CallWarning = {
1627
1725
  type: 'unsupported-setting';
1628
- setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
1726
+ setting: keyof LanguageModelV1CallSettings;
1629
1727
  details?: string;
1630
1728
  } | {
1631
1729
  type: 'unsupported-tool';
1632
- tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
1730
+ tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
1633
1731
  details?: string;
1634
1732
  } | {
1635
1733
  type: 'other';
@@ -1648,9 +1746,9 @@ Can be one of the following:
1648
1746
  - `other`: model stopped for other reasons
1649
1747
  - `unknown`: the model has not transmitted a finish reason
1650
1748
  */
1651
- type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
1749
+ type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
1652
1750
 
1653
- type LanguageModelV2FunctionToolCall = {
1751
+ type LanguageModelV1FunctionToolCall = {
1654
1752
  toolCallType: 'function';
1655
1753
  toolCallId: string;
1656
1754
  toolName: string;
@@ -1664,7 +1762,7 @@ type LanguageModelV2FunctionToolCall = {
1664
1762
  /**
1665
1763
  Log probabilities for each token and its top log probabilities.
1666
1764
  */
1667
- type LanguageModelV2LogProbs = Array<{
1765
+ type LanguageModelV1LogProbs = Array<{
1668
1766
  token: string;
1669
1767
  logprob: number;
1670
1768
  topLogprobs: Array<{
@@ -1674,58 +1772,9 @@ type LanguageModelV2LogProbs = Array<{
1674
1772
  }>;
1675
1773
 
1676
1774
  /**
1677
- * Additional provider-specific metadata.
1678
- * Metadata are additional outputs from the provider.
1679
- * They are passed through to the provider from the AI SDK
1680
- * and enable provider-specific functionality
1681
- * that can be fully encapsulated in the provider.
1682
- *
1683
- * This enables us to quickly ship provider-specific functionality
1684
- * without affecting the core AI SDK.
1685
- *
1686
- * The outer record is keyed by the provider name, and the inner
1687
- * record is keyed by the provider-specific metadata key.
1688
- *
1689
- * ```ts
1690
- * {
1691
- * "anthropic": {
1692
- * "cacheControl": { "type": "ephemeral" }
1693
- * }
1694
- * }
1695
- * ```
1696
- */
1697
- type LanguageModelV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
1698
-
1699
- /**
1700
- * A source that has been used as input to generate the response.
1701
- */
1702
- type LanguageModelV2Source = {
1703
- /**
1704
- * A URL source. This is return by web search RAG models.
1705
- */
1706
- sourceType: 'url';
1707
- /**
1708
- * The ID of the source.
1709
- */
1710
- id: string;
1711
- /**
1712
- * The URL of the source.
1713
- */
1714
- url: string;
1715
- /**
1716
- * The title of the source.
1717
- */
1718
- title?: string;
1719
- /**
1720
- * Additional provider metadata for the source.
1721
- */
1722
- providerMetadata?: LanguageModelV2ProviderMetadata;
1723
- };
1724
-
1725
- /**
1726
- Specification for a language model that implements the language model interface version 2.
1775
+ Specification for a language model that implements the language model interface version 1.
1727
1776
  */
1728
- type LanguageModelV2 = {
1777
+ type LanguageModelV1 = {
1729
1778
  /**
1730
1779
  The language model must specify which language model interface
1731
1780
  version it implements. This will allow us to evolve the language
@@ -1733,7 +1782,7 @@ type LanguageModelV2 = {
1733
1782
  implementation versions can be handled as a discriminated union
1734
1783
  on our side.
1735
1784
  */
1736
- readonly specificationVersion: 'v2';
1785
+ readonly specificationVersion: 'v1';
1737
1786
  /**
1738
1787
  Name of the provider for logging purposes.
1739
1788
  */
@@ -1750,7 +1799,7 @@ type LanguageModelV2 = {
1750
1799
  This is needed to generate the best objects possible w/o requiring the
1751
1800
  user to explicitly specify the object generation mode.
1752
1801
  */
1753
- readonly defaultObjectGenerationMode: LanguageModelV2ObjectGenerationMode;
1802
+ readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
1754
1803
  /**
1755
1804
  Flag whether this model supports image URLs. Default is `true`.
1756
1805
 
@@ -1789,7 +1838,7 @@ type LanguageModelV2 = {
1789
1838
  Naming: "do" prefix to prevent accidental direct usage of the method
1790
1839
  by the user.
1791
1840
  */
1792
- doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
1841
+ doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
1793
1842
  /**
1794
1843
  Text that the model has generated.
1795
1844
  Can be undefined if the model did not generate any text.
@@ -1813,32 +1862,23 @@ An optional signature for verifying that the reasoning originated from the model
1813
1862
  /**
1814
1863
  Generated files as base64 encoded strings or binary data.
1815
1864
  The files should be returned without any unnecessary conversion.
1865
+ If the API returns base64 encoded strings, the files should be returned
1866
+ as base64 encoded strings. If the API returns binary data, the files should
1867
+ be returned as binary data.
1816
1868
  */
1817
1869
  files?: Array<{
1818
- /**
1819
- Generated file data as base64 encoded strings or binary data.
1820
- The file data should be returned without any unnecessary conversion.
1821
- If the API returns base64 encoded strings, the file data should be returned
1822
- as base64 encoded strings. If the API returns binary data, the file data should
1823
- be returned as binary data.
1824
- */
1825
1870
  data: string | Uint8Array;
1826
- /**
1827
- The IANA media type of the file.
1828
-
1829
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1830
- */
1831
- mediaType: string;
1871
+ mimeType: string;
1832
1872
  }>;
1833
1873
  /**
1834
1874
  Tool calls that the model has generated.
1835
1875
  Can be undefined if the model did not generate any tool calls.
1836
1876
  */
1837
- toolCalls?: Array<LanguageModelV2FunctionToolCall>;
1877
+ toolCalls?: Array<LanguageModelV1FunctionToolCall>;
1838
1878
  /**
1839
1879
  Finish reason.
1840
1880
  */
1841
- finishReason: LanguageModelV2FinishReason;
1881
+ finishReason: LanguageModelV1FinishReason;
1842
1882
  /**
1843
1883
  Usage information.
1844
1884
  */
@@ -1847,13 +1887,42 @@ An optional signature for verifying that the reasoning originated from the model
1847
1887
  completionTokens: number;
1848
1888
  };
1849
1889
  /**
1890
+ Raw prompt and setting information for observability provider integration.
1891
+ */
1892
+ rawCall: {
1893
+ /**
1894
+ Raw prompt after expansion and conversion to the format that the
1895
+ provider uses to send the information to their API.
1896
+ */
1897
+ rawPrompt: unknown;
1898
+ /**
1899
+ Raw settings that are used for the API call. Includes provider-specific
1900
+ settings.
1901
+ */
1902
+ rawSettings: Record<string, unknown>;
1903
+ };
1904
+ /**
1905
+ Optional response information for telemetry and debugging purposes.
1906
+ */
1907
+ rawResponse?: {
1908
+ /**
1909
+ Response headers.
1910
+ */
1911
+ headers?: Record<string, string>;
1912
+ /**
1913
+ Response body.
1914
+ */
1915
+ body?: unknown;
1916
+ };
1917
+ /**
1850
1918
  Optional request information for telemetry and debugging purposes.
1851
1919
  */
1852
1920
  request?: {
1853
1921
  /**
1854
- Request HTTP body that was sent to the provider API.
1922
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1923
+ Non-HTTP(s) providers should not set this.
1855
1924
  */
1856
- body?: unknown;
1925
+ body?: string;
1857
1926
  };
1858
1927
  /**
1859
1928
  Optional response information for telemetry and debugging purposes.
@@ -1871,33 +1940,25 @@ An optional signature for verifying that the reasoning originated from the model
1871
1940
  The ID of the response model that was used to generate the response, if the provider sends one.
1872
1941
  */
1873
1942
  modelId?: string;
1874
- /**
1875
- Response headers.
1876
- */
1877
- headers?: Record<string, string>;
1878
- /**
1879
- Response HTTP body.
1880
- */
1881
- body?: unknown;
1882
1943
  };
1883
- warnings?: LanguageModelV2CallWarning[];
1944
+ warnings?: LanguageModelV1CallWarning[];
1884
1945
  /**
1885
1946
  Additional provider-specific metadata. They are passed through
1886
1947
  from the provider to the AI SDK and enable provider-specific
1887
1948
  results that can be fully encapsulated in the provider.
1888
1949
  */
1889
- providerMetadata?: LanguageModelV2ProviderMetadata;
1950
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1890
1951
  /**
1891
1952
  Sources that have been used as input to generate the response.
1892
1953
  */
1893
- sources?: LanguageModelV2Source[];
1954
+ sources?: LanguageModelV1Source[];
1894
1955
  /**
1895
1956
  Logprobs for the completion.
1896
1957
  `undefined` if the mode does not support logprobs or if was not enabled
1897
1958
 
1898
1959
  @deprecated will be changed into a provider-specific extension in v2
1899
1960
  */
1900
- logprobs?: LanguageModelV2LogProbs;
1961
+ logprobs?: LanguageModelV1LogProbs;
1901
1962
  }>;
1902
1963
  /**
1903
1964
  Generates a language model output (streaming).
@@ -1907,33 +1968,49 @@ An optional signature for verifying that the reasoning originated from the model
1907
1968
  *
1908
1969
  @return A stream of higher-level language model output parts.
1909
1970
  */
1910
- doStream(options: LanguageModelV2CallOptions): PromiseLike<{
1911
- stream: ReadableStream<LanguageModelV2StreamPart>;
1971
+ doStream(options: LanguageModelV1CallOptions): PromiseLike<{
1972
+ stream: ReadableStream<LanguageModelV1StreamPart>;
1912
1973
  /**
1913
- Optional request information for telemetry and debugging purposes.
1974
+ Raw prompt and setting information for observability provider integration.
1914
1975
  */
1915
- request?: {
1976
+ rawCall: {
1916
1977
  /**
1917
- Request HTTP body that was sent to the provider API.
1918
- */
1919
- body?: unknown;
1978
+ Raw prompt after expansion and conversion to the format that the
1979
+ provider uses to send the information to their API.
1980
+ */
1981
+ rawPrompt: unknown;
1982
+ /**
1983
+ Raw settings that are used for the API call. Includes provider-specific
1984
+ settings.
1985
+ */
1986
+ rawSettings: Record<string, unknown>;
1920
1987
  };
1921
1988
  /**
1922
1989
  Optional raw response data.
1923
1990
  */
1924
- response?: {
1991
+ rawResponse?: {
1925
1992
  /**
1926
1993
  Response headers.
1927
1994
  */
1928
1995
  headers?: Record<string, string>;
1929
1996
  };
1930
1997
  /**
1998
+ Optional request information for telemetry and debugging purposes.
1999
+ */
2000
+ request?: {
2001
+ /**
2002
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
2003
+ Non-HTTP(s) providers should not set this.
2004
+ */
2005
+ body?: string;
2006
+ };
2007
+ /**
1931
2008
  Warnings for the call, e.g. unsupported settings.
1932
2009
  */
1933
- warnings?: Array<LanguageModelV2CallWarning>;
2010
+ warnings?: Array<LanguageModelV1CallWarning>;
1934
2011
  }>;
1935
2012
  };
1936
- type LanguageModelV2StreamPart = {
2013
+ type LanguageModelV1StreamPart = {
1937
2014
  type: 'text-delta';
1938
2015
  textDelta: string;
1939
2016
  } | {
@@ -1947,15 +2024,10 @@ type LanguageModelV2StreamPart = {
1947
2024
  data: string;
1948
2025
  } | {
1949
2026
  type: 'source';
1950
- source: LanguageModelV2Source;
2027
+ source: LanguageModelV1Source;
1951
2028
  } | {
1952
2029
  type: 'file';
1953
- /**
1954
- The IANA media type of the file.
1955
-
1956
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1957
- */
1958
- mediaType: string;
2030
+ mimeType: string;
1959
2031
  /**
1960
2032
  Generated file data as base64 encoded strings or binary data.
1961
2033
  The file data should be returned without any unnecessary conversion.
@@ -1966,7 +2038,7 @@ be returned as binary data.
1966
2038
  data: string | Uint8Array;
1967
2039
  } | ({
1968
2040
  type: 'tool-call';
1969
- } & LanguageModelV2FunctionToolCall) | {
2041
+ } & LanguageModelV1FunctionToolCall) | {
1970
2042
  type: 'tool-call-delta';
1971
2043
  toolCallType: 'function';
1972
2044
  toolCallId: string;
@@ -1979,13 +2051,13 @@ be returned as binary data.
1979
2051
  modelId?: string;
1980
2052
  } | {
1981
2053
  type: 'finish';
1982
- finishReason: LanguageModelV2FinishReason;
1983
- providerMetadata?: LanguageModelV2ProviderMetadata;
2054
+ finishReason: LanguageModelV1FinishReason;
2055
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1984
2056
  usage: {
1985
2057
  promptTokens: number;
1986
2058
  completionTokens: number;
1987
2059
  };
1988
- logprobs?: LanguageModelV2LogProbs;
2060
+ logprobs?: LanguageModelV1LogProbs;
1989
2061
  } | {
1990
2062
  type: 'error';
1991
2063
  error: unknown;
@@ -1994,67 +2066,7 @@ be returned as binary data.
1994
2066
  The object generation modes available for use with a model. `undefined`
1995
2067
  represents no support for object generation.
1996
2068
  */
1997
- type LanguageModelV2ObjectGenerationMode = 'json' | 'tool' | undefined;
1998
-
1999
- /**
2000
- * Experimental middleware for LanguageModelV2.
2001
- * This type defines the structure for middleware that can be used to modify
2002
- * the behavior of LanguageModelV2 operations.
2003
- */
2004
- type LanguageModelV2Middleware = {
2005
- /**
2006
- * Middleware specification version. Use `v2` for the current version.
2007
- */
2008
- middlewareVersion?: 'v2' | undefined;
2009
- /**
2010
- * Transforms the parameters before they are passed to the language model.
2011
- * @param options - Object containing the type of operation and the parameters.
2012
- * @param options.type - The type of operation ('generate' or 'stream').
2013
- * @param options.params - The original parameters for the language model call.
2014
- * @returns A promise that resolves to the transformed parameters.
2015
- */
2016
- transformParams?: (options: {
2017
- type: 'generate' | 'stream';
2018
- params: LanguageModelV2CallOptions;
2019
- }) => PromiseLike<LanguageModelV2CallOptions>;
2020
- /**
2021
- * Wraps the generate operation of the language model.
2022
- * @param options - Object containing the generate function, parameters, and model.
2023
- * @param options.doGenerate - The original generate function.
2024
- * @param options.doStream - The original stream function.
2025
- * @param options.params - The parameters for the generate call. If the
2026
- * `transformParams` middleware is used, this will be the transformed parameters.
2027
- * @param options.model - The language model instance.
2028
- * @returns A promise that resolves to the result of the generate operation.
2029
- */
2030
- wrapGenerate?: (options: {
2031
- doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
2032
- doStream: () => ReturnType<LanguageModelV2['doStream']>;
2033
- params: LanguageModelV2CallOptions;
2034
- model: LanguageModelV2;
2035
- }) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
2036
- /**
2037
- * Wraps the stream operation of the language model.
2038
- *
2039
- * @param options - Object containing the stream function, parameters, and model.
2040
- * @param options.doGenerate - The original generate function.
2041
- * @param options.doStream - The original stream function.
2042
- * @param options.params - The parameters for the stream call. If the
2043
- * `transformParams` middleware is used, this will be the transformed parameters.
2044
- * @param options.model - The language model instance.
2045
- * @returns A promise that resolves to the result of the stream operation.
2046
- */
2047
- wrapStream?: (options: {
2048
- doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
2049
- doStream: () => ReturnType<LanguageModelV2['doStream']>;
2050
- params: LanguageModelV2CallOptions;
2051
- model: LanguageModelV2;
2052
- }) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
2053
- };
2054
- /**
2055
- * @deprecated Use `LanguageModelV2Middleware` instead.
2056
- */
2057
- type Experimental_LanguageModelV2Middleware = LanguageModelV2Middleware;
2069
+ type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
2058
2070
 
2059
2071
  type TranscriptionModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
2060
2072
  type TranscriptionModelV1CallOptions = {
@@ -2233,7 +2245,7 @@ interface ProviderV1 {
2233
2245
 
2234
2246
  @throws {NoSuchModelError} If no such model exists.
2235
2247
  */
2236
- textEmbeddingModel(modelId: string): EmbeddingModelV1<string>;
2248
+ textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
2237
2249
  /**
2238
2250
  Returns the image model with the given id.
2239
2251
  The model id is then passed to the provider function to get the model.
@@ -2279,7 +2291,7 @@ interface ProviderV2 {
2279
2291
 
2280
2292
  @throws {NoSuchModelError} If no such model exists.
2281
2293
  */
2282
- textEmbeddingModel(modelId: string): EmbeddingModelV1<string>;
2294
+ textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
2283
2295
  /**
2284
2296
  Returns the image model with the given id.
2285
2297
  The model id is then passed to the provider function to get the model.
@@ -2291,4 +2303,4 @@ interface ProviderV2 {
2291
2303
  readonly imageModel: (modelId: string) => ImageModelV1;
2292
2304
  }
2293
2305
 
2294
- export { AISDKError, APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, type Experimental_LanguageModelV2Middleware, type ImageModelV1, type ImageModelV1CallOptions, type ImageModelV1CallWarning, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1ObjectGenerationMode, type LanguageModelV1Prompt, type LanguageModelV1ProviderDefinedTool, type LanguageModelV1ProviderMetadata, type LanguageModelV1ReasoningPart, type LanguageModelV1RedactedReasoningPart, type LanguageModelV1Source, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2FunctionToolCall, type LanguageModelV2LogProbs, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2ObjectGenerationMode, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2ProviderMetadata, type LanguageModelV2ProviderOptions, type LanguageModelV2ReasoningPart, type LanguageModelV2RedactedReasoningPart, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2TextPart, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, type ProviderV2, TooManyEmbeddingValuesForCallError, type TranscriptionModelV1, type TranscriptionModelV1CallOptions, type TranscriptionModelV1CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
2306
+ export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, EmptyResponseBodyError, type ImageModelV1, type ImageModelV1CallOptions, type ImageModelV1CallWarning, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FilePart, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1ObjectGenerationMode, type LanguageModelV1Prompt, type LanguageModelV1ProviderDefinedTool, type LanguageModelV1ProviderMetadata, type LanguageModelV1ReasoningPart, type LanguageModelV1RedactedReasoningPart, type LanguageModelV1Source, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2LogProbs, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2ObjectGenerationMode, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2RedactedReasoningPart, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallDelta, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, type ProviderV2, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, TooManyEmbeddingValuesForCallError, type TranscriptionModelV1, type TranscriptionModelV1CallOptions, type TranscriptionModelV1CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };