@ai-sdk/provider 2.0.0-canary.5 → 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.mts 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.
675
- */
676
- providerMetadata?: LanguageModelV1ProviderMetadata;
677
- }
678
- /**
679
- Image content part of a prompt. It contains an image.
680
- */
681
- interface LanguageModelV1ImagePart {
682
- type: 'image';
683
- /**
684
- Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
685
- */
686
- image: Uint8Array | URL;
687
- /**
688
- Optional mime type of the image.
689
- */
690
- mimeType?: string;
691
- /**
692
- * Additional provider-specific metadata. They are passed through
608
+ * Additional provider-specific options. They are passed through
693
609
  * to the provider from the AI SDK and enable provider-specific
694
610
  * functionality that can be fully encapsulated in the provider.
695
611
  */
696
- providerMetadata?: LanguageModelV1ProviderMetadata;
612
+ providerOptions?: SharedV2ProviderOptions;
697
613
  }
698
614
  /**
699
615
  File content part of a prompt. It contains a file.
700
616
  */
701
- interface LanguageModelV1FilePart {
617
+ interface LanguageModelV2FilePart {
702
618
  type: 'file';
703
619
  /**
704
620
  * Optional filename of the file.
705
621
  */
706
622
  filename?: string;
707
623
  /**
708
- File data as base64 encoded string or as a URL.
709
- */
710
- data: string | URL;
711
- /**
712
- Mime type of the file.
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
713
633
  */
714
- mimeType: string;
634
+ mediaType: string;
715
635
  /**
716
- * Additional provider-specific metadata. They are passed through
636
+ * Additional provider-specific options. They are passed through
717
637
  * to the provider from the AI SDK and enable provider-specific
718
638
  * functionality that can be fully encapsulated in the provider.
719
639
  */
720
- providerMetadata?: LanguageModelV1ProviderMetadata;
640
+ providerOptions?: SharedV2ProviderOptions;
721
641
  }
722
642
  /**
723
643
  Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
724
644
  */
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,133 +1142,255 @@ 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
1154
  /**
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.
1155
+ Warnings for the call, e.g. unsupported settings.
1123
1156
  */
1124
- providerMetadata?: LanguageModelV1ProviderMetadata;
1157
+ warnings?: LanguageModelV2CallWarning[];
1158
+ }>;
1159
+ /**
1160
+ Generates a language model output (streaming).
1161
+
1162
+ Naming: "do" prefix to prevent accidental direct usage of the method
1163
+ by the user.
1164
+ *
1165
+ @return A stream of higher-level language model output parts.
1166
+ */
1167
+ doStream(options: LanguageModelV2CallOptions): PromiseLike<{
1168
+ stream: ReadableStream<LanguageModelV2StreamPart>;
1125
1169
  /**
1126
- Sources that have been used as input to generate the response.
1170
+ Optional request information for telemetry and debugging purposes.
1127
1171
  */
1128
- sources?: LanguageModelV1Source[];
1172
+ request?: {
1173
+ /**
1174
+ Request HTTP body that was sent to the provider API.
1175
+ */
1176
+ body?: unknown;
1177
+ };
1129
1178
  /**
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
1179
+ Optional response data.
1134
1180
  */
1135
- logprobs?: LanguageModelV1LogProbs;
1181
+ response?: {
1182
+ /**
1183
+ Response headers.
1184
+ */
1185
+ headers?: Record<string, string>;
1186
+ };
1187
+ /**
1188
+ Warnings for the call, e.g. unsupported settings.
1189
+ */
1190
+ warnings?: Array<LanguageModelV2CallWarning>;
1136
1191
  }>;
1192
+ };
1193
+ type LanguageModelV2StreamPart = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2Source | LanguageModelV2File | LanguageModelV2ToolCall | LanguageModelV2ToolCallDelta | {
1194
+ type: 'response-metadata';
1195
+ id?: string;
1196
+ timestamp?: Date;
1197
+ modelId?: string;
1198
+ } | {
1199
+ type: 'finish';
1200
+ finishReason: LanguageModelV2FinishReason;
1201
+ providerMetadata?: SharedV2ProviderMetadata;
1202
+ usage: LanguageModelV2Usage;
1203
+ logprobs?: LanguageModelV2LogProbs;
1204
+ } | {
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;
1137
1311
  /**
1138
- Generates a language model output (streaming).
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.
1139
1324
 
1140
- Naming: "do" prefix to prevent accidental direct usage of the method
1141
- by the user.
1142
- *
1143
- @return A stream of higher-level language model output parts.
1325
+ It is recommended to set either `temperature` or `topP`, but not both.
1144
1326
  */
1145
- doStream(options: LanguageModelV1CallOptions): PromiseLike<{
1146
- stream: ReadableStream<LanguageModelV1StreamPart>;
1147
- /**
1148
- Raw prompt and setting information for observability provider integration.
1149
- */
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;
1156
- /**
1157
- Raw settings that are used for the API call. Includes provider-specific
1158
- settings.
1159
- */
1160
- rawSettings: Record<string, unknown>;
1161
- };
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';
1162
1366
  /**
1163
- Optional raw response data.
1367
+ * JSON schema that the generated output should conform to.
1164
1368
  */
1165
- rawResponse?: {
1166
- /**
1167
- Response headers.
1168
- */
1169
- headers?: Record<string, string>;
1170
- };
1369
+ schema?: JSONSchema7;
1171
1370
  /**
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.
1371
+ * Name of output that should be generated. Used by some providers for additional LLM guidance.
1178
1372
  */
1179
- body?: string;
1180
- };
1373
+ name?: string;
1181
1374
  /**
1182
- Warnings for the call, e.g. unsupported settings.
1375
+ * Description of the output that should be generated. Used by some providers for additional LLM guidance.
1183
1376
  */
