@ai-sdk/provider 2.0.0-canary.8 → 2.0.0
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/CHANGELOG.md +311 -0
- package/dist/index.d.mts +414 -1103
- package/dist/index.d.ts +414 -1103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
import { JSONSchema7 } from 'json-schema';
|
2
2
|
export { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
3
3
|
|
4
|
+
type SharedV2Headers = Record<string, string>;
|
5
|
+
|
6
|
+
/**
|
7
|
+
A JSON value can be a string, number, boolean, object, array, or null.
|
8
|
+
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
|
9
|
+
*/
|
4
10
|
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
5
11
|
type JSONObject = {
|
6
12
|
[key: string]: JSONValue;
|
@@ -86,12 +92,14 @@ type EmbeddingModelV2<VALUE> = {
|
|
86
92
|
readonly modelId: string;
|
87
93
|
/**
|
88
94
|
Limit of how many embeddings can be generated in a single API call.
|
95
|
+
|
96
|
+
Use Infinity for models that do not have a limit.
|
89
97
|
*/
|
90
|
-
readonly maxEmbeddingsPerCall: number | undefined;
|
98
|
+
readonly maxEmbeddingsPerCall: PromiseLike<number | undefined> | number | undefined;
|
91
99
|
/**
|
92
100
|
True if the model can handle multiple embedding calls in parallel.
|
93
101
|
*/
|
94
|
-
readonly supportsParallelCalls: boolean;
|
102
|
+
readonly supportsParallelCalls: PromiseLike<boolean> | boolean;
|
95
103
|
/**
|
96
104
|
Generates a list of embeddings for the given input text.
|
97
105
|
|
@@ -130,13 +138,19 @@ type EmbeddingModelV2<VALUE> = {
|
|
130
138
|
tokens: number;
|
131
139
|
};
|
132
140
|
/**
|
141
|
+
Additional provider-specific metadata. They are passed through
|
142
|
+
from the provider to the AI SDK and enable provider-specific
|
143
|
+
results that can be fully encapsulated in the provider.
|
144
|
+
*/
|
145
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
146
|
+
/**
|
133
147
|
Optional response information for debugging purposes.
|
134
148
|
*/
|
135
149
|
response?: {
|
136
150
|
/**
|
137
151
|
Response headers.
|
138
152
|
*/
|
139
|
-
headers?:
|
153
|
+
headers?: SharedV2Headers;
|
140
154
|
/**
|
141
155
|
The response body.
|
142
156
|
*/
|
@@ -305,11 +319,11 @@ declare const symbol$3: unique symbol;
|
|
305
319
|
declare class NoSuchModelError extends AISDKError {
|
306
320
|
private readonly [symbol$3];
|
307
321
|
readonly modelId: string;
|
308
|
-
readonly modelType: 'languageModel' | 'textEmbeddingModel' | 'imageModel';
|
322
|
+
readonly modelType: 'languageModel' | 'textEmbeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel';
|
309
323
|
constructor({ errorName, modelId, modelType, message, }: {
|
310
324
|
errorName?: string;
|
311
325
|
modelId: string;
|
312
|
-
modelType: 'languageModel' | 'textEmbeddingModel' | 'imageModel';
|
326
|
+
modelType: 'languageModel' | 'textEmbeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel';
|
313
327
|
message?: string;
|
314
328
|
});
|
315
329
|
static isInstance(error: unknown): error is NoSuchModelError;
|
@@ -367,7 +381,11 @@ declare class UnsupportedFunctionalityError extends AISDKError {
|
|
367
381
|
static isInstance(error: unknown): error is UnsupportedFunctionalityError;
|
368
382
|
}
|
369
383
|
|
370
|
-
|
384
|
+
declare function isJSONValue(value: unknown): value is JSONValue;
|
385
|
+
declare function isJSONArray(value: unknown): value is JSONArray;
|
386
|
+
declare function isJSONObject(value: unknown): value is JSONObject;
|
387
|
+
|
388
|
+
type ImageModelV2CallOptions = {
|
371
389
|
/**
|
372
390
|
Prompt for the image generation.
|
373
391
|
*/
|
@@ -401,13 +419,13 @@ type ImageModelV1CallOptions = {
|
|
401
419
|
record is keyed by the provider-specific metadata key.
|
402
420
|
```ts
|
403
421
|
{
|
404
|
-
|
405
|
-
|
406
|
-
|
422
|
+
"openai": {
|
423
|
+
"style": "vivid"
|
424
|
+
}
|
407
425
|
}
|
408
426
|
```
|
409
427
|
*/
|
410
|
-
providerOptions:
|
428
|
+
providerOptions: SharedV2ProviderOptions;
|
411
429
|
/**
|
412
430
|
Abort signal for cancelling the operation.
|
413
431
|
*/
|
@@ -423,19 +441,25 @@ type ImageModelV1CallOptions = {
|
|
423
441
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
424
442
|
some settings might not be supported, which can lead to suboptimal results.
|
425
443
|
*/
|
426
|
-
type
|
444
|
+
type ImageModelV2CallWarning = {
|
427
445
|
type: 'unsupported-setting';
|
428
|
-
setting: keyof
|
446
|
+
setting: keyof ImageModelV2CallOptions;
|
429
447
|
details?: string;
|
430
448
|
} | {
|
431
449
|
type: 'other';
|
432
450
|
message: string;
|
433
451
|
};
|
434
452
|
|
453
|
+
type ImageModelV2ProviderMetadata = Record<string, {
|
454
|
+
images: JSONArray;
|
455
|
+
} & JSONValue>;
|
456
|
+
type GetMaxImagesPerCallFunction = (options: {
|
457
|
+
modelId: string;
|
458
|
+
}) => PromiseLike<number | undefined> | number | undefined;
|
435
459
|
/**
|
436
|
-
Image generation model specification version
|
460
|
+
Image generation model specification version 2.
|
437
461
|
*/
|
438
|
-
type
|
462
|
+
type ImageModelV2 = {
|
439
463
|
/**
|
440
464
|
The image model must specify which image model interface
|
441
465
|
version it implements. This will allow us to evolve the image
|
@@ -443,7 +467,7 @@ type ImageModelV1 = {
|
|
443
467
|
implementation versions can be handled as a discriminated union
|
444
468
|
on our side.
|
445
469
|
*/
|
446
|
-
readonly specificationVersion: '
|
470
|
+
readonly specificationVersion: 'v2';
|
447
471
|
/**
|
448
472
|
Name of the provider for logging purposes.
|
449
473
|
*/
|
@@ -454,13 +478,15 @@ type ImageModelV1 = {
|
|
454
478
|
readonly modelId: string;
|
455
479
|
/**
|
456
480
|
Limit of how many images can be generated in a single API call.
|
457
|
-
|
481
|
+
Can be set to a number for a fixed limit, to undefined to use
|
482
|
+
the global limit, or a function that returns a number or undefined,
|
483
|
+
optionally as a promise.
|
458
484
|
*/
|
459
|
-
readonly maxImagesPerCall: number | undefined;
|
485
|
+
readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction;
|
460
486
|
/**
|
461
487
|
Generates an array of images.
|
462
488
|
*/
|
463
|
-
doGenerate(options:
|
489
|
+
doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
|
464
490
|
/**
|
465
491
|
Generated images as base64 encoded strings or binary data.
|
466
492
|
The images should be returned without any unnecessary conversion.
|
@@ -472,7 +498,25 @@ type ImageModelV1 = {
|
|
472
498
|
/**
|
473
499
|
Warnings for the call, e.g. unsupported settings.
|
474
500
|
*/
|
475
|
-
warnings: Array<
|
501
|
+
warnings: Array<ImageModelV2CallWarning>;
|
502
|
+
/**
|
503
|
+
Additional provider-specific metadata. They are passed through
|
504
|
+
from the provider to the AI SDK and enable provider-specific
|
505
|
+
results that can be fully encapsulated in the provider.
|
506
|
+
|
507
|
+
The outer record is keyed by the provider name, and the inner
|
508
|
+
record is provider-specific metadata. It always includes an
|
509
|
+
`images` key with image-specific metadata
|
510
|
+
|
511
|
+
```ts
|
512
|
+
{
|
513
|
+
"openai": {
|
514
|
+
"images": ["revisedPrompt": "Revised prompt here."]
|
515
|
+
}
|
516
|
+
}
|
517
|
+
```
|
518
|
+
*/
|
519
|
+
providerMetadata?: ImageModelV2ProviderMetadata;
|
476
520
|
/**
|
477
521
|
Response information for telemetry and debugging purposes.
|
478
522
|
*/
|
@@ -493,10 +537,6 @@ type ImageModelV1 = {
|
|
493
537
|
}>;
|
494
538
|
};
|
495
539
|
|
496
|
-
declare function isJSONValue(value: unknown): value is JSONValue;
|
497
|
-
declare function isJSONArray(value: unknown): value is JSONArray;
|
498
|
-
declare function isJSONObject(value: unknown): value is JSONObject;
|
499
|
-
|
500
540
|
/**
|
501
541
|
A tool has a name, a description, and a set of parameters.
|
502
542
|
|
@@ -521,7 +561,11 @@ type LanguageModelV2FunctionTool = {
|
|
521
561
|
The parameters that the tool expects. The language model uses this to
|
522
562
|
understand the tool's input requirements and to provide matching suggestions.
|
523
563
|
*/
|
524
|
-
|
564
|
+
inputSchema: JSONSchema7;
|
565
|
+
/**
|
566
|
+
The provider-specific options for the tool.
|
567
|
+
*/
|
568
|
+
providerOptions?: SharedV2ProviderOptions;
|
525
569
|
};
|
526
570
|
|
527
571
|
/**
|
@@ -547,7 +591,7 @@ type LanguageModelV2Message = ({
|
|
547
591
|
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
|
548
592
|
} | {
|
549
593
|
role: 'assistant';
|
550
|
-
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart |
|
594
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart | LanguageModelV2ToolResultPart>;
|
551
595
|
} | {
|
552
596
|
role: 'tool';
|
553
597
|
content: Array<LanguageModelV2ToolResultPart>;
|
@@ -585,26 +629,6 @@ interface LanguageModelV2ReasoningPart {
|
|
585
629
|
*/
|
586
630
|
text: string;
|
587
631
|
/**
|
588
|
-
An optional signature for verifying that the reasoning originated from the model.
|
589
|
-
*/
|
590
|
-
signature?: string;
|
591
|
-
/**
|
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.
|
595
|
-
*/
|
596
|
-
providerOptions?: SharedV2ProviderOptions;
|
597
|
-
}
|
598
|
-
/**
|
599
|
-
Redacted reasoning content part of a prompt.
|
600
|
-
*/
|
601
|
-
interface LanguageModelV2RedactedReasoningPart {
|
602
|
-
type: 'redacted-reasoning';
|
603
|
-
/**
|
604
|
-
Redacted reasoning data.
|
605
|
-
*/
|
606
|
-
data: string;
|
607
|
-
/**
|
608
632
|
* Additional provider-specific options. They are passed through
|
609
633
|
* to the provider from the AI SDK and enable provider-specific
|
610
634
|
* functionality that can be fully encapsulated in the provider.
|
@@ -655,7 +679,12 @@ interface LanguageModelV2ToolCallPart {
|
|
655
679
|
/**
|
656
680
|
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
657
681
|
*/
|
658
|
-
|
682
|
+
input: unknown;
|
683
|
+
/**
|
684
|
+
* Whether the tool call will be executed by the provider.
|
685
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
686
|
+
*/
|
687
|
+
providerExecuted?: boolean;
|
659
688
|
/**
|
660
689
|
* Additional provider-specific options. They are passed through
|
661
690
|
* to the provider from the AI SDK and enable provider-specific
|
@@ -677,43 +706,49 @@ interface LanguageModelV2ToolResultPart {
|
|
677
706
|
*/
|
678
707
|
toolName: string;
|
679
708
|
/**
|
680
|
-
Result of the tool call.
|
681
|
-
*/
|
682
|
-
result: unknown;
|
683
|
-
/**
|
684
|
-
Optional flag if the result is an error or an error message.
|
709
|
+
Result of the tool call.
|
685
710
|
*/
|
686
|
-
|
711
|
+
output: LanguageModelV2ToolResultOutput;
|
687
712
|
/**
|
688
|
-
|
689
|
-
|
713
|
+
* Additional provider-specific options. They are passed through
|
714
|
+
* to the provider from the AI SDK and enable provider-specific
|
715
|
+
* functionality that can be fully encapsulated in the provider.
|
690
716
|
*/
|
691
|
-
|
717
|
+
providerOptions?: SharedV2ProviderOptions;
|
718
|
+
}
|
719
|
+
type LanguageModelV2ToolResultOutput = {
|
720
|
+
type: 'text';
|
721
|
+
value: string;
|
722
|
+
} | {
|
723
|
+
type: 'json';
|
724
|
+
value: JSONValue;
|
725
|
+
} | {
|
726
|
+
type: 'error-text';
|
727
|
+
value: string;
|
728
|
+
} | {
|
729
|
+
type: 'error-json';
|
730
|
+
value: JSONValue;
|
731
|
+
} | {
|
732
|
+
type: 'content';
|
733
|
+
value: Array<{
|
692
734
|
type: 'text';
|
693
735
|
/**
|
694
736
|
Text content.
|
695
|
-
|
737
|
+
*/
|
696
738
|
text: string;
|
697
739
|
} | {
|
698
|
-
type: '
|
740
|
+
type: 'media';
|
699
741
|
/**
|
700
|
-
|
701
|
-
|
742
|
+
Base-64 encoded media data.
|
743
|
+
*/
|
702
744
|
data: string;
|
703
745
|
/**
|
704
|
-
IANA media type
|
705
|
-
|
746
|
+
IANA media type.
|
706
747
|
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
707
|
-
|
708
|
-
mediaType
|
748
|
+
*/
|
749
|
+
mediaType: string;
|
709
750
|
}>;
|
710
|
-
|
711
|
-
* Additional provider-specific options. They are passed through
|
712
|
-
* to the provider from the AI SDK and enable provider-specific
|
713
|
-
* functionality that can be fully encapsulated in the provider.
|
714
|
-
*/
|
715
|
-
providerOptions?: SharedV2ProviderOptions;
|
716
|
-
}
|
751
|
+
};
|
717
752
|
|
718
753
|
/**
|
719
754
|
The configuration of a tool that is defined by the provider.
|
@@ -724,11 +759,11 @@ type LanguageModelV2ProviderDefinedTool = {
|
|
724
759
|
*/
|
725
760
|
type: 'provider-defined';
|
726
761
|
/**
|
727
|
-
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
762
|
+
The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
|
728
763
|
*/
|
729
764
|
id: `${string}.${string}`;
|
730
765
|
/**
|
731
|
-
The name of the tool
|
766
|
+
The name of the tool that the user must use in the tool set.
|
732
767
|
*/
|
733
768
|
name: string;
|
734
769
|
/**
|
@@ -750,13 +785,6 @@ type LanguageModelV2ToolChoice = {
|
|
750
785
|
|
751
786
|
type LanguageModelV2CallOptions = {
|
752
787
|
/**
|
753
|
-
Whether the user provided the input as messages or as
|
754
|
-
a prompt. This can help guide non-chat models in the
|
755
|
-
expansion, bc different expansions can be needed for
|
756
|
-
chat/non-chat use cases.
|
757
|
-
*/
|
758
|
-
inputFormat: 'messages' | 'prompt';
|
759
|
-
/**
|
760
788
|
A language mode prompt is a standardized prompt type.
|
761
789
|
|
762
790
|
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
@@ -770,9 +798,7 @@ type LanguageModelV2CallOptions = {
|
|
770
798
|
*/
|
771
799
|
maxOutputTokens?: number;
|
772
800
|
/**
|
773
|
-
Temperature setting.
|
774
|
-
|
775
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
801
|
+
Temperature setting. The range depends on the provider and model.
|
776
802
|
*/
|
777
803
|
temperature?: number;
|
778
804
|
/**
|
@@ -783,8 +809,6 @@ type LanguageModelV2CallOptions = {
|
|
783
809
|
stopSequences?: string[];
|
784
810
|
/**
|
785
811
|
Nucleus sampling.
|
786
|
-
|
787
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
788
812
|
*/
|
789
813
|
topP?: number;
|
790
814
|
/**
|
@@ -840,6 +864,10 @@ type LanguageModelV2CallOptions = {
|
|
840
864
|
*/
|
841
865
|
toolChoice?: LanguageModelV2ToolChoice;
|
842
866
|
/**
|
867
|
+
Include raw chunks in the stream. Only applicable for streaming calls.
|
868
|
+
*/
|
869
|
+
includeRawChunks?: boolean;
|
870
|
+
/**
|
843
871
|
Abort signal for cancelling the operation.
|
844
872
|
*/
|
845
873
|
abortSignal?: AbortSignal;
|
@@ -902,16 +930,11 @@ Reasoning that the model has generated.
|
|
902
930
|
*/
|
903
931
|
type LanguageModelV2Reasoning = {
|
904
932
|
type: 'reasoning';
|
905
|
-
reasoningType: 'text';
|
906
933
|
text: string;
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
} | {
|
912
|
-
type: 'reasoning';
|
913
|
-
reasoningType: 'redacted';
|
914
|
-
data: string;
|
934
|
+
/**
|
935
|
+
* Optional provider-specific metadata for the reasoning part.
|
936
|
+
*/
|
937
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
915
938
|
};
|
916
939
|
|
917
940
|
/**
|
@@ -920,7 +943,7 @@ A source that has been used as input to generate the response.
|
|
920
943
|
type LanguageModelV2Source = {
|
921
944
|
type: 'source';
|
922
945
|
/**
|
923
|
-
*
|
946
|
+
* The type of source - URL sources reference web content.
|
924
947
|
*/
|
925
948
|
sourceType: 'url';
|
926
949
|
/**
|
@@ -939,6 +962,32 @@ type LanguageModelV2Source = {
|
|
939
962
|
* Additional provider metadata for the source.
|
940
963
|
*/
|
941
964
|
providerMetadata?: SharedV2ProviderMetadata;
|
965
|
+
} | {
|
966
|
+
type: 'source';
|
967
|
+
/**
|
968
|
+
* The type of source - document sources reference files/documents.
|
969
|
+
*/
|
970
|
+
sourceType: 'document';
|
971
|
+
/**
|
972
|
+
* The ID of the source.
|
973
|
+
*/
|
974
|
+
id: string;
|
975
|
+
/**
|
976
|
+
* IANA media type of the document (e.g., 'application/pdf').
|
977
|
+
*/
|
978
|
+
mediaType: string;
|
979
|
+
/**
|
980
|
+
* The title of the document.
|
981
|
+
*/
|
982
|
+
title: string;
|
983
|
+
/**
|
984
|
+
* Optional filename of the document.
|
985
|
+
*/
|
986
|
+
filename?: string;
|
987
|
+
/**
|
988
|
+
* Additional provider metadata for the source.
|
989
|
+
*/
|
990
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
942
991
|
};
|
943
992
|
|
944
993
|
/**
|
@@ -950,6 +999,7 @@ type LanguageModelV2Text = {
|
|
950
999
|
The text content.
|
951
1000
|
*/
|
952
1001
|
text: string;
|
1002
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
953
1003
|
};
|
954
1004
|
|
955
1005
|
/**
|
@@ -957,17 +1007,58 @@ Tool calls that the model has generated.
|
|
957
1007
|
*/
|
958
1008
|
type LanguageModelV2ToolCall = {
|
959
1009
|
type: 'tool-call';
|
960
|
-
toolCallType: 'function';
|
961
1010
|
toolCallId: string;
|
962
1011
|
toolName: string;
|
963
1012
|
/**
|
964
1013
|
Stringified JSON object with the tool call arguments. Must match the
|
965
1014
|
parameters schema of the tool.
|
966
1015
|
*/
|
967
|
-
|
1016
|
+
input: string;
|
1017
|
+
/**
|
1018
|
+
* Whether the tool call will be executed by the provider.
|
1019
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
1020
|
+
*/
|
1021
|
+
providerExecuted?: boolean;
|
1022
|
+
/**
|
1023
|
+
* Additional provider-specific metadata for the tool call.
|
1024
|
+
*/
|
1025
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1026
|
+
};
|
1027
|
+
|
1028
|
+
/**
|
1029
|
+
Result of a tool call that has been executed by the provider.
|
1030
|
+
*/
|
1031
|
+
type LanguageModelV2ToolResult = {
|
1032
|
+
type: 'tool-result';
|
1033
|
+
/**
|
1034
|
+
* The ID of the tool call that this result is associated with.
|
1035
|
+
*/
|
1036
|
+
toolCallId: string;
|
1037
|
+
/**
|
1038
|
+
* Name of the tool that generated this result.
|
1039
|
+
*/
|
1040
|
+
toolName: string;
|
1041
|
+
/**
|
1042
|
+
* Result of the tool call. This is a JSON-serializable object.
|
1043
|
+
*/
|
1044
|
+
result: unknown;
|
1045
|
+
/**
|
1046
|
+
* Optional flag if the result is an error or an error message.
|
1047
|
+
*/
|
1048
|
+
isError?: boolean;
|
1049
|
+
/**
|
1050
|
+
* Whether the tool result was generated by the provider.
|
1051
|
+
* If this flag is set to true, the tool result was generated by the provider.
|
1052
|
+
* If this flag is not set or is false, the tool result was generated by the client.
|
1053
|
+
*/
|
1054
|
+
providerExecuted?: boolean;
|
1055
|
+
/**
|
1056
|
+
* Additional provider-specific metadata for the tool result.
|
1057
|
+
*/
|
1058
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
968
1059
|
};
|
969
1060
|
|
970
|
-
type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall;
|
1061
|
+
type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall | LanguageModelV2ToolResult;
|
971
1062
|
|
972
1063
|
/**
|
973
1064
|
Reason why a language model finished generating a response.
|
@@ -983,38 +1074,109 @@ Can be one of the following:
|
|
983
1074
|
*/
|
984
1075
|
type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
985
1076
|
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
toolCallType: 'function';
|
1001
|
-
toolCallId: string;
|
1002
|
-
toolName: string;
|
1003
|
-
argsTextDelta: string;
|
1004
|
-
};
|
1077
|
+
interface LanguageModelV2ResponseMetadata {
|
1078
|
+
/**
|
1079
|
+
ID for the generated response, if the provider sends one.
|
1080
|
+
*/
|
1081
|
+
id?: string;
|
1082
|
+
/**
|
1083
|
+
Timestamp for the start of the generated response, if the provider sends one.
|
1084
|
+
*/
|
1085
|
+
timestamp?: Date;
|
1086
|
+
/**
|
1087
|
+
The ID of the response model that was used to generate the response, if the provider sends one.
|
1088
|
+
*/
|
1089
|
+
modelId?: string;
|
1090
|
+
}
|
1005
1091
|
|
1006
1092
|
/**
|
1007
|
-
|
1093
|
+
Usage information for a language model call.
|
1094
|
+
|
1095
|
+
If your API return additional usage information, you can add it to the
|
1096
|
+
provider metadata under your provider's key.
|
1008
1097
|
*/
|
1009
1098
|
type LanguageModelV2Usage = {
|
1010
1099
|
/**
|
1011
|
-
|
1100
|
+
The number of input (prompt) tokens used.
|
1012
1101
|
*/
|
1013
1102
|
inputTokens: number | undefined;
|
1014
1103
|
/**
|
1015
|
-
|
1104
|
+
The number of output (completion) tokens used.
|
1016
1105
|
*/
|
1017
1106
|
outputTokens: number | undefined;
|
1107
|
+
/**
|
1108
|
+
The total number of tokens as reported by the provider.
|
1109
|
+
This number might be different from the sum of `inputTokens` and `outputTokens`
|
1110
|
+
and e.g. include reasoning tokens or other overhead.
|
1111
|
+
*/
|
1112
|
+
totalTokens: number | undefined;
|
1113
|
+
/**
|
1114
|
+
The number of reasoning tokens used.
|
1115
|
+
*/
|
1116
|
+
reasoningTokens?: number | undefined;
|
1117
|
+
/**
|
1118
|
+
The number of cached input tokens.
|
1119
|
+
*/
|
1120
|
+
cachedInputTokens?: number | undefined;
|
1121
|
+
};
|
1122
|
+
|
1123
|
+
type LanguageModelV2StreamPart = {
|
1124
|
+
type: 'text-start';
|
1125
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1126
|
+
id: string;
|
1127
|
+
} | {
|
1128
|
+
type: 'text-delta';
|
1129
|
+
id: string;
|
1130
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1131
|
+
delta: string;
|
1132
|
+
} | {
|
1133
|
+
type: 'text-end';
|
1134
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1135
|
+
id: string;
|
1136
|
+
} | {
|
1137
|
+
type: 'reasoning-start';
|
1138
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1139
|
+
id: string;
|
1140
|
+
} | {
|
1141
|
+
type: 'reasoning-delta';
|
1142
|
+
id: string;
|
1143
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1144
|
+
delta: string;
|
1145
|
+
} | {
|
1146
|
+
type: 'reasoning-end';
|
1147
|
+
id: string;
|
1148
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1149
|
+
} | {
|
1150
|
+
type: 'tool-input-start';
|
1151
|
+
id: string;
|
1152
|
+
toolName: string;
|
1153
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1154
|
+
providerExecuted?: boolean;
|
1155
|
+
} | {
|
1156
|
+
type: 'tool-input-delta';
|
1157
|
+
id: string;
|
1158
|
+
delta: string;
|
1159
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1160
|
+
} | {
|
1161
|
+
type: 'tool-input-end';
|
1162
|
+
id: string;
|
1163
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1164
|
+
} | LanguageModelV2ToolCall | LanguageModelV2ToolResult | LanguageModelV2File | LanguageModelV2Source | {
|
1165
|
+
type: 'stream-start';
|
1166
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
1167
|
+
} | ({
|
1168
|
+
type: 'response-metadata';
|
1169
|
+
} & LanguageModelV2ResponseMetadata) | {
|
1170
|
+
type: 'finish';
|
1171
|
+
usage: LanguageModelV2Usage;
|
1172
|
+
finishReason: LanguageModelV2FinishReason;
|
1173
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1174
|
+
} | {
|
1175
|
+
type: 'raw';
|
1176
|
+
rawValue: unknown;
|
1177
|
+
} | {
|
1178
|
+
type: 'error';
|
1179
|
+
error: unknown;
|
1018
1180
|
};
|
1019
1181
|
|
1020
1182
|
/**
|
@@ -1022,11 +1184,7 @@ Specification for a language model that implements the language model interface
|
|
1022
1184
|
*/
|
1023
1185
|
type LanguageModelV2 = {
|
1024
1186
|
/**
|
1025
|
-
The language model must specify which language model interface
|
1026
|
-
version it implements. This will allow us to evolve the language
|
1027
|
-
model interface and retain backwards compatibility. The different
|
1028
|
-
implementation versions can be handled as a discriminated union
|
1029
|
-
on our side.
|
1187
|
+
The language model must specify which language model interface version it implements.
|
1030
1188
|
*/
|
1031
1189
|
readonly specificationVersion: 'v2';
|
1032
1190
|
/**
|
@@ -1038,17 +1196,18 @@ type LanguageModelV2 = {
|
|
1038
1196
|
*/
|
1039
1197
|
readonly modelId: string;
|
1040
1198
|
/**
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1199
|
+
Supported URL patterns by media type for the provider.
|
1200
|
+
|
1201
|
+
The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
|
1202
|
+
and the values are arrays of regular expressions that match the URL paths.
|
1203
|
+
|
1204
|
+
The matching should be against lower-case URLs.
|
1205
|
+
|
1206
|
+
Matched URLs are supported natively by the model and are not downloaded.
|
1207
|
+
|
1208
|
+
@returns A map of supported URL patterns by media type (as a promise or a plain object).
|
1050
1209
|
*/
|
1051
|
-
|
1210
|
+
supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
1052
1211
|
/**
|
1053
1212
|
Generates a language model output (non-streaming).
|
1054
1213
|
|
@@ -1061,13 +1220,6 @@ type LanguageModelV2 = {
|
|
1061
1220
|
*/
|
1062
1221
|
content: Array<LanguageModelV2Content>;
|
1063
1222
|
/**
|
1064
|
-
Logprobs for the completion.
|
1065
|
-
`undefined` if the mode does not support logprobs or if was not enabled
|
1066
|
-
|
1067
|
-
@deprecated will be changed into a provider-specific extension in v2
|
1068
|
-
*/
|
1069
|
-
logprobs?: LanguageModelV2LogProbs;
|
1070
|
-
/**
|
1071
1223
|
Finish reason.
|
1072
1224
|
*/
|
1073
1225
|
finishReason: LanguageModelV2FinishReason;
|
@@ -1093,23 +1245,11 @@ type LanguageModelV2 = {
|
|
1093
1245
|
/**
|
1094
1246
|
Optional response information for telemetry and debugging purposes.
|
1095
1247
|
*/
|
1096
|
-
response?: {
|
1097
|
-
/**
|
1098
|
-
ID for the generated response, if the provider sends one.
|
1099
|
-
*/
|
1100
|
-
id?: string;
|
1101
|
-
/**
|
1102
|
-
Timestamp for the start of the generated response, if the provider sends one.
|
1103
|
-
*/
|
1104
|
-
timestamp?: Date;
|
1105
|
-
/**
|
1106
|
-
The ID of the response model that was used to generate the response, if the provider sends one.
|
1107
|
-
*/
|
1108
|
-
modelId?: string;
|
1248
|
+
response?: LanguageModelV2ResponseMetadata & {
|
1109
1249
|
/**
|
1110
1250
|
Response headers.
|
1111
1251
|
*/
|
1112
|
-
headers?:
|
1252
|
+
headers?: SharedV2Headers;
|
1113
1253
|
/**
|
1114
1254
|
Response HTTP body.
|
1115
1255
|
*/
|
@@ -1146,28 +1286,10 @@ type LanguageModelV2 = {
|
|
1146
1286
|
/**
|
1147
1287
|
Response headers.
|
1148
1288
|
*/
|
1149
|
-
headers?:
|
1289
|
+
headers?: SharedV2Headers;
|
1150
1290
|
};
|
1151
1291
|
}>;
|
1152
1292
|
};
|
1153
|
-
type LanguageModelV2StreamPart = LanguageModelV2Content | LanguageModelV2ToolCallDelta | {
|
1154
|
-
type: 'stream-start';
|
1155
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
1156
|
-
} | {
|
1157
|
-
type: 'response-metadata';
|
1158
|
-
id?: string;
|
1159
|
-
timestamp?: Date;
|
1160
|
-
modelId?: string;
|
1161
|
-
} | {
|
1162
|
-
type: 'finish';
|
1163
|
-
finishReason: LanguageModelV2FinishReason;
|
1164
|
-
providerMetadata?: SharedV2ProviderMetadata;
|
1165
|
-
usage: LanguageModelV2Usage;
|
1166
|
-
logprobs?: LanguageModelV2LogProbs;
|
1167
|
-
} | {
|
1168
|
-
type: 'error';
|
1169
|
-
error: unknown;
|
1170
|
-
};
|
1171
1293
|
|
1172
1294
|
/**
|
1173
1295
|
* Experimental middleware for LanguageModelV2.
|
@@ -1179,6 +1301,27 @@ type LanguageModelV2Middleware = {
|
|
1179
1301
|
* Middleware specification version. Use `v2` for the current version.
|
1180
1302
|
*/
|
1181
1303
|
middlewareVersion?: 'v2' | undefined;
|
1304
|
+
/**
|
1305
|
+
* Override the provider name if desired.
|
1306
|
+
* @param options.model - The language model instance.
|
1307
|
+
*/
|
1308
|
+
overrideProvider?: (options: {
|
1309
|
+
model: LanguageModelV2;
|
1310
|
+
}) => string;
|
1311
|
+
/**
|
1312
|
+
* Override the model ID if desired.
|
1313
|
+
* @param options.model - The language model instance.
|
1314
|
+
*/
|
1315
|
+
overrideModelId?: (options: {
|
1316
|
+
model: LanguageModelV2;
|
1317
|
+
}) => string;
|
1318
|
+
/**
|
1319
|
+
* Override the supported URLs if desired.
|
1320
|
+
* @param options.model - The language model instance.
|
1321
|
+
*/
|
1322
|
+
overrideSupportedUrls?: (options: {
|
1323
|
+
model: LanguageModelV2;
|
1324
|
+
}) => PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
1182
1325
|
/**
|
1183
1326
|
* Transforms the parameters before they are passed to the language model.
|
1184
1327
|
* @param options - Object containing the type of operation and the parameters.
|
@@ -1189,6 +1332,7 @@ type LanguageModelV2Middleware = {
|
|
1189
1332
|
transformParams?: (options: {
|
1190
1333
|
type: 'generate' | 'stream';
|
1191
1334
|
params: LanguageModelV2CallOptions;
|
1335
|
+
model: LanguageModelV2;
|
1192
1336
|
}) => PromiseLike<LanguageModelV2CallOptions>;
|
1193
1337
|
/**
|
1194
1338
|
* Wraps the generate operation of the language model.
|
@@ -1225,467 +1369,65 @@ type LanguageModelV2Middleware = {
|
|
1225
1369
|
}) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
1226
1370
|
};
|
1227
1371
|
|
1228
|
-
|
1229
|
-
|
1230
|
-
* to the provider from the AI SDK and enable provider-specific
|
1231
|
-
* functionality that can be fully encapsulated in the provider.
|
1232
|
-
*
|
1233
|
-
* This enables us to quickly ship provider-specific functionality
|
1234
|
-
* without affecting the core AI SDK.
|
1235
|
-
*
|
1236
|
-
* The outer record is keyed by the provider name, and the inner
|
1237
|
-
* record is keyed by the provider-specific metadata key.
|
1238
|
-
*
|
1239
|
-
* ```ts
|
1240
|
-
* {
|
1241
|
-
* "anthropic": {
|
1242
|
-
* "cacheControl": { "type": "ephemeral" }
|
1243
|
-
* }
|
1244
|
-
* }
|
1245
|
-
* ```
|
1246
|
-
*/
|
1247
|
-
type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
1248
|
-
|
1249
|
-
/**
|
1250
|
-
* A source that has been used as input to generate the response.
|
1251
|
-
*/
|
1252
|
-
type LanguageModelV1Source = {
|
1253
|
-
/**
|
1254
|
-
* A URL source. This is return by web search RAG models.
|
1255
|
-
*/
|
1256
|
-
sourceType: 'url';
|
1257
|
-
/**
|
1258
|
-
* The ID of the source.
|
1259
|
-
*/
|
1260
|
-
id: string;
|
1261
|
-
/**
|
1262
|
-
* The URL of the source.
|
1263
|
-
*/
|
1264
|
-
url: string;
|
1265
|
-
/**
|
1266
|
-
* The title of the source.
|
1267
|
-
*/
|
1268
|
-
title?: string;
|
1269
|
-
/**
|
1270
|
-
* Additional provider metadata for the source.
|
1271
|
-
*/
|
1272
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1273
|
-
};
|
1274
|
-
|
1275
|
-
type LanguageModelV1CallSettings = {
|
1276
|
-
/**
|
1277
|
-
Maximum number of tokens to generate.
|
1278
|
-
*/
|
1279
|
-
maxTokens?: number;
|
1372
|
+
type SpeechModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
1373
|
+
type SpeechModelV2CallOptions = {
|
1280
1374
|
/**
|
1281
|
-
|
1282
|
-
|
1283
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
1284
|
-
*/
|
1285
|
-
temperature?: number;
|
1286
|
-
/**
|
1287
|
-
Stop sequences.
|
1288
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
1289
|
-
Providers may have limits on the number of stop sequences.
|
1375
|
+
* Text to convert to speech.
|
1290
1376
|
*/
|
1291
|
-
|
1377
|
+
text: string;
|
1292
1378
|
/**
|
1293
|
-
|
1294
|
-
|
1295
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
1379
|
+
* The voice to use for speech synthesis.
|
1380
|
+
* This is provider-specific and may be a voice ID, name, or other identifier.
|
1296
1381
|
*/
|
1297
|
-
|
1382
|
+
voice?: string;
|
1298
1383
|
/**
|
1299
|
-
|
1300
|
-
|
1301
|
-
Used to remove "long tail" low probability responses.
|
1302
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
1384
|
+
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
1303
1385
|
*/
|
1304
|
-
|
1386
|
+
outputFormat?: string;
|
1305
1387
|
/**
|
1306
|
-
|
1307
|
-
repeat information that is already in the prompt.
|
1388
|
+
* Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
1308
1389
|
*/
|
1309
|
-
|
1390
|
+
instructions?: string;
|
1310
1391
|
/**
|
1311
|
-
|
1312
|
-
to repeatedly use the same words or phrases.
|
1392
|
+
* The speed of the speech generation.
|
1313
1393
|
*/
|
1314
|
-
|
1394
|
+
speed?: number;
|
1315
1395
|
/**
|
1316
|
-
|
1317
|
-
|
1318
|
-
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1396
|
+
* The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
|
1397
|
+
* or "auto" for automatic language detection. Provider support varies.
|
1319
1398
|
*/
|
1320
|
-
|
1321
|
-
type: 'text';
|
1322
|
-
} | {
|
1323
|
-
type: 'json';
|
1324
|
-
/**
|
1325
|
-
* JSON schema that the generated output should conform to.
|
1326
|
-
*/
|
1327
|
-
schema?: JSONSchema7;
|
1328
|
-
/**
|
1329
|
-
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1330
|
-
*/
|
1331
|
-
name?: string;
|
1332
|
-
/**
|
1333
|
-
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1334
|
-
*/
|
1335
|
-
description?: string;
|
1336
|
-
};
|
1399
|
+
language?: string;
|
1337
1400
|
/**
|
1338
|
-
|
1339
|
-
|
1401
|
+
* Additional provider-specific options that are passed through to the provider
|
1402
|
+
* as body parameters.
|
1403
|
+
*
|
1404
|
+
* The outer record is keyed by the provider name, and the inner
|
1405
|
+
* record is keyed by the provider-specific metadata key.
|
1406
|
+
* ```ts
|
1407
|
+
* {
|
1408
|
+
* "openai": {}
|
1409
|
+
* }
|
1410
|
+
* ```
|
1340
1411
|
*/
|
1341
|
-
|
1412
|
+
providerOptions?: SpeechModelV2ProviderOptions;
|
1342
1413
|
/**
|
1343
|
-
|
1414
|
+
* Abort signal for cancelling the operation.
|
1344
1415
|
*/
|
1345
1416
|
abortSignal?: AbortSignal;
|
1346
1417
|
/**
|
1347
|
-
|
1348
|
-
|
1418
|
+
* Additional HTTP headers to be sent with the request.
|
1419
|
+
* Only applicable for HTTP-based providers.
|
1349
1420
|
*/
|
1350
1421
|
headers?: Record<string, string | undefined>;
|
1351
1422
|
};
|
1352
1423
|
|
1353
1424
|
/**
|
1354
|
-
|
1355
|
-
|
1356
|
-
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
1357
|
-
map the user-facing tool definitions to this format.
|
1358
|
-
*/
|
1359
|
-
type LanguageModelV1FunctionTool = {
|
1360
|
-
/**
|
1361
|
-
The type of the tool (always 'function').
|
1362
|
-
*/
|
1363
|
-
type: 'function';
|
1364
|
-
/**
|
1365
|
-
The name of the tool. Unique within this model call.
|
1366
|
-
*/
|
1367
|
-
name: string;
|
1368
|
-
/**
|
1369
|
-
A description of the tool. The language model uses this to understand the
|
1370
|
-
tool's purpose and to provide better completion suggestions.
|
1371
|
-
*/
|
1372
|
-
description?: string;
|
1373
|
-
/**
|
1374
|
-
The parameters that the tool expects. The language model uses this to
|
1375
|
-
understand the tool's input requirements and to provide matching suggestions.
|
1376
|
-
*/
|
1377
|
-
parameters: JSONSchema7;
|
1378
|
-
};
|
1379
|
-
|
1380
|
-
/**
|
1381
|
-
A prompt is a list of messages.
|
1382
|
-
|
1383
|
-
Note: Not all models and prompt formats support multi-modal inputs and
|
1384
|
-
tool calls. The validation happens at runtime.
|
1385
|
-
|
1386
|
-
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
1387
|
-
user-facing prompt types such as chat or instruction prompts to this format.
|
1388
|
-
*/
|
1389
|
-
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
1390
|
-
type LanguageModelV1Message = ({
|
1391
|
-
role: 'system';
|
1392
|
-
content: string;
|
1393
|
-
} | {
|
1394
|
-
role: 'user';
|
1395
|
-
content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
|
1396
|
-
} | {
|
1397
|
-
role: 'assistant';
|
1398
|
-
content: Array<LanguageModelV1TextPart | LanguageModelV1FilePart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
|
1399
|
-
} | {
|
1400
|
-
role: 'tool';
|
1401
|
-
content: Array<LanguageModelV1ToolResultPart>;
|
1402
|
-
}) & {
|
1403
|
-
/**
|
1404
|
-
* Additional provider-specific metadata. They are passed through
|
1405
|
-
* to the provider from the AI SDK and enable provider-specific
|
1406
|
-
* functionality that can be fully encapsulated in the provider.
|
1407
|
-
*/
|
1408
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1409
|
-
};
|
1410
|
-
/**
|
1411
|
-
Text content part of a prompt. It contains a string of text.
|
1412
|
-
*/
|
1413
|
-
interface LanguageModelV1TextPart {
|
1414
|
-
type: 'text';
|
1415
|
-
/**
|
1416
|
-
The text content.
|
1417
|
-
*/
|
1418
|
-
text: string;
|
1419
|
-
/**
|
1420
|
-
* Additional provider-specific metadata. They are passed through
|
1421
|
-
* to the provider from the AI SDK and enable provider-specific
|
1422
|
-
* functionality that can be fully encapsulated in the provider.
|
1423
|
-
*/
|
1424
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1425
|
-
}
|
1426
|
-
/**
|
1427
|
-
Reasoning content part of a prompt. It contains a string of reasoning text.
|
1428
|
-
*/
|
1429
|
-
interface LanguageModelV1ReasoningPart {
|
1430
|
-
type: 'reasoning';
|
1431
|
-
/**
|
1432
|
-
The reasoning text.
|
1433
|
-
*/
|
1434
|
-
text: string;
|
1435
|
-
/**
|
1436
|
-
An optional signature for verifying that the reasoning originated from the model.
|
1437
|
-
*/
|
1438
|
-
signature?: string;
|
1439
|
-
/**
|
1440
|
-
Additional provider-specific metadata. They are passed through
|
1441
|
-
to the provider from the AI SDK and enable provider-specific
|
1442
|
-
functionality that can be fully encapsulated in the provider.
|
1443
|
-
*/
|
1444
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1445
|
-
}
|
1446
|
-
/**
|
1447
|
-
Redacted reasoning content part of a prompt.
|
1448
|
-
*/
|
1449
|
-
interface LanguageModelV1RedactedReasoningPart {
|
1450
|
-
type: 'redacted-reasoning';
|
1451
|
-
/**
|
1452
|
-
Redacted reasoning data.
|
1453
|
-
*/
|
1454
|
-
data: string;
|
1455
|
-
/**
|
1456
|
-
Additional provider-specific metadata. They are passed through
|
1457
|
-
to the provider from the AI SDK and enable provider-specific
|
1458
|
-
functionality that can be fully encapsulated in the provider.
|
1459
|
-
*/
|
1460
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1461
|
-
}
|
1462
|
-
/**
|
1463
|
-
Image content part of a prompt. It contains an image.
|
1464
|
-
*/
|
1465
|
-
interface LanguageModelV1ImagePart {
|
1466
|
-
type: 'image';
|
1467
|
-
/**
|
1468
|
-
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
1469
|
-
*/
|
1470
|
-
image: Uint8Array | URL;
|
1471
|
-
/**
|
1472
|
-
Optional mime type of the image.
|
1473
|
-
*/
|
1474
|
-
mimeType?: string;
|
1475
|
-
/**
|
1476
|
-
* Additional provider-specific metadata. They are passed through
|
1477
|
-
* to the provider from the AI SDK and enable provider-specific
|
1478
|
-
* functionality that can be fully encapsulated in the provider.
|
1479
|
-
*/
|
1480
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1481
|
-
}
|
1482
|
-
/**
|
1483
|
-
File content part of a prompt. It contains a file.
|
1484
|
-
*/
|
1485
|
-
interface LanguageModelV1FilePart {
|
1486
|
-
type: 'file';
|
1487
|
-
/**
|
1488
|
-
* Optional filename of the file.
|
1489
|
-
*/
|
1490
|
-
filename?: string;
|
1491
|
-
/**
|
1492
|
-
File data as base64 encoded string or as a URL.
|
1493
|
-
*/
|
1494
|
-
data: string | URL;
|
1495
|
-
/**
|
1496
|
-
Mime type of the file.
|
1497
|
-
*/
|
1498
|
-
mimeType: string;
|
1499
|
-
/**
|
1500
|
-
* Additional provider-specific metadata. They are passed through
|
1501
|
-
* to the provider from the AI SDK and enable provider-specific
|
1502
|
-
* functionality that can be fully encapsulated in the provider.
|
1503
|
-
*/
|
1504
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1505
|
-
}
|
1506
|
-
/**
|
1507
|
-
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
1508
|
-
*/
|
1509
|
-
interface LanguageModelV1ToolCallPart {
|
1510
|
-
type: 'tool-call';
|
1511
|
-
/**
|
1512
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
1513
|
-
*/
|
1514
|
-
toolCallId: string;
|
1515
|
-
/**
|
1516
|
-
Name of the tool that is being called.
|
1517
|
-
*/
|
1518
|
-
toolName: string;
|
1519
|
-
/**
|
1520
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
1521
|
-
*/
|
1522
|
-
args: unknown;
|
1523
|
-
/**
|
1524
|
-
* Additional provider-specific metadata. They are passed through
|
1525
|
-
* to the provider from the AI SDK and enable provider-specific
|
1526
|
-
* functionality that can be fully encapsulated in the provider.
|
1527
|
-
*/
|
1528
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1529
|
-
}
|
1530
|
-
/**
|
1531
|
-
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
1532
|
-
*/
|
1533
|
-
interface LanguageModelV1ToolResultPart {
|
1534
|
-
type: 'tool-result';
|
1535
|
-
/**
|
1536
|
-
ID of the tool call that this result is associated with.
|
1537
|
-
*/
|
1538
|
-
toolCallId: string;
|
1539
|
-
/**
|
1540
|
-
Name of the tool that generated this result.
|
1541
|
-
*/
|
1542
|
-
toolName: string;
|
1543
|
-
/**
|
1544
|
-
Result of the tool call. This is a JSON-serializable object.
|
1545
|
-
*/
|
1546
|
-
result: unknown;
|
1547
|
-
/**
|
1548
|
-
Optional flag if the result is an error or an error message.
|
1549
|
-
*/
|
1550
|
-
isError?: boolean;
|
1551
|
-
/**
|
1552
|
-
Tool results as an array of parts. This enables advanced tool results including images.
|
1553
|
-
When this is used, the `result` field should be ignored (if the provider supports content).
|
1554
|
-
*/
|
1555
|
-
content?: Array<{
|
1556
|
-
type: 'text';
|
1557
|
-
/**
|
1558
|
-
Text content.
|
1559
|
-
*/
|
1560
|
-
text: string;
|
1561
|
-
} | {
|
1562
|
-
type: 'image';
|
1563
|
-
/**
|
1564
|
-
base-64 encoded image data
|
1565
|
-
*/
|
1566
|
-
data: string;
|
1567
|
-
/**
|
1568
|
-
Mime type of the image.
|
1569
|
-
*/
|
1570
|
-
mimeType?: string;
|
1571
|
-
}>;
|
1572
|
-
/**
|
1573
|
-
* Additional provider-specific metadata. They are passed through
|
1574
|
-
* to the provider from the AI SDK and enable provider-specific
|
1575
|
-
* functionality that can be fully encapsulated in the provider.
|
1576
|
-
*/
|
1577
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1578
|
-
}
|
1579
|
-
|
1580
|
-
/**
|
1581
|
-
The configuration of a tool that is defined by the provider.
|
1582
|
-
*/
|
1583
|
-
type LanguageModelV1ProviderDefinedTool = {
|
1584
|
-
/**
|
1585
|
-
The type of the tool (always 'provider-defined').
|
1586
|
-
*/
|
1587
|
-
type: 'provider-defined';
|
1588
|
-
/**
|
1589
|
-
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
1590
|
-
*/
|
1591
|
-
id: `${string}.${string}`;
|
1592
|
-
/**
|
1593
|
-
The name of the tool. Unique within this model call.
|
1594
|
-
*/
|
1595
|
-
name: string;
|
1596
|
-
/**
|
1597
|
-
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1598
|
-
*/
|
1599
|
-
args: Record<string, unknown>;
|
1600
|
-
};
|
1601
|
-
|
1602
|
-
type LanguageModelV1ToolChoice = {
|
1603
|
-
type: 'auto';
|
1604
|
-
} | {
|
1605
|
-
type: 'none';
|
1606
|
-
} | {
|
1607
|
-
type: 'required';
|
1608
|
-
} | {
|
1609
|
-
type: 'tool';
|
1610
|
-
toolName: string;
|
1611
|
-
};
|
1612
|
-
|
1613
|
-
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
1614
|
-
/**
|
1615
|
-
Whether the user provided the input as messages or as
|
1616
|
-
a prompt. This can help guide non-chat models in the
|
1617
|
-
expansion, bc different expansions can be needed for
|
1618
|
-
chat/non-chat use cases.
|
1619
|
-
*/
|
1620
|
-
inputFormat: 'messages' | 'prompt';
|
1621
|
-
/**
|
1622
|
-
The mode affects the behavior of the language model. It is required to
|
1623
|
-
support provider-independent streaming and generation of structured objects.
|
1624
|
-
The model can take this information and e.g. configure json mode, the correct
|
1625
|
-
low level grammar, etc. It can also be used to optimize the efficiency of the
|
1626
|
-
streaming, e.g. tool-delta stream parts are only needed in the
|
1627
|
-
object-tool mode.
|
1628
|
-
|
1629
|
-
@deprecated mode will be removed in v2.
|
1630
|
-
All necessary settings will be directly supported through the call settings,
|
1631
|
-
in particular responseFormat, toolChoice, and tools.
|
1632
|
-
*/
|
1633
|
-
mode: {
|
1634
|
-
type: 'regular';
|
1635
|
-
/**
|
1636
|
-
The tools that are available for the model.
|
1637
|
-
*/
|
1638
|
-
tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
|
1639
|
-
/**
|
1640
|
-
Specifies how the tool should be selected. Defaults to 'auto'.
|
1641
|
-
*/
|
1642
|
-
toolChoice?: LanguageModelV1ToolChoice;
|
1643
|
-
} | {
|
1644
|
-
type: 'object-json';
|
1645
|
-
/**
|
1646
|
-
* JSON schema that the generated output should conform to.
|
1647
|
-
*/
|
1648
|
-
schema?: JSONSchema7;
|
1649
|
-
/**
|
1650
|
-
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1651
|
-
*/
|
1652
|
-
name?: string;
|
1653
|
-
/**
|
1654
|
-
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1655
|
-
*/
|
1656
|
-
description?: string;
|
1657
|
-
} | {
|
1658
|
-
type: 'object-tool';
|
1659
|
-
tool: LanguageModelV1FunctionTool;
|
1660
|
-
};
|
1661
|
-
/**
|
1662
|
-
A language mode prompt is a standardized prompt type.
|
1663
|
-
|
1664
|
-
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
1665
|
-
user-facing prompt types such as chat or instruction prompts to this format.
|
1666
|
-
That approach allows us to evolve the user facing prompts without breaking
|
1667
|
-
the language model interface.
|
1668
|
-
*/
|
1669
|
-
prompt: LanguageModelV1Prompt;
|
1670
|
-
/**
|
1671
|
-
Additional provider-specific metadata.
|
1672
|
-
The metadata is passed through to the provider from the AI SDK and enables
|
1673
|
-
provider-specific functionality that can be fully encapsulated in the provider.
|
1674
|
-
*/
|
1675
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1676
|
-
};
|
1677
|
-
|
1678
|
-
/**
|
1679
|
-
Warning from the model provider for this call. The call will proceed, but e.g.
|
1680
|
-
some settings might not be supported, which can lead to suboptimal results.
|
1425
|
+
* Warning from the model provider for this call. The call will proceed, but e.g.
|
1426
|
+
* some settings might not be supported, which can lead to suboptimal results.
|
1681
1427
|
*/
|
1682
|
-
type
|
1428
|
+
type SpeechModelV2CallWarning = {
|
1683
1429
|
type: 'unsupported-setting';
|
1684
|
-
setting: keyof
|
1685
|
-
details?: string;
|
1686
|
-
} | {
|
1687
|
-
type: 'unsupported-tool';
|
1688
|
-
tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
|
1430
|
+
setting: keyof SpeechModelV2CallOptions;
|
1689
1431
|
details?: string;
|
1690
1432
|
} | {
|
1691
1433
|
type: 'other';
|
@@ -1693,341 +1435,82 @@ type LanguageModelV1CallWarning = {
|
|
1693
1435
|
};
|
1694
1436
|
|
1695
1437
|
/**
|
1696
|
-
|
1697
|
-
|
1698
|
-
Can be one of the following:
|
1699
|
-
- `stop`: model generated stop sequence
|
1700
|
-
- `length`: model generated maximum number of tokens
|
1701
|
-
- `content-filter`: content filter violation stopped the model
|
1702
|
-
- `tool-calls`: model triggered tool calls
|
1703
|
-
- `error`: model stopped because of an error
|
1704
|
-
- `other`: model stopped for other reasons
|
1705
|
-
- `unknown`: the model has not transmitted a finish reason
|
1438
|
+
* Speech model specification version 2.
|
1706
1439
|
*/
|
1707
|
-
type
|
1708
|
-
|
1709
|
-
type LanguageModelV1FunctionToolCall = {
|
1710
|
-
toolCallType: 'function';
|
1711
|
-
toolCallId: string;
|
1712
|
-
toolName: string;
|
1440
|
+
type SpeechModelV2 = {
|
1713
1441
|
/**
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
/**
|
1721
|
-
Log probabilities for each token and its top log probabilities.
|
1722
|
-
*/
|
1723
|
-
type LanguageModelV1LogProbs = Array<{
|
1724
|
-
token: string;
|
1725
|
-
logprob: number;
|
1726
|
-
topLogprobs: Array<{
|
1727
|
-
token: string;
|
1728
|
-
logprob: number;
|
1729
|
-
}>;
|
1730
|
-
}>;
|
1731
|
-
|
1732
|
-
/**
|
1733
|
-
Specification for a language model that implements the language model interface version 1.
|
1734
|
-
*/
|
1735
|
-
type LanguageModelV1 = {
|
1736
|
-
/**
|
1737
|
-
The language model must specify which language model interface
|
1738
|
-
version it implements. This will allow us to evolve the language
|
1739
|
-
model interface and retain backwards compatibility. The different
|
1740
|
-
implementation versions can be handled as a discriminated union
|
1741
|
-
on our side.
|
1442
|
+
* The speech model must specify which speech model interface
|
1443
|
+
* version it implements. This will allow us to evolve the speech
|
1444
|
+
* model interface and retain backwards compatibility. The different
|
1445
|
+
* implementation versions can be handled as a discriminated union
|
1446
|
+
* on our side.
|
1742
1447
|
*/
|
1743
|
-
readonly specificationVersion: '
|
1448
|
+
readonly specificationVersion: 'v2';
|
1744
1449
|
/**
|
1745
|
-
|
1450
|
+
* Name of the provider for logging purposes.
|
1746
1451
|
*/
|
1747
1452
|
readonly provider: string;
|
1748
1453
|
/**
|
1749
|
-
|
1454
|
+
* Provider-specific model ID for logging purposes.
|
1750
1455
|
*/
|
1751
1456
|
readonly modelId: string;
|
1752
1457
|
/**
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
This is needed to generate the best objects possible w/o requiring the
|
1758
|
-
user to explicitly specify the object generation mode.
|
1759
|
-
*/
|
1760
|
-
readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
|
1761
|
-
/**
|
1762
|
-
Flag whether this model supports image URLs. Default is `true`.
|
1763
|
-
|
1764
|
-
When the flag is set to `false`, the AI SDK will download the image and
|
1765
|
-
pass the image data to the model.
|
1766
|
-
*/
|
1767
|
-
readonly supportsImageUrls?: boolean;
|
1768
|
-
/**
|
1769
|
-
Flag whether this model supports grammar-guided generation,
|
1770
|
-
i.e. follows JSON schemas for object generation
|
1771
|
-
when the response format is set to 'json' or
|
1772
|
-
when the `object-json` mode is used.
|
1773
|
-
|
1774
|
-
This means that the model guarantees that the generated JSON
|
1775
|
-
will be a valid JSON object AND that the object will match the
|
1776
|
-
JSON schema.
|
1777
|
-
|
1778
|
-
Please note that `generateObject` and `streamObject` will work
|
1779
|
-
regardless of this flag, but might send different prompts and
|
1780
|
-
use further optimizations if this flag is set to `true`.
|
1781
|
-
|
1782
|
-
Defaults to `false`.
|
1783
|
-
*/
|
1784
|
-
readonly supportsStructuredOutputs?: boolean;
|
1785
|
-
/**
|
1786
|
-
Checks if the model supports the given URL for file parts natively.
|
1787
|
-
If the model does not support the URL,
|
1788
|
-
the AI SDK will download the file and pass the file data to the model.
|
1789
|
-
|
1790
|
-
When undefined, the AI SDK will download the file.
|
1791
|
-
*/
|
1792
|
-
supportsUrl?(url: URL): boolean;
|
1793
|
-
/**
|
1794
|
-
Generates a language model output (non-streaming).
|
1795
|
-
|
1796
|
-
Naming: "do" prefix to prevent accidental direct usage of the method
|
1797
|
-
by the user.
|
1798
|
-
*/
|
1799
|
-
doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
|
1800
|
-
/**
|
1801
|
-
Text that the model has generated.
|
1802
|
-
Can be undefined if the model did not generate any text.
|
1803
|
-
*/
|
1804
|
-
text?: string;
|
1805
|
-
/**
|
1806
|
-
Reasoning that the model has generated.
|
1807
|
-
Can be undefined if the model does not support reasoning.
|
1808
|
-
*/
|
1809
|
-
reasoning?: string | Array<{
|
1810
|
-
type: 'text';
|
1811
|
-
text: string;
|
1812
|
-
/**
|
1813
|
-
An optional signature for verifying that the reasoning originated from the model.
|
1814
|
-
*/
|
1815
|
-
signature?: string;
|
1816
|
-
} | {
|
1817
|
-
type: 'redacted';
|
1818
|
-
data: string;
|
1819
|
-
}>;
|
1820
|
-
/**
|
1821
|
-
Generated files as base64 encoded strings or binary data.
|
1822
|
-
The files should be returned without any unnecessary conversion.
|
1823
|
-
If the API returns base64 encoded strings, the files should be returned
|
1824
|
-
as base64 encoded strings. If the API returns binary data, the files should
|
1825
|
-
be returned as binary data.
|
1826
|
-
*/
|
1827
|
-
files?: Array<{
|
1828
|
-
data: string | Uint8Array;
|
1829
|
-
mimeType: string;
|
1830
|
-
}>;
|
1831
|
-
/**
|
1832
|
-
Tool calls that the model has generated.
|
1833
|
-
Can be undefined if the model did not generate any tool calls.
|
1834
|
-
*/
|
1835
|
-
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
1836
|
-
/**
|
1837
|
-
Finish reason.
|
1838
|
-
*/
|
1839
|
-
finishReason: LanguageModelV1FinishReason;
|
1840
|
-
/**
|
1841
|
-
Usage information.
|
1842
|
-
*/
|
1843
|
-
usage: {
|
1844
|
-
promptTokens: number;
|
1845
|
-
completionTokens: number;
|
1846
|
-
};
|
1847
|
-
/**
|
1848
|
-
Raw prompt and setting information for observability provider integration.
|
1849
|
-
*/
|
1850
|
-
rawCall: {
|
1851
|
-
/**
|
1852
|
-
Raw prompt after expansion and conversion to the format that the
|
1853
|
-
provider uses to send the information to their API.
|
1854
|
-
*/
|
1855
|
-
rawPrompt: unknown;
|
1856
|
-
/**
|
1857
|
-
Raw settings that are used for the API call. Includes provider-specific
|
1858
|
-
settings.
|
1859
|
-
*/
|
1860
|
-
rawSettings: Record<string, unknown>;
|
1861
|
-
};
|
1862
|
-
/**
|
1863
|
-
Optional response information for telemetry and debugging purposes.
|
1864
|
-
*/
|
1865
|
-
rawResponse?: {
|
1866
|
-
/**
|
1867
|
-
Response headers.
|
1868
|
-
*/
|
1869
|
-
headers?: Record<string, string>;
|
1870
|
-
/**
|
1871
|
-
Response body.
|
1872
|
-
*/
|
1873
|
-
body?: unknown;
|
1874
|
-
};
|
1875
|
-
/**
|
1876
|
-
Optional request information for telemetry and debugging purposes.
|
1877
|
-
*/
|
1878
|
-
request?: {
|
1879
|
-
/**
|
1880
|
-
Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
|
1881
|
-
Non-HTTP(s) providers should not set this.
|
1882
|
-
*/
|
1883
|
-
body?: string;
|
1884
|
-
};
|
1885
|
-
/**
|
1886
|
-
Optional response information for telemetry and debugging purposes.
|
1887
|
-
*/
|
1888
|
-
response?: {
|
1889
|
-
/**
|
1890
|
-
ID for the generated response, if the provider sends one.
|
1891
|
-
*/
|
1892
|
-
id?: string;
|
1893
|
-
/**
|
1894
|
-
Timestamp for the start of the generated response, if the provider sends one.
|
1895
|
-
*/
|
1896
|
-
timestamp?: Date;
|
1897
|
-
/**
|
1898
|
-
The ID of the response model that was used to generate the response, if the provider sends one.
|
1899
|
-
*/
|
1900
|
-
modelId?: string;
|
1901
|
-
};
|
1902
|
-
warnings?: LanguageModelV1CallWarning[];
|
1458
|
+
* Generates speech audio from text.
|
1459
|
+
*/
|
1460
|
+
doGenerate(options: SpeechModelV2CallOptions): PromiseLike<{
|
1903
1461
|
/**
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1462
|
+
* Generated audio as an ArrayBuffer.
|
1463
|
+
* The audio should be returned without any unnecessary conversion.
|
1464
|
+
* If the API returns base64 encoded strings, the audio should be returned
|
1465
|
+
* as base64 encoded strings. If the API returns binary data, the audio
|
1466
|
+
* should be returned as binary data.
|
1907
1467
|
*/
|
1908
|
-
|
1468
|
+
audio: string | Uint8Array;
|
1909
1469
|
/**
|
1910
|
-
|
1470
|
+
* Warnings for the call, e.g. unsupported settings.
|
1911
1471
|
*/
|
1912
|
-
|
1472
|
+
warnings: Array<SpeechModelV2CallWarning>;
|
1913
1473
|
/**
|
1914
|
-
|
1915
|
-
`undefined` if the mode does not support logprobs or if was not enabled
|
1916
|
-
|
1917
|
-
@deprecated will be changed into a provider-specific extension in v2
|
1474
|
+
* Optional request information for telemetry and debugging purposes.
|
1918
1475
|
*/
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
by the user.
|
1926
|
-
*
|
1927
|
-
@return A stream of higher-level language model output parts.
|
1928
|
-
*/
|
1929
|
-
doStream(options: LanguageModelV1CallOptions): PromiseLike<{
|
1930
|
-
stream: ReadableStream<LanguageModelV1StreamPart>;
|
1476
|
+
request?: {
|
1477
|
+
/**
|
1478
|
+
* Response body (available only for providers that use HTTP requests).
|
1479
|
+
*/
|
1480
|
+
body?: unknown;
|
1481
|
+
};
|
1931
1482
|
/**
|
1932
|
-
|
1483
|
+
* Response information for telemetry and debugging purposes.
|
1933
1484
|
*/
|
1934
|
-
|
1485
|
+
response: {
|
1935
1486
|
/**
|
1936
|
-
|
1937
|
-
provider uses to send the information to their API.
|
1487
|
+
* Timestamp for the start of the generated response.
|
1938
1488
|
*/
|
1939
|
-
|
1489
|
+
timestamp: Date;
|
1940
1490
|
/**
|
1941
|
-
|
1942
|
-
settings.
|
1491
|
+
* The ID of the response model that was used to generate the response.
|
1943
1492
|
*/
|
1944
|
-
|
1945
|
-
};
|
1946
|
-
/**
|
1947
|
-
Optional raw response data.
|
1948
|
-
*/
|
1949
|
-
rawResponse?: {
|
1493
|
+
modelId: string;
|
1950
1494
|
/**
|
1951
|
-
|
1495
|
+
* Response headers.
|
1952
1496
|
*/
|
1953
|
-
headers?:
|
1954
|
-
};
|
1955
|
-
/**
|
1956
|
-
Optional request information for telemetry and debugging purposes.
|
1957
|
-
*/
|
1958
|
-
request?: {
|
1497
|
+
headers?: SharedV2Headers;
|
1959
1498
|
/**
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
body?: string;
|
1499
|
+
* Response body.
|
1500
|
+
*/
|
1501
|
+
body?: unknown;
|
1964
1502
|
};
|
1965
1503
|
/**
|
1966
|
-
|
1504
|
+
* Additional provider-specific metadata. They are passed through
|
1505
|
+
* from the provider to the AI SDK and enable provider-specific
|
1506
|
+
* results that can be fully encapsulated in the provider.
|
1967
1507
|
*/
|
1968
|
-
|
1508
|
+
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
1969
1509
|
}>;
|
1970
1510
|
};
|
1971
|
-
type LanguageModelV1StreamPart = {
|
1972
|
-
type: 'text-delta';
|
1973
|
-
textDelta: string;
|
1974
|
-
} | {
|
1975
|
-
type: 'reasoning';
|
1976
|
-
textDelta: string;
|
1977
|
-
} | {
|
1978
|
-
type: 'reasoning-signature';
|
1979
|
-
signature: string;
|
1980
|
-
} | {
|
1981
|
-
type: 'redacted-reasoning';
|
1982
|
-
data: string;
|
1983
|
-
} | {
|
1984
|
-
type: 'source';
|
1985
|
-
source: LanguageModelV1Source;
|
1986
|
-
} | {
|
1987
|
-
type: 'file';
|
1988
|
-
mimeType: string;
|
1989
|
-
/**
|
1990
|
-
Generated file data as base64 encoded strings or binary data.
|
1991
|
-
The file data should be returned without any unnecessary conversion.
|
1992
|
-
If the API returns base64 encoded strings, the file data should be returned
|
1993
|
-
as base64 encoded strings. If the API returns binary data, the file data should
|
1994
|
-
be returned as binary data.
|
1995
|
-
*/
|
1996
|
-
data: string | Uint8Array;
|
1997
|
-
} | ({
|
1998
|
-
type: 'tool-call';
|
1999
|
-
} & LanguageModelV1FunctionToolCall) | {
|
2000
|
-
type: 'tool-call-delta';
|
2001
|
-
toolCallType: 'function';
|
2002
|
-
toolCallId: string;
|
2003
|
-
toolName: string;
|
2004
|
-
argsTextDelta: string;
|
2005
|
-
} | {
|
2006
|
-
type: 'response-metadata';
|
2007
|
-
id?: string;
|
2008
|
-
timestamp?: Date;
|
2009
|
-
modelId?: string;
|
2010
|
-
} | {
|
2011
|
-
type: 'finish';
|
2012
|
-
finishReason: LanguageModelV1FinishReason;
|
2013
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
2014
|
-
usage: {
|
2015
|
-
promptTokens: number;
|
2016
|
-
completionTokens: number;
|
2017
|
-
};
|
2018
|
-
logprobs?: LanguageModelV1LogProbs;
|
2019
|
-
} | {
|
2020
|
-
type: 'error';
|
2021
|
-
error: unknown;
|
2022
|
-
};
|
2023
|
-
/**
|
2024
|
-
The object generation modes available for use with a model. `undefined`
|
2025
|
-
represents no support for object generation.
|
2026
|
-
*/
|
2027
|
-
type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
|
2028
1511
|
|
2029
|
-
type
|
2030
|
-
type
|
1512
|
+
type TranscriptionModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
1513
|
+
type TranscriptionModelV2CallOptions = {
|
2031
1514
|
/**
|
2032
1515
|
Audio data to transcribe.
|
2033
1516
|
Accepts a `Uint8Array` or `string`, where `string` is a base64 encoded audio file.
|
@@ -2053,7 +1536,7 @@ type TranscriptionModelV1CallOptions = {
|
|
2053
1536
|
}
|
2054
1537
|
```
|
2055
1538
|
*/
|
2056
|
-
providerOptions?:
|
1539
|
+
providerOptions?: TranscriptionModelV2ProviderOptions;
|
2057
1540
|
/**
|
2058
1541
|
Abort signal for cancelling the operation.
|
2059
1542
|
*/
|
@@ -2069,9 +1552,9 @@ type TranscriptionModelV1CallOptions = {
|
|
2069
1552
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
2070
1553
|
some settings might not be supported, which can lead to suboptimal results.
|
2071
1554
|
*/
|
2072
|
-
type
|
1555
|
+
type TranscriptionModelV2CallWarning = {
|
2073
1556
|
type: 'unsupported-setting';
|
2074
|
-
setting: keyof
|
1557
|
+
setting: keyof TranscriptionModelV2CallOptions;
|
2075
1558
|
details?: string;
|
2076
1559
|
} | {
|
2077
1560
|
type: 'other';
|
@@ -2079,9 +1562,9 @@ type TranscriptionModelV1CallWarning = {
|
|
2079
1562
|
};
|
2080
1563
|
|
2081
1564
|
/**
|
2082
|
-
Transcription model specification version
|
1565
|
+
Transcription model specification version 2.
|
2083
1566
|
*/
|
2084
|
-
type
|
1567
|
+
type TranscriptionModelV2 = {
|
2085
1568
|
/**
|
2086
1569
|
The transcription model must specify which transcription model interface
|
2087
1570
|
version it implements. This will allow us to evolve the transcription
|
@@ -2089,7 +1572,7 @@ type TranscriptionModelV1 = {
|
|
2089
1572
|
implementation versions can be handled as a discriminated union
|
2090
1573
|
on our side.
|
2091
1574
|
*/
|
2092
|
-
readonly specificationVersion: '
|
1575
|
+
readonly specificationVersion: 'v2';
|
2093
1576
|
/**
|
2094
1577
|
Name of the provider for logging purposes.
|
2095
1578
|
*/
|
@@ -2101,7 +1584,7 @@ type TranscriptionModelV1 = {
|
|
2101
1584
|
/**
|
2102
1585
|
Generates a transcript.
|
2103
1586
|
*/
|
2104
|
-
doGenerate(options:
|
1587
|
+
doGenerate(options: TranscriptionModelV2CallOptions): PromiseLike<{
|
2105
1588
|
/**
|
2106
1589
|
* The complete transcribed text from the audio.
|
2107
1590
|
*/
|
@@ -2137,7 +1620,7 @@ type TranscriptionModelV1 = {
|
|
2137
1620
|
/**
|
2138
1621
|
Warnings for the call, e.g. unsupported settings.
|
2139
1622
|
*/
|
2140
|
-
warnings: Array<
|
1623
|
+
warnings: Array<TranscriptionModelV2CallWarning>;
|
2141
1624
|
/**
|
2142
1625
|
Optional request information for telemetry and debugging purposes.
|
2143
1626
|
*/
|
@@ -2163,7 +1646,7 @@ type TranscriptionModelV1 = {
|
|
2163
1646
|
/**
|
2164
1647
|
Response headers.
|
2165
1648
|
*/
|
2166
|
-
headers
|
1649
|
+
headers?: SharedV2Headers;
|
2167
1650
|
/**
|
2168
1651
|
Response body.
|
2169
1652
|
*/
|
@@ -2178,145 +1661,10 @@ type TranscriptionModelV1 = {
|
|
2178
1661
|
}>;
|
2179
1662
|
};
|
2180
1663
|
|
2181
|
-
type SpeechModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
|
2182
|
-
type SpeechModelV1CallOptions = {
|
2183
|
-
/**
|
2184
|
-
* Text to convert to speech.
|
2185
|
-
*/
|
2186
|
-
text: string;
|
2187
|
-
/**
|
2188
|
-
* The voice to use for speech synthesis.
|
2189
|
-
* This is provider-specific and may be a voice ID, name, or other identifier.
|
2190
|
-
*/
|
2191
|
-
voice?: string;
|
2192
|
-
/**
|
2193
|
-
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
2194
|
-
*/
|
2195
|
-
outputFormat?: string;
|
2196
|
-
/**
|
2197
|
-
* Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
2198
|
-
*/
|
2199
|
-
instructions?: string;
|
2200
|
-
/**
|
2201
|
-
* The speed of the speech generation.
|
2202
|
-
*/
|
2203
|
-
speed?: number;
|
2204
|
-
/**
|
2205
|
-
* Additional provider-specific options that are passed through to the provider
|
2206
|
-
* as body parameters.
|
2207
|
-
*
|
2208
|
-
* The outer record is keyed by the provider name, and the inner
|
2209
|
-
* record is keyed by the provider-specific metadata key.
|
2210
|
-
* ```ts
|
2211
|
-
* {
|
2212
|
-
* "openai": {}
|
2213
|
-
* }
|
2214
|
-
* ```
|
2215
|
-
*/
|
2216
|
-
providerOptions?: SpeechModelV1ProviderOptions;
|
2217
|
-
/**
|
2218
|
-
* Abort signal for cancelling the operation.
|
2219
|
-
*/
|
2220
|
-
abortSignal?: AbortSignal;
|
2221
|
-
/**
|
2222
|
-
* Additional HTTP headers to be sent with the request.
|
2223
|
-
* Only applicable for HTTP-based providers.
|
2224
|
-
*/
|
2225
|
-
headers?: Record<string, string | undefined>;
|
2226
|
-
};
|
2227
|
-
|
2228
|
-
/**
|
2229
|
-
* Warning from the model provider for this call. The call will proceed, but e.g.
|
2230
|
-
* some settings might not be supported, which can lead to suboptimal results.
|
2231
|
-
*/
|
2232
|
-
type SpeechModelV1CallWarning = {
|
2233
|
-
type: 'unsupported-setting';
|
2234
|
-
setting: keyof SpeechModelV1CallOptions;
|
2235
|
-
details?: string;
|
2236
|
-
} | {
|
2237
|
-
type: 'other';
|
2238
|
-
message: string;
|
2239
|
-
};
|
2240
|
-
|
2241
|
-
/**
|
2242
|
-
* Speech model specification version 1.
|
2243
|
-
*/
|
2244
|
-
type SpeechModelV1 = {
|
2245
|
-
/**
|
2246
|
-
* The speech model must specify which speech model interface
|
2247
|
-
* version it implements. This will allow us to evolve the speech
|
2248
|
-
* model interface and retain backwards compatibility. The different
|
2249
|
-
* implementation versions can be handled as a discriminated union
|
2250
|
-
* on our side.
|
2251
|
-
*/
|
2252
|
-
readonly specificationVersion: 'v1';
|
2253
|
-
/**
|
2254
|
-
* Name of the provider for logging purposes.
|
2255
|
-
*/
|
2256
|
-
readonly provider: string;
|
2257
|
-
/**
|
2258
|
-
* Provider-specific model ID for logging purposes.
|
2259
|
-
*/
|
2260
|
-
readonly modelId: string;
|
2261
|
-
/**
|
2262
|
-
* Generates speech audio from text.
|
2263
|
-
*/
|
2264
|
-
doGenerate(options: SpeechModelV1CallOptions): PromiseLike<{
|
2265
|
-
/**
|
2266
|
-
* Generated audio as an ArrayBuffer.
|
2267
|
-
* The audio should be returned without any unnecessary conversion.
|
2268
|
-
* If the API returns base64 encoded strings, the audio should be returned
|
2269
|
-
* as base64 encoded strings. If the API returns binary data, the audio
|
2270
|
-
* should be returned as binary data.
|
2271
|
-
*/
|
2272
|
-
audio: string | Uint8Array;
|
2273
|
-
/**
|
2274
|
-
* Warnings for the call, e.g. unsupported settings.
|
2275
|
-
*/
|
2276
|
-
warnings: Array<SpeechModelV1CallWarning>;
|
2277
|
-
/**
|
2278
|
-
* Optional request information for telemetry and debugging purposes.
|
2279
|
-
*/
|
2280
|
-
request?: {
|
2281
|
-
/**
|
2282
|
-
* Response body (available only for providers that use HTTP requests).
|
2283
|
-
*/
|
2284
|
-
body?: unknown;
|
2285
|
-
};
|
2286
|
-
/**
|
2287
|
-
* Response information for telemetry and debugging purposes.
|
2288
|
-
*/
|
2289
|
-
response: {
|
2290
|
-
/**
|
2291
|
-
* Timestamp for the start of the generated response.
|
2292
|
-
*/
|
2293
|
-
timestamp: Date;
|
2294
|
-
/**
|
2295
|
-
* The ID of the response model that was used to generate the response.
|
2296
|
-
*/
|
2297
|
-
modelId: string;
|
2298
|
-
/**
|
2299
|
-
* Response headers.
|
2300
|
-
*/
|
2301
|
-
headers: Record<string, string> | undefined;
|
2302
|
-
/**
|
2303
|
-
* Response body.
|
2304
|
-
*/
|
2305
|
-
body?: unknown;
|
2306
|
-
};
|
2307
|
-
/**
|
2308
|
-
* Additional provider-specific metadata. They are passed through
|
2309
|
-
* from the provider to the AI SDK and enable provider-specific
|
2310
|
-
* results that can be fully encapsulated in the provider.
|
2311
|
-
*/
|
2312
|
-
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
2313
|
-
}>;
|
2314
|
-
};
|
2315
|
-
|
2316
1664
|
/**
|
2317
1665
|
* Provider for language, text embedding, and image generation models.
|
2318
1666
|
*/
|
2319
|
-
interface
|
1667
|
+
interface ProviderV2 {
|
2320
1668
|
/**
|
2321
1669
|
Returns the language model with the given id.
|
2322
1670
|
The model id is then passed to the provider function to get the model.
|
@@ -2327,7 +1675,7 @@ interface ProviderV1 {
|
|
2327
1675
|
|
2328
1676
|
@throws {NoSuchModelError} If no such model exists.
|
2329
1677
|
*/
|
2330
|
-
languageModel(modelId: string):
|
1678
|
+
languageModel(modelId: string): LanguageModelV2;
|
2331
1679
|
/**
|
2332
1680
|
Returns the text embedding model with the given id.
|
2333
1681
|
The model id is then passed to the provider function to get the model.
|
@@ -2347,7 +1695,7 @@ interface ProviderV1 {
|
|
2347
1695
|
|
2348
1696
|
@returns {ImageModel} The image model associated with the id
|
2349
1697
|
*/
|
2350
|
-
|
1698
|
+
imageModel(modelId: string): ImageModelV2;
|
2351
1699
|
/**
|
2352
1700
|
Returns the transcription model with the given id.
|
2353
1701
|
The model id is then passed to the provider function to get the model.
|
@@ -2355,8 +1703,8 @@ interface ProviderV1 {
|
|
2355
1703
|
@param {string} modelId - The id of the model to return.
|
2356
1704
|
|
2357
1705
|
@returns {TranscriptionModel} The transcription model associated with the id
|
2358
|
-
|
2359
|
-
|
1706
|
+
*/
|
1707
|
+
transcriptionModel?(modelId: string): TranscriptionModelV2;
|
2360
1708
|
/**
|
2361
1709
|
Returns the speech model with the given id.
|
2362
1710
|
The model id is then passed to the provider function to get the model.
|
@@ -2364,45 +1712,8 @@ interface ProviderV1 {
|
|
2364
1712
|
@param {string} modelId - The id of the model to return.
|
2365
1713
|
|
2366
1714
|
@returns {SpeechModel} The speech model associated with the id
|
2367
|
-
|
2368
|
-
|
2369
|
-
}
|
2370
|
-
|
2371
|
-
/**
|
2372
|
-
* Provider for language, text embedding, and image generation models.
|
2373
|
-
*/
|
2374
|
-
interface ProviderV2 {
|
2375
|
-
/**
|
2376
|
-
Returns the language model with the given id.
|
2377
|
-
The model id is then passed to the provider function to get the model.
|
2378
|
-
|
2379
|
-
@param {string} modelId - The id of the model to return.
|
2380
|
-
|
2381
|
-
@returns {LanguageModel} The language model associated with the id
|
2382
|
-
|
2383
|
-
@throws {NoSuchModelError} If no such model exists.
|
2384
|
-
*/
|
2385
|
-
languageModel(modelId: string): LanguageModelV2;
|
2386
|
-
/**
|
2387
|
-
Returns the text embedding model with the given id.
|
2388
|
-
The model id is then passed to the provider function to get the model.
|
2389
|
-
|
2390
|
-
@param {string} modelId - The id of the model to return.
|
2391
|
-
|
2392
|
-
@returns {LanguageModel} The language model associated with the id
|
2393
|
-
|
2394
|
-
@throws {NoSuchModelError} If no such model exists.
|
2395
|
-
*/
|
2396
|
-
textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
|
2397
|
-
/**
|
2398
|
-
Returns the image model with the given id.
|
2399
|
-
The model id is then passed to the provider function to get the model.
|
2400
|
-
|
2401
|
-
@param {string} modelId - The id of the model to return.
|
2402
|
-
|
2403
|
-
@returns {ImageModel} The image model associated with the id
|
2404
|
-
*/
|
2405
|
-
readonly imageModel: (modelId: string) => ImageModelV1;
|
1715
|
+
*/
|
1716
|
+
speechModel?(modelId: string): SpeechModelV2;
|
2406
1717
|
}
|
2407
1718
|
|
2408
|
-
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, EmptyResponseBodyError, type
|
1719
|
+
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, type ImageModelV2ProviderMetadata, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2Content, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2ResponseMetadata, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultOutput, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV2, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV2, type SpeechModelV2CallOptions, type SpeechModelV2CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV2, type TranscriptionModelV2CallOptions, type TranscriptionModelV2CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|