1184
- warnings?: Array<LanguageModelV1CallWarning>;
1185
- }>;
1186
- };
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;
1199
- } | {
1200
- type: 'source';
1201
- source: LanguageModelV1Source;
1202
- } | {
1203
- type: 'file';
1204
- mimeType: string;
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,34 +1419,6 @@ type LanguageModelV2FunctionTool = {
1269
1419
  parameters: JSONSchema7;
1270
1420
  };
1271
1421
 
1272
- /**
1273
- Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
1274
- */
1275
- type LanguageModelV2DataContent = Uint8Array | string | URL;
1276
-
1277
- /**
1278
- * Additional provider-specific options.
1279
- * Options are additional input to the provider.
1280
- * They are passed through to the provider from the AI SDK
1281
- * and enable provider-specific functionality
1282
- * that can be fully encapsulated in the provider.
1283
- *
1284
- * This enables us to quickly ship provider-specific functionality
1285
- * without affecting the core AI SDK.
1286
- *
1287
- * The outer record is keyed by the provider name, and the inner
1288
- * record is keyed by the provider-specific metadata key.
1289
- *
1290
- * ```ts
1291
- * {
1292
- * "anthropic": {
1293
- * "cacheControl": { "type": "ephemeral" }
1294
- * }
1295
- * }
1296
- * ```
1297
- */
1298
- type LanguageModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
1299
-
1300
1422
  /**
1301
1423
  A prompt is a list of messages.
1302
1424
 
@@ -1306,47 +1428,47 @@ tool calls. The validation happens at runtime.
1306
1428
  Note: This is not a user-facing prompt. The AI SDK methods will map the
1307
1429
  user-facing prompt types such as chat or instruction prompts to this format.
1308
1430
  */
1309
- type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
1310
- type LanguageModelV2Message = ({
1431
+ type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
1432
+ type LanguageModelV1Message = ({
1311
1433
  role: 'system';
1312
1434
  content: string;
1313
1435
  } | {
1314
1436
  role: 'user';
1315
- content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
1437
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
1316
1438
  } | {
1317
1439
  role: 'assistant';
1318
- content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2RedactedReasoningPart | LanguageModelV2ToolCallPart>;
1440
+ content: Array<LanguageModelV1TextPart | LanguageModelV1FilePart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
1319
1441
  } | {
1320
1442
  role: 'tool';
1321
- content: Array<LanguageModelV2ToolResultPart>;
1443
+ content: Array<LanguageModelV1ToolResultPart>;
1322
1444
  }) & {
1323
1445
  /**
1324
- * Additional provider-specific options. They are passed through
1446
+ * Additional provider-specific metadata. They are passed through
1325
1447
  * to the provider from the AI SDK and enable provider-specific
1326
1448
  * functionality that can be fully encapsulated in the provider.
1327
1449
  */
1328
- providerOptions?: LanguageModelV2ProviderOptions;
1450
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1329
1451
  };
1330
1452
  /**
1331
1453
  Text content part of a prompt. It contains a string of text.
1332
1454
  */
1333
- interface LanguageModelV2TextPart {
1455
+ interface LanguageModelV1TextPart {
1334
1456
  type: 'text';
1335
1457
  /**
1336
1458
  The text content.
1337
1459
  */
1338
1460
  text: string;
1339
1461
  /**
1340
- * Additional provider-specific options. They are passed through
1462
+ * Additional provider-specific metadata. They are passed through
1341
1463
  * to the provider from the AI SDK and enable provider-specific
1342
1464
  * functionality that can be fully encapsulated in the provider.
1343
1465
  */
1344
- providerOptions?: LanguageModelV2ProviderOptions;
1466
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1345
1467
  }
1346
1468
  /**
1347
1469
  Reasoning content part of a prompt. It contains a string of reasoning text.
1348
1470
  */
1349
- interface LanguageModelV2ReasoningPart {
1471
+ interface LanguageModelV1ReasoningPart {
1350
1472
  type: 'reasoning';
1351
1473
  /**
1352
1474
  The reasoning text.
@@ -1357,60 +1479,76 @@ interface LanguageModelV2ReasoningPart {
1357
1479
  */
1358
1480
  signature?: string;
1359
1481
  /**
1360
- * Additional provider-specific options. They are passed through
1361
- * to the provider from the AI SDK and enable provider-specific
1362
- * 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.
1363
1485
  */
1364
- providerOptions?: LanguageModelV2ProviderOptions;
1486
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1365
1487
  }
1366
1488
  /**
1367
1489
  Redacted reasoning content part of a prompt.
1368
1490
  */
1369
- interface LanguageModelV2RedactedReasoningPart {
1491
+ interface LanguageModelV1RedactedReasoningPart {
1370
1492
  type: 'redacted-reasoning';
1371
1493
  /**
1372
1494
  Redacted reasoning data.
1373
1495
  */
1374
1496
  data: string;
1375
1497
  /**
1376
- * 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
1377
1519
  * to the provider from the AI SDK and enable provider-specific
1378
1520
  * functionality that can be fully encapsulated in the provider.
1379
1521
  */
1380
- providerOptions?: LanguageModelV2ProviderOptions;
1522
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1381
1523
  }
1382
1524
  /**
1383
1525
  File content part of a prompt. It contains a file.
1384
1526
  */
1385
- interface LanguageModelV2FilePart {
1527
+ interface LanguageModelV1FilePart {
1386
1528
  type: 'file';
1387
1529
  /**
1388
1530
  * Optional filename of the file.
1389
1531
  */
1390
1532
  filename?: string;
1391
1533
  /**
1392
- File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
1393
- */
1394
- data: LanguageModelV2DataContent;
1534
+ File data as base64 encoded string or as a URL.
1535
+ */
1536
+ data: string | URL;
1395
1537
  /**
1396
- IANA media type of the file.
1397
-
1398
- Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
1399
-
1400
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1538
+ Mime type of the file.
1401
1539
  */
1402
- mediaType: string;
1540
+ mimeType: string;
1403
1541
  /**
1404
- * Additional provider-specific options. They are passed through
1542
+ * Additional provider-specific metadata. They are passed through
1405
1543
  * to the provider from the AI SDK and enable provider-specific
1406
1544
  * functionality that can be fully encapsulated in the provider.
1407
1545
  */
1408
- providerOptions?: LanguageModelV2ProviderOptions;
1546
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1409
1547
  }
1410
1548
  /**
1411
1549
  Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
1412
1550
  */
1413
- interface LanguageModelV2ToolCallPart {
1551
+ interface LanguageModelV1ToolCallPart {
1414
1552
  type: 'tool-call';
1415
1553
  /**
1416
1554
  ID of the tool call. This ID is used to match the tool call with the tool result.
@@ -1425,16 +1563,16 @@ interface LanguageModelV2ToolCallPart {
1425
1563
  */
1426
1564
  args: unknown;
1427
1565
  /**
1428
- * Additional provider-specific options. They are passed through
1566
+ * Additional provider-specific metadata. They are passed through
1429
1567
  * to the provider from the AI SDK and enable provider-specific
1430
1568
  * functionality that can be fully encapsulated in the provider.
1431
1569
  */
1432
- providerOptions?: LanguageModelV2ProviderOptions;
1570
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1433
1571
  }
1434
1572
  /**
1435
1573
  Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
1436
1574
  */
1437
- interface LanguageModelV2ToolResultPart {
1575
+ interface LanguageModelV1ToolResultPart {
1438
1576
  type: 'tool-result';
1439
1577
  /**
1440
1578
  ID of the tool call that this result is associated with.
@@ -1469,24 +1607,22 @@ base-64 encoded image data
1469
1607
  */
1470
1608
  data: string;
1471
1609
  /**
1472
- IANA media type of the image.
1473
-
1474
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1610
+ Mime type of the image.
1475
1611
  */
1476
- mediaType?: string;
1612
+ mimeType?: string;
1477
1613
  }>;
1478
1614
  /**
1479
- * Additional provider-specific options. They are passed through
1615
+ * Additional provider-specific metadata. They are passed through
1480
1616
  * to the provider from the AI SDK and enable provider-specific
1481
1617
  * functionality that can be fully encapsulated in the provider.
1482
1618
  */
1483
- providerOptions?: LanguageModelV2ProviderOptions;
1619
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1484
1620
  }
1485
1621
 
1486
1622
  /**
1487
1623
  The configuration of a tool that is defined by the provider.
1488
1624
  */
1489
- type LanguageModelV2ProviderDefinedTool = {
1625
+ type LanguageModelV1ProviderDefinedTool = {
1490
1626
  /**
1491
1627
  The type of the tool (always 'provider-defined').
1492
1628
  */
@@ -1505,7 +1641,7 @@ type LanguageModelV2ProviderDefinedTool = {
1505
1641
  args: Record<string, unknown>;
1506
1642
  };
1507
1643
 
1508
- type LanguageModelV2ToolChoice = {
1644
+ type LanguageModelV1ToolChoice = {
1509
1645
  type: 'auto';
1510
1646
  } | {
1511
1647
  type: 'none';
@@ -1516,7 +1652,7 @@ type LanguageModelV2ToolChoice = {
1516
1652
  toolName: string;
1517
1653
  };
1518
1654
 
1519
- type LanguageModelV2CallOptions = {
1655
+ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
1520
1656
  /**
1521
1657
  Whether the user provided the input as messages or as
1522
1658
  a prompt. This can help guide non-chat models in the
@@ -1525,62 +1661,29 @@ type LanguageModelV2CallOptions = {
1525
1661
  */
1526
1662
  inputFormat: 'messages' | 'prompt';
1527
1663
  /**
1528
- 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.
1529
1670
 
1530
- Note: This is **not** the user-facing prompt. The AI SDK methods will map the
1531
- user-facing prompt types such as chat or instruction prompts to this format.
1532
- That approach allows us to evolve the user facing prompts without breaking
1533
- the language model interface.
1534
- */
1535
- prompt: LanguageModelV2Prompt;
1536
- /**
1537
- 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.
1538
1674
  */
1539
- maxOutputTokens?: number;
1540
- /**
1541
- Temperature setting.
1542
-
1543
- It is recommended to set either `temperature` or `topP`, but not both.
1544
- */
1545
- temperature?: number;
1546
- /**
1547
- Stop sequences.
1548
- If set, the model will stop generating text when one of the stop sequences is generated.
1549
- Providers may have limits on the number of stop sequences.
1550
- */
1551
- stopSequences?: string[];
1552
- /**
1553
- Nucleus sampling.
1554
-
1555
- It is recommended to set either `temperature` or `topP`, but not both.
1556
- */
1557
- topP?: number;
1558
- /**
1559
- Only sample from the top K options for each subsequent token.
1560
-
1561
- Used to remove "long tail" low probability responses.
1562
- Recommended for advanced use cases only. You usually only need to use temperature.
1563
- */
1564
- topK?: number;
1565
- /**
1566
- Presence penalty setting. It affects the likelihood of the model to
1567
- repeat information that is already in the prompt.
1568
- */
1569
- presencePenalty?: number;
1570
- /**
1571
- Frequency penalty setting. It affects the likelihood of the model
1572
- to repeatedly use the same words or phrases.
1573
- */
1574
- frequencyPenalty?: number;
1575
- /**
1576
- Response format. The output can either be text or JSON. Default is text.
1577
-
1578
- If JSON is selected, a schema can optionally be provided to guide the LLM.
1579
- */
1580
- responseFormat?: {
1581
- 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;
1582
1685
  } | {
1583
- type: 'json';
1686
+ type: 'object-json';
1584
1687
  /**
1585
1688
  * JSON schema that the generated output should conform to.
1586
1689
  */
@@ -1593,179 +1696,85 @@ type LanguageModelV2CallOptions = {
1593
1696
  * Description of the output that should be generated. Used by some providers for additional LLM guidance.
1594
1697
  */
1595
1698
  description?: string;
1699
+ } | {
1700
+ type: 'object-tool';
1701
+ tool: LanguageModelV1FunctionTool;
1596
1702
  };
1597
1703
  /**
1598
- The seed (integer) to use for random sampling. If set and supported
1599
- by the model, calls will generate deterministic results.
1600
- */
1601
- seed?: number;
1602
- /**
1603
- The tools that are available for the model.
1604
- */
1605
- tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
1606
- /**
1607
- Specifies how the tool should be selected. Defaults to 'auto'.
1608
- */
1609
- toolChoice?: LanguageModelV2ToolChoice;
1610
- /**
1611
- Abort signal for cancelling the operation.
1612
- */
1613
- abortSignal?: AbortSignal;
1614
- /**
1615
- Additional HTTP headers to be sent with the request.
1616
- Only applicable for HTTP-based providers.
1617
- */
1618
- 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;
1619
1712
  /**
1620
- * Additional provider-specific options. They are passed through
1621
- * to the provider from the AI SDK and enable provider-specific
1622
- * 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.
1623
1716
  */
1624
- providerOptions?: LanguageModelV2ProviderOptions;
1717
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1625
1718
  };
1626
1719
 
1627
1720
  /**
1628
1721
  Warning from the model provider for this call. The call will proceed, but e.g.
1629
1722
  some settings might not be supported, which can lead to suboptimal results.
1630
1723
  */
1631
- type LanguageModelV2CallWarning = {
1724
+ type LanguageModelV1CallWarning = {
1632
1725
  type: 'unsupported-setting';
1633
- setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
1726
+ setting: keyof LanguageModelV1CallSettings;
1634
1727
  details?: string;
1635
1728
  } | {
1636
1729
  type: 'unsupported-tool';
1637
- tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
1730
+ tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
1638
1731
  details?: string;
1639
1732
  } | {
1640
1733
  type: 'other';
1641
- message: string;
1642
- };
1643
-
1644
- /**
1645
- A file that has been generated by the model.
1646
- */
1647
- type LanguageModelV2File = {
1648
- /**
1649
- The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
1650
-
1651
- @see https://www.iana.org/assignments/media-types/media-types.xhtml
1652
- */
1653
- mediaType: string;
1654
- /**
1655
- Generated file data as base64 encoded strings or binary data.
1656
-
1657
- The file data should be returned without any unnecessary conversion.
1658
- If the API returns base64 encoded strings, the file data should be returned
1659
- as base64 encoded strings. If the API returns binary data, the file data should
1660
- be returned as binary data.
1661
- */
1662
- data: string | Uint8Array;
1663
- };
1664
-
1665
- /**
1666
- Reason why a language model finished generating a response.
1667
-
1668
- Can be one of the following:
1669
- - `stop`: model generated stop sequence
1670
- - `length`: model generated maximum number of tokens
1671
- - `content-filter`: content filter violation stopped the model
1672
- - `tool-calls`: model triggered tool calls
1673
- - `error`: model stopped because of an error
1674
- - `other`: model stopped for other reasons
1675
- - `unknown`: the model has not transmitted a finish reason
1676
- */
1677
- type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
1678
-
1679
- type LanguageModelV2FunctionToolCall = {
1680
- toolCallType: 'function';
1681
- toolCallId: string;
1682
- toolName: string;
1683
- /**
1684
- Stringified JSON object with the tool call arguments. Must match the
1685
- parameters schema of the tool.
1686
- */
1687
- args: string;
1688
- };
1689
-
1690
- /**
1691
- Log probabilities for each token and its top log probabilities.
1692
- */
1693
- type LanguageModelV2LogProbs = Array<{
1694
- token: string;
1695
- logprob: number;
1696
- topLogprobs: Array<{
1697
- token: string;
1698
- logprob: number;
1699
- }>;
1700
- }>;
1701
-
1702
- /**
1703
- * Additional provider-specific metadata.
1704
- * Metadata are additional outputs from the provider.
1705
- * They are passed through to the provider from the AI SDK
1706
- * and enable provider-specific functionality
1707
- * that can be fully encapsulated in the provider.
1708
- *
1709
- * This enables us to quickly ship provider-specific functionality
1710
- * without affecting the core AI SDK.
1711
- *
1712
- * The outer record is keyed by the provider name, and the inner
1713
- * record is keyed by the provider-specific metadata key.
1714
- *
1715
- * ```ts
1716
- * {
1717
- * "anthropic": {
1718
- * "cacheControl": { "type": "ephemeral" }
1719
- * }
1720
- * }
1721
- * ```
1722
- */
1723
- type LanguageModelV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
1724
-
1725
- /**
1726
- * A source that has been used as input to generate the response.
1727
- */
1728
- type LanguageModelV2Source = {
1729
- /**
1730
- * A URL source. This is return by web search RAG models.
1731
- */
1732
- sourceType: 'url';
1733
- /**
1734
- * The ID of the source.
1735
- */
1736
- id: string;
1737
- /**
1738
- * The URL of the source.
1739
- */
1740
- url: string;
1741
- /**
1742
- * The title of the source.
1743
- */
1744
- title?: string;
1745
- /**
1746
- * Additional provider metadata for the source.
1747
- */
1748
- providerMetadata?: LanguageModelV2ProviderMetadata;
1734
+ message: string;
1749
1735
  };
1750
1736
 
1751
1737
  /**
1752
- * Usage information for a language model call.
1738
+ Reason why a language model finished generating a response.
1739
+
1740
+ Can be one of the following:
1741
+ - `stop`: model generated stop sequence
1742
+ - `length`: model generated maximum number of tokens
1743
+ - `content-filter`: content filter violation stopped the model
1744
+ - `tool-calls`: model triggered tool calls
1745
+ - `error`: model stopped because of an error
1746
+ - `other`: model stopped for other reasons
1747
+ - `unknown`: the model has not transmitted a finish reason
1753
1748
  */
1754
- type LanguageModelV2Usage = {
1755
- /**
1756
- * The number of input (prompt) tokens used.
1757
- */
1758
- inputTokens: number | undefined;
1749
+ type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
1750
+
1751
+ type LanguageModelV1FunctionToolCall = {
1752
+ toolCallType: 'function';
1753
+ toolCallId: string;
1754
+ toolName: string;
1759
1755
  /**
1760
- * The number of output (completion) tokens used.
1756
+ Stringified JSON object with the tool call arguments. Must match the
1757
+ parameters schema of the tool.
1761
1758
  */
1762
- outputTokens: number | undefined;
1759
+ args: string;
1763
1760
  };
1764
1761
 
1765
1762
  /**
1766
- Specification for a language model that implements the language model interface version 2.
1763
+ Log probabilities for each token and its top log probabilities.
1767
1764
  */
1768
- type LanguageModelV2 = {
1765
+ type LanguageModelV1LogProbs = Array<{
1766
+ token: string;
1767
+ logprob: number;
1768
+ topLogprobs: Array<{
1769
+ token: string;
1770
+ logprob: number;
1771
+ }>;
1772
+ }>;
1773
+
1774
+ /**
1775
+ Specification for a language model that implements the language model interface version 1.
1776
+ */
1777
+ type LanguageModelV1 = {
1769
1778
  /**
1770
1779
  The language model must specify which language model interface
1771
1780
  version it implements. This will allow us to evolve the language
@@ -1773,7 +1782,7 @@ type LanguageModelV2 = {
1773
1782
  implementation versions can be handled as a discriminated union
1774
1783
  on our side.
1775
1784
  */
1776
- readonly specificationVersion: 'v2';
1785
+ readonly specificationVersion: 'v1';
1777
1786
  /**
1778
1787
  Name of the provider for logging purposes.
1779
1788
  */
@@ -1790,7 +1799,7 @@ type LanguageModelV2 = {
1790
1799
  This is needed to generate the best objects possible w/o requiring the
1791
1800
  user to explicitly specify the object generation mode.
1792
1801
  */
1793
- readonly defaultObjectGenerationMode: LanguageModelV2ObjectGenerationMode;
1802
+ readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
1794
1803
  /**
1795
1804
  Flag whether this model supports image URLs. Default is `true`.
1796
1805
 
@@ -1829,7 +1838,7 @@ type LanguageModelV2 = {
1829
1838
  Naming: "do" prefix to prevent accidental direct usage of the method
1830
1839
  by the user.
1831
1840
  */
1832
- doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
1841
+ doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
1833
1842
  /**
1834
1843
  Text that the model has generated.
1835
1844
  Can be undefined if the model did not generate any text.
@@ -1853,46 +1862,67 @@ An optional signature for verifying that the reasoning originated from the model
1853
1862
  /**
1854
1863
  Generated files as base64 encoded strings or binary data.
1855
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.
1856
1868
  */
1857
- files?: Array<LanguageModelV2File>;
1858
- /**
1859
- Sources that have been used as input to generate the response.
1860
- */
1861
- sources?: LanguageModelV2Source[];
1869
+ files?: Array<{
1870
+ data: string | Uint8Array;
1871
+ mimeType: string;
1872
+ }>;
1862
1873
  /**
1863
1874
  Tool calls that the model has generated.
1864
1875
  Can be undefined if the model did not generate any tool calls.
1865
1876
  */
1866
- toolCalls?: Array<LanguageModelV2FunctionToolCall>;
1867
- /**
1868
- Logprobs for the completion.
1869
- `undefined` if the mode does not support logprobs or if was not enabled
1870
-
1871
- @deprecated will be changed into a provider-specific extension in v2
1872
- */
1873
- logprobs?: LanguageModelV2LogProbs;
1877
+ toolCalls?: Array<LanguageModelV1FunctionToolCall>;
1874
1878
  /**
1875
1879
  Finish reason.
1876
1880
  */
1877
- finishReason: LanguageModelV2FinishReason;
1881
+ finishReason: LanguageModelV1FinishReason;
1878
1882
  /**
1879
1883
  Usage information.
1880
1884
  */
1881
- usage: LanguageModelV2Usage;
1885
+ usage: {
1886
+ promptTokens: number;
1887
+ completionTokens: number;
1888
+ };
1882
1889
  /**
1883
- Additional provider-specific metadata. They are passed through
1884
- from the provider to the AI SDK and enable provider-specific
1885
- results that can be fully encapsulated in the provider.
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.
1886
1906
  */
1887
- providerMetadata?: LanguageModelV2ProviderMetadata;
1907
+ rawResponse?: {
1908
+ /**
1909
+ Response headers.
1910
+ */
1911
+ headers?: Record<string, string>;
1912
+ /**
1913
+ Response body.
1914
+ */
1915
+ body?: unknown;
1916
+ };
1888
1917
  /**
1889
1918
  Optional request information for telemetry and debugging purposes.
1890
1919
  */
1891
1920
  request?: {
1892
1921
  /**
1893
- 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.
1894
1924
  */
1895
- body?: unknown;
1925
+ body?: string;
1896
1926
  };
1897
1927
  /**
1898
1928
  Optional response information for telemetry and debugging purposes.
@@ -1910,19 +1940,25 @@ An optional signature for verifying that the reasoning originated from the model
1910
1940
  The ID of the response model that was used to generate the response, if the provider sends one.
1911
1941
  */
1912
1942
  modelId?: string;
1913
- /**
1914
- Response headers.
1915
- */
1916
- headers?: Record<string, string>;
1917
- /**
1918
- Response HTTP body.
1919
- */
1920
- body?: unknown;
1921
1943
  };
1944
+ warnings?: LanguageModelV1CallWarning[];
1922
1945
  /**
1923
- Warnings for the call, e.g. unsupported settings.
1946
+ Additional provider-specific metadata. They are passed through
1947
+ from the provider to the AI SDK and enable provider-specific
1948
+ results that can be fully encapsulated in the provider.
1924
1949
  */
1925
- warnings?: LanguageModelV2CallWarning[];
1950
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1951
+ /**
1952
+ Sources that have been used as input to generate the response.
1953
+ */
1954
+ sources?: LanguageModelV1Source[];
1955
+ /**
1956
+ Logprobs for the completion.
1957
+ `undefined` if the mode does not support logprobs or if was not enabled
1958
+
1959
+ @deprecated will be changed into a provider-specific extension in v2
1960
+ */
1961
+ logprobs?: LanguageModelV1LogProbs;
1926
1962
  }>;
1927
1963
  /**
1928
1964
  Generates a language model output (streaming).
@@ -1932,33 +1968,49 @@ An optional signature for verifying that the reasoning originated from the model
1932
1968
  *
1933
1969
  @return A stream of higher-level language model output parts.
1934
1970
  */
1935
- doStream(options: LanguageModelV2CallOptions): PromiseLike<{
1936
- stream: ReadableStream<LanguageModelV2StreamPart>;
1971
+ doStream(options: LanguageModelV1CallOptions): PromiseLike<{
1972
+ stream: ReadableStream<LanguageModelV1StreamPart>;
1937
1973
  /**
1938
- Optional request information for telemetry and debugging purposes.
1974
+ Raw prompt and setting information for observability provider integration.
1939
1975
  */
1940
- request?: {
1976
+ rawCall: {
1941
1977
  /**
1942
- Request HTTP body that was sent to the provider API.
1943
- */
1944
- 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>;
1945
1987
  };
1946
1988
  /**
1947
1989
  Optional raw response data.
1948
1990
  */
1949
- response?: {
1991
+ rawResponse?: {
1950
1992
  /**
1951
1993
  Response headers.
1952
1994
  */
1953
1995
  headers?: Record<string, string>;
1954
1996
  };
1955
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
+ /**
1956
2008
  Warnings for the call, e.g. unsupported settings.
1957
2009
  */
1958
- warnings?: Array<LanguageModelV2CallWarning>;
2010
+ warnings?: Array<LanguageModelV1CallWarning>;
1959
2011
  }>;
1960
2012
  };
1961
- type LanguageModelV2StreamPart = {
2013
+ type LanguageModelV1StreamPart = {
1962
2014
  type: 'text-delta';
1963
2015
  textDelta: string;
1964
2016
  } | {
@@ -1972,12 +2024,21 @@ type LanguageModelV2StreamPart = {
1972
2024
  data: string;
1973
2025
  } | {
1974
2026
  type: 'source';
1975
- source: LanguageModelV2Source;
1976
- } | ({
2027
+ source: LanguageModelV1Source;
2028
+ } | {
1977
2029
  type: 'file';
1978
- } & LanguageModelV2File) | ({
2030
+ mimeType: string;
2031
+ /**
2032
+ Generated file data as base64 encoded strings or binary data.
2033
+ The file data should be returned without any unnecessary conversion.
2034
+ If the API returns base64 encoded strings, the file data should be returned
2035
+ as base64 encoded strings. If the API returns binary data, the file data should
2036
+ be returned as binary data.
2037
+ */
2038
+ data: string | Uint8Array;
2039
+ } | ({
1979
2040
  type: 'tool-call';
1980
- } & LanguageModelV2FunctionToolCall) | {
2041
+ } & LanguageModelV1FunctionToolCall) | {
1981
2042
  type: 'tool-call-delta';
1982
2043
  toolCallType: 'function';
1983
2044
  toolCallId: string;
@@ -1990,10 +2051,13 @@ type LanguageModelV2StreamPart = {
1990
2051
  modelId?: string;
1991
2052
  } | {
1992
2053
  type: 'finish';
1993
- finishReason: LanguageModelV2FinishReason;
1994
- providerMetadata?: LanguageModelV2ProviderMetadata;
1995
- usage: LanguageModelV2Usage;
1996
- logprobs?: LanguageModelV2LogProbs;
2054
+ finishReason: LanguageModelV1FinishReason;
2055
+ providerMetadata?: LanguageModelV1ProviderMetadata;
2056
+ usage: {
2057
+ promptTokens: number;
2058
+ completionTokens: number;
2059
+ };
2060
+ logprobs?: LanguageModelV1LogProbs;
1997
2061
  } | {
1998
2062
  type: 'error';
1999
2063
  error: unknown;
@@ -2002,67 +2066,7 @@ type LanguageModelV2StreamPart = {
2002
2066
  The object generation modes available for use with a model. `undefined`
2003
2067
  represents no support for object generation.
2004
2068
  */
2005
- type LanguageModelV2ObjectGenerationMode = 'json' | 'tool' | undefined;
2006
-
2007
- /**
2008
- * Experimental middleware for LanguageModelV2.
2009
- * This type defines the structure for middleware that can be used to modify
2010
- * the behavior of LanguageModelV2 operations.
2011
- */
2012
- type LanguageModelV2Middleware = {
2013
- /**
2014
- * Middleware specification version. Use `v2` for the current version.
2015
- */
2016
- middlewareVersion?: 'v2' | undefined;
2017
- /**
2018
- * Transforms the parameters before they are passed to the language model.
2019
- * @param options - Object containing the type of operation and the parameters.
2020
- * @param options.type - The type of operation ('generate' or 'stream').
2021
- * @param options.params - The original parameters for the language model call.
2022
- * @returns A promise that resolves to the transformed parameters.
2023
- */
2024
- transformParams?: (options: {
2025
- type: 'generate' | 'stream';
2026
- params: LanguageModelV2CallOptions;
2027
- }) => PromiseLike<LanguageModelV2CallOptions>;
2028
- /**
2029
- * Wraps the generate operation of the language model.
2030
- * @param options - Object containing the generate function, parameters, and model.
2031
- * @param options.doGenerate - The original generate function.
2032
- * @param options.doStream - The original stream function.
2033
- * @param options.params - The parameters for the generate call. If the
2034
- * `transformParams` middleware is used, this will be the transformed parameters.
2035
- * @param options.model - The language model instance.
2036
- * @returns A promise that resolves to the result of the generate operation.
2037
- */
2038
- wrapGenerate?: (options: {
2039
- doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
2040
- doStream: () => ReturnType<LanguageModelV2['doStream']>;
2041
- params: LanguageModelV2CallOptions;
2042
- model: LanguageModelV2;
2043
- }) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
2044
- /**
2045
- * Wraps the stream operation of the language model.
2046
- *
2047
- * @param options - Object containing the stream function, parameters, and model.
2048
- * @param options.doGenerate - The original generate function.
2049
- * @param options.doStream - The original stream function.
2050
- * @param options.params - The parameters for the stream call. If the
2051
- * `transformParams` middleware is used, this will be the transformed parameters.
2052
- * @param options.model - The language model instance.
2053
- * @returns A promise that resolves to the result of the stream operation.
2054
- */
2055
- wrapStream?: (options: {
2056
- doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
2057
- doStream: () => ReturnType<LanguageModelV2['doStream']>;
2058
- params: LanguageModelV2CallOptions;
2059
- model: LanguageModelV2;
2060
- }) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
2061
- };
2062
- /**
2063
- * @deprecated Use `LanguageModelV2Middleware` instead.
2064
- */
2065
- type Experimental_LanguageModelV2Middleware = LanguageModelV2Middleware;
2069
+ type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
2066
2070
 
2067
2071
  type TranscriptionModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
2068
2072
  type TranscriptionModelV1CallOptions = {
@@ -2241,7 +2245,7 @@ interface ProviderV1 {
2241
2245
 
2242
2246
  @throws {NoSuchModelError} If no such model exists.
2243
2247
  */
2244
- textEmbeddingModel(modelId: string): EmbeddingModelV1<string>;
2248
+ textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
2245
2249
  /**
2246
2250
  Returns the image model with the given id.
2247
2251
  The model id is then passed to the provider function to get the model.
@@ -2287,7 +2291,7 @@ interface ProviderV2 {
2287
2291
 
2288
2292
  @throws {NoSuchModelError} If no such model exists.
2289
2293
  */
2290
- textEmbeddingModel(modelId: string): EmbeddingModelV1<string>;
2294
+ textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
2291
2295
  /**
2292
2296
  Returns the image model with the given id.
2293
2297
  The model id is then passed to the provider function to get the model.
@@ -2299,4 +2303,4 @@ interface ProviderV2 {
2299
2303
  readonly imageModel: (modelId: string) => ImageModelV1;
2300
2304
  }
2301
2305
 
2302
- 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 LanguageModelV2DataContent, type LanguageModelV2File, 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, type LanguageModelV2Usage, 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 };