@ai-sdk/provider 2.0.0-canary.1 → 2.0.0-canary.10
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 +91 -0
- package/dist/index.d.mts +982 -784
- package/dist/index.d.ts +982 -784
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,65 @@
|
|
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
|
+
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
7
|
+
type JSONObject = {
|
8
|
+
[key: string]: JSONValue;
|
9
|
+
};
|
10
|
+
type JSONArray = JSONValue[];
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Additional provider-specific metadata.
|
14
|
+
* Metadata are additional outputs from the provider.
|
15
|
+
* They are passed through to the provider from the AI SDK
|
16
|
+
* and enable provider-specific functionality
|
17
|
+
* that can be fully encapsulated in the provider.
|
18
|
+
*
|
19
|
+
* This enables us to quickly ship provider-specific functionality
|
20
|
+
* without affecting the core AI SDK.
|
21
|
+
*
|
22
|
+
* The outer record is keyed by the provider name, and the inner
|
23
|
+
* record is keyed by the provider-specific metadata key.
|
24
|
+
*
|
25
|
+
* ```ts
|
26
|
+
* {
|
27
|
+
* "anthropic": {
|
28
|
+
* "cacheControl": { "type": "ephemeral" }
|
29
|
+
* }
|
30
|
+
* }
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Additional provider-specific options.
|
37
|
+
* Options are additional input to the provider.
|
38
|
+
* They are passed through to the provider from the AI SDK
|
39
|
+
* and enable provider-specific functionality
|
40
|
+
* that can be fully encapsulated in the provider.
|
41
|
+
*
|
42
|
+
* This enables us to quickly ship provider-specific functionality
|
43
|
+
* without affecting the core AI SDK.
|
44
|
+
*
|
45
|
+
* The outer record is keyed by the provider name, and the inner
|
46
|
+
* record is keyed by the provider-specific metadata key.
|
47
|
+
*
|
48
|
+
* ```ts
|
49
|
+
* {
|
50
|
+
* "anthropic": {
|
51
|
+
* "cacheControl": { "type": "ephemeral" }
|
52
|
+
* }
|
53
|
+
* }
|
54
|
+
* ```
|
55
|
+
*/
|
56
|
+
type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
57
|
+
|
4
58
|
/**
|
5
59
|
An embedding is a vector, i.e. an array of numbers.
|
6
60
|
It is e.g. used to represent a text as a vector of word embeddings.
|
7
61
|
*/
|
8
|
-
type
|
62
|
+
type EmbeddingModelV2Embedding = Array<number>;
|
9
63
|
|
10
64
|
/**
|
11
65
|
Specification for an embedding model that implements the embedding model
|
@@ -15,7 +69,7 @@ VALUE is the type of the values that the model can embed.
|
|
15
69
|
This will allow us to go beyond text embeddings in the future,
|
16
70
|
e.g. to support image embeddings
|
17
71
|
*/
|
18
|
-
type
|
72
|
+
type EmbeddingModelV2<VALUE> = {
|
19
73
|
/**
|
20
74
|
The embedding model must specify which embedding model interface
|
21
75
|
version it implements. This will allow us to evolve the embedding
|
@@ -23,7 +77,7 @@ type EmbeddingModelV1<VALUE> = {
|
|
23
77
|
implementation versions can be handled as a discriminated union
|
24
78
|
on our side.
|
25
79
|
*/
|
26
|
-
readonly specificationVersion: '
|
80
|
+
readonly specificationVersion: 'v2';
|
27
81
|
/**
|
28
82
|
Name of the provider for logging purposes.
|
29
83
|
*/
|
@@ -56,6 +110,12 @@ type EmbeddingModelV1<VALUE> = {
|
|
56
110
|
*/
|
57
111
|
abortSignal?: AbortSignal;
|
58
112
|
/**
|
113
|
+
Additional provider-specific options. They are passed through
|
114
|
+
to the provider from the AI SDK and enable provider-specific
|
115
|
+
functionality that can be fully encapsulated in the provider.
|
116
|
+
*/
|
117
|
+
providerOptions?: SharedV2ProviderOptions;
|
118
|
+
/**
|
59
119
|
Additional HTTP headers to be sent with the request.
|
60
120
|
Only applicable for HTTP-based providers.
|
61
121
|
*/
|
@@ -64,7 +124,7 @@ type EmbeddingModelV1<VALUE> = {
|
|
64
124
|
/**
|
65
125
|
Generated embeddings. They are in the same order as the input values.
|
66
126
|
*/
|
67
|
-
embeddings: Array<
|
127
|
+
embeddings: Array<EmbeddingModelV2Embedding>;
|
68
128
|
/**
|
69
129
|
Token usage. We only have input tokens for embeddings.
|
70
130
|
*/
|
@@ -72,13 +132,17 @@ type EmbeddingModelV1<VALUE> = {
|
|
72
132
|
tokens: number;
|
73
133
|
};
|
74
134
|
/**
|
75
|
-
Optional
|
135
|
+
Optional response information for debugging purposes.
|
76
136
|
*/
|
77
|
-
|
137
|
+
response?: {
|
78
138
|
/**
|
79
139
|
Response headers.
|
80
140
|
*/
|
81
|
-
headers?:
|
141
|
+
headers?: SharedV2Headers;
|
142
|
+
/**
|
143
|
+
The response body.
|
144
|
+
*/
|
145
|
+
body?: unknown;
|
82
146
|
};
|
83
147
|
}>;
|
84
148
|
};
|
@@ -305,13 +369,7 @@ declare class UnsupportedFunctionalityError extends AISDKError {
|
|
305
369
|
static isInstance(error: unknown): error is UnsupportedFunctionalityError;
|
306
370
|
}
|
307
371
|
|
308
|
-
type
|
309
|
-
type JSONObject = {
|
310
|
-
[key: string]: JSONValue;
|
311
|
-
};
|
312
|
-
type JSONArray = JSONValue[];
|
313
|
-
|
314
|
-
type ImageModelV1CallOptions = {
|
372
|
+
type ImageModelV2CallOptions = {
|
315
373
|
/**
|
316
374
|
Prompt for the image generation.
|
317
375
|
*/
|
@@ -367,9 +425,9 @@ type ImageModelV1CallOptions = {
|
|
367
425
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
368
426
|
some settings might not be supported, which can lead to suboptimal results.
|
369
427
|
*/
|
370
|
-
type
|
428
|
+
type ImageModelV2CallWarning = {
|
371
429
|
type: 'unsupported-setting';
|
372
|
-
setting: keyof
|
430
|
+
setting: keyof ImageModelV2CallOptions;
|
373
431
|
details?: string;
|
374
432
|
} | {
|
375
433
|
type: 'other';
|
@@ -379,7 +437,7 @@ type ImageModelV1CallWarning = {
|
|
379
437
|
/**
|
380
438
|
Image generation model specification version 1.
|
381
439
|
*/
|
382
|
-
type
|
440
|
+
type ImageModelV2 = {
|
383
441
|
/**
|
384
442
|
The image model must specify which image model interface
|
385
443
|
version it implements. This will allow us to evolve the image
|
@@ -404,7 +462,7 @@ type ImageModelV1 = {
|
|
404
462
|
/**
|
405
463
|
Generates an array of images.
|
406
464
|
*/
|
407
|
-
doGenerate(options:
|
465
|
+
doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
|
408
466
|
/**
|
409
467
|
Generated images as base64 encoded strings or binary data.
|
410
468
|
The images should be returned without any unnecessary conversion.
|
@@ -416,7 +474,7 @@ type ImageModelV1 = {
|
|
416
474
|
/**
|
417
475
|
Warnings for the call, e.g. unsupported settings.
|
418
476
|
*/
|
419
|
-
warnings: Array<
|
477
|
+
warnings: Array<ImageModelV2CallWarning>;
|
420
478
|
/**
|
421
479
|
Response information for telemetry and debugging purposes.
|
422
480
|
*/
|
@@ -441,138 +499,13 @@ declare function isJSONValue(value: unknown): value is JSONValue;
|
|
441
499
|
declare function isJSONArray(value: unknown): value is JSONArray;
|
442
500
|
declare function isJSONObject(value: unknown): value is JSONObject;
|
443
501
|
|
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
502
|
/**
|
570
503
|
A tool has a name, a description, and a set of parameters.
|
571
504
|
|
572
505
|
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
573
506
|
map the user-facing tool definitions to this format.
|
574
507
|
*/
|
575
|
-
type
|
508
|
+
type LanguageModelV2FunctionTool = {
|
576
509
|
/**
|
577
510
|
The type of the tool (always 'function').
|
578
511
|
*/
|
@@ -593,6 +526,11 @@ type LanguageModelV1FunctionTool = {
|
|
593
526
|
parameters: JSONSchema7;
|
594
527
|
};
|
595
528
|
|
529
|
+
/**
|
530
|
+
Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
531
|
+
*/
|
532
|
+
type LanguageModelV2DataContent = Uint8Array | string | URL;
|
533
|
+
|
596
534
|
/**
|
597
535
|
A prompt is a list of messages.
|
598
536
|
|
@@ -602,128 +540,92 @@ tool calls. The validation happens at runtime.
|
|
602
540
|
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
603
541
|
user-facing prompt types such as chat or instruction prompts to this format.
|
604
542
|
*/
|
605
|
-
type
|
606
|
-
type
|
543
|
+
type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
|
544
|
+
type LanguageModelV2Message = ({
|
607
545
|
role: 'system';
|
608
546
|
content: string;
|
609
547
|
} | {
|
610
548
|
role: 'user';
|
611
|
-
content: Array<
|
549
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
|
612
550
|
} | {
|
613
551
|
role: 'assistant';
|
614
|
-
content: Array<
|
552
|
+
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart>;
|
615
553
|
} | {
|
616
554
|
role: 'tool';
|
617
|
-
content: Array<
|
555
|
+
content: Array<LanguageModelV2ToolResultPart>;
|
618
556
|
}) & {
|
619
557
|
/**
|
620
|
-
* Additional provider-specific
|
558
|
+
* Additional provider-specific options. They are passed through
|
621
559
|
* to the provider from the AI SDK and enable provider-specific
|
622
560
|
* functionality that can be fully encapsulated in the provider.
|
623
561
|
*/
|
624
|
-
|
562
|
+
providerOptions?: SharedV2ProviderOptions;
|
625
563
|
};
|
626
564
|
/**
|
627
565
|
Text content part of a prompt. It contains a string of text.
|
628
566
|
*/
|
629
|
-
interface
|
567
|
+
interface LanguageModelV2TextPart {
|
630
568
|
type: 'text';
|
631
569
|
/**
|
632
570
|
The text content.
|
633
571
|
*/
|
634
572
|
text: string;
|
635
573
|
/**
|
636
|
-
* Additional provider-specific
|
574
|
+
* Additional provider-specific options. They are passed through
|
637
575
|
* to the provider from the AI SDK and enable provider-specific
|
638
576
|
* functionality that can be fully encapsulated in the provider.
|
639
577
|
*/
|
640
|
-
|
578
|
+
providerOptions?: SharedV2ProviderOptions;
|
641
579
|
}
|
642
580
|
/**
|
643
581
|
Reasoning content part of a prompt. It contains a string of reasoning text.
|
644
582
|
*/
|
645
|
-
interface
|
583
|
+
interface LanguageModelV2ReasoningPart {
|
646
584
|
type: 'reasoning';
|
647
585
|
/**
|
648
586
|
The reasoning text.
|
649
587
|
*/
|
650
588
|
text: string;
|
651
589
|
/**
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
/**
|
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.
|
590
|
+
* Additional provider-specific options. They are passed through
|
591
|
+
* to the provider from the AI SDK and enable provider-specific
|
592
|
+
* functionality that can be fully encapsulated in the provider.
|
659
593
|
*/
|
660
|
-
|
594
|
+
providerOptions?: SharedV2ProviderOptions;
|
661
595
|
}
|
662
596
|
/**
|
663
|
-
|
597
|
+
File content part of a prompt. It contains a file.
|
664
598
|
*/
|
665
|
-
interface
|
666
|
-
type: '
|
599
|
+
interface LanguageModelV2FilePart {
|
600
|
+
type: 'file';
|
667
601
|
/**
|
668
|
-
|
602
|
+
* Optional filename of the file.
|
669
603
|
*/
|
670
|
-
|
604
|
+
filename?: string;
|
671
605
|
/**
|
672
|
-
|
673
|
-
|
674
|
-
|
606
|
+
File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
607
|
+
*/
|
608
|
+
data: LanguageModelV2DataContent;
|
609
|
+
/**
|
610
|
+
IANA media type of the file.
|
611
|
+
|
612
|
+
Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
|
613
|
+
|
614
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
675
615
|
*/
|
676
|
-
|
616
|
+
mediaType: string;
|
617
|
+
/**
|
618
|
+
* Additional provider-specific options. They are passed through
|
619
|
+
* to the provider from the AI SDK and enable provider-specific
|
620
|
+
* functionality that can be fully encapsulated in the provider.
|
621
|
+
*/
|
622
|
+
providerOptions?: SharedV2ProviderOptions;
|
677
623
|
}
|
678
624
|
/**
|
679
|
-
|
625
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
680
626
|
*/
|
681
|
-
interface
|
682
|
-
type: '
|
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
|
693
|
-
* to the provider from the AI SDK and enable provider-specific
|
694
|
-
* functionality that can be fully encapsulated in the provider.
|
695
|
-
*/
|
696
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
697
|
-
}
|
698
|
-
/**
|
699
|
-
File content part of a prompt. It contains a file.
|
700
|
-
*/
|
701
|
-
interface LanguageModelV1FilePart {
|
702
|
-
type: 'file';
|
703
|
-
/**
|
704
|
-
* Optional filename of the file.
|
705
|
-
*/
|
706
|
-
filename?: string;
|
707
|
-
/**
|
708
|
-
File data as base64 encoded string or as a URL.
|
709
|
-
*/
|
710
|
-
data: string | URL;
|
711
|
-
/**
|
712
|
-
Mime type of the file.
|
713
|
-
*/
|
714
|
-
mimeType: string;
|
715
|
-
/**
|
716
|
-
* Additional provider-specific metadata. They are passed through
|
717
|
-
* to the provider from the AI SDK and enable provider-specific
|
718
|
-
* functionality that can be fully encapsulated in the provider.
|
719
|
-
*/
|
720
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
721
|
-
}
|
722
|
-
/**
|
723
|
-
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
724
|
-
*/
|
725
|
-
interface LanguageModelV1ToolCallPart {
|
726
|
-
type: 'tool-call';
|
627
|
+
interface LanguageModelV2ToolCallPart {
|
628
|
+
type: 'tool-call';
|
727
629
|
/**
|
728
630
|
ID of the tool call. This ID is used to match the tool call with the tool result.
|
729
631
|
*/
|
@@ -737,16 +639,16 @@ interface LanguageModelV1ToolCallPart {
|
|
737
639
|
*/
|
738
640
|
args: unknown;
|
739
641
|
/**
|
740
|
-
* Additional provider-specific
|
642
|
+
* Additional provider-specific options. They are passed through
|
741
643
|
* to the provider from the AI SDK and enable provider-specific
|
742
644
|
* functionality that can be fully encapsulated in the provider.
|
743
645
|
*/
|
744
|
-
|
646
|
+
providerOptions?: SharedV2ProviderOptions;
|
745
647
|
}
|
746
648
|
/**
|
747
649
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
748
650
|
*/
|
749
|
-
interface
|
651
|
+
interface LanguageModelV2ToolResultPart {
|
750
652
|
type: 'tool-result';
|
751
653
|
/**
|
752
654
|
ID of the tool call that this result is associated with.
|
@@ -781,22 +683,24 @@ base-64 encoded image data
|
|
781
683
|
*/
|
782
684
|
data: string;
|
783
685
|
/**
|
784
|
-
|
686
|
+
IANA media type of the image.
|
687
|
+
|
688
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
785
689
|
*/
|
786
|
-
|
690
|
+
mediaType?: string;
|
787
691
|
}>;
|
788
692
|
/**
|
789
|
-
* Additional provider-specific
|
693
|
+
* Additional provider-specific options. They are passed through
|
790
694
|
* to the provider from the AI SDK and enable provider-specific
|
791
695
|
* functionality that can be fully encapsulated in the provider.
|
792
696
|
*/
|
793
|
-
|
697
|
+
providerOptions?: SharedV2ProviderOptions;
|
794
698
|
}
|
795
699
|
|
796
700
|
/**
|
797
701
|
The configuration of a tool that is defined by the provider.
|
798
702
|
*/
|
799
|
-
type
|
703
|
+
type LanguageModelV2ProviderDefinedTool = {
|
800
704
|
/**
|
801
705
|
The type of the tool (always 'provider-defined').
|
802
706
|
*/
|
@@ -815,7 +719,7 @@ type LanguageModelV1ProviderDefinedTool = {
|
|
815
719
|
args: Record<string, unknown>;
|
816
720
|
};
|
817
721
|
|
818
|
-
type
|
722
|
+
type LanguageModelV2ToolChoice = {
|
819
723
|
type: 'auto';
|
820
724
|
} | {
|
821
725
|
type: 'none';
|
@@ -826,7 +730,7 @@ type LanguageModelV1ToolChoice = {
|
|
826
730
|
toolName: string;
|
827
731
|
};
|
828
732
|
|
829
|
-
type
|
733
|
+
type LanguageModelV2CallOptions = {
|
830
734
|
/**
|
831
735
|
Whether the user provided the input as messages or as
|
832
736
|
a prompt. This can help guide non-chat models in the
|
@@ -835,29 +739,62 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
|
835
739
|
*/
|
836
740
|
inputFormat: 'messages' | 'prompt';
|
837
741
|
/**
|
838
|
-
|
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.
|
742
|
+
A language mode prompt is a standardized prompt type.
|
844
743
|
|
845
|
-
|
846
|
-
|
847
|
-
|
744
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
745
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
746
|
+
That approach allows us to evolve the user facing prompts without breaking
|
747
|
+
the language model interface.
|
848
748
|
*/
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
749
|
+
prompt: LanguageModelV2Prompt;
|
750
|
+
/**
|
751
|
+
Maximum number of tokens to generate.
|
752
|
+
*/
|
753
|
+
maxOutputTokens?: number;
|
754
|
+
/**
|
755
|
+
Temperature setting.
|
756
|
+
|
757
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
758
|
+
*/
|
759
|
+
temperature?: number;
|
760
|
+
/**
|
761
|
+
Stop sequences.
|
762
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
763
|
+
Providers may have limits on the number of stop sequences.
|
764
|
+
*/
|
765
|
+
stopSequences?: string[];
|
766
|
+
/**
|
767
|
+
Nucleus sampling.
|
768
|
+
|
769
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
770
|
+
*/
|
771
|
+
topP?: number;
|
772
|
+
/**
|
773
|
+
Only sample from the top K options for each subsequent token.
|
774
|
+
|
775
|
+
Used to remove "long tail" low probability responses.
|
776
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
777
|
+
*/
|
778
|
+
topK?: number;
|
779
|
+
/**
|
780
|
+
Presence penalty setting. It affects the likelihood of the model to
|
781
|
+
repeat information that is already in the prompt.
|
782
|
+
*/
|
783
|
+
presencePenalty?: number;
|
784
|
+
/**
|
785
|
+
Frequency penalty setting. It affects the likelihood of the model
|
786
|
+
to repeatedly use the same words or phrases.
|
787
|
+
*/
|
788
|
+
frequencyPenalty?: number;
|
789
|
+
/**
|
790
|
+
Response format. The output can either be text or JSON. Default is text.
|
791
|
+
|
792
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
793
|
+
*/
|
794
|
+
responseFormat?: {
|
795
|
+
type: 'text';
|
859
796
|
} | {
|
860
|
-
type: '
|
797
|
+
type: 'json';
|
861
798
|
/**
|
862
799
|
* JSON schema that the generated output should conform to.
|
863
800
|
*/
|
@@ -870,38 +807,48 @@ Specifies how the tool should be selected. Defaults to 'auto'.
|
|
870
807
|
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
871
808
|
*/
|
872
809
|
description?: string;
|
873
|
-
} | {
|
874
|
-
type: 'object-tool';
|
875
|
-
tool: LanguageModelV1FunctionTool;
|
876
810
|
};
|
877
811
|
/**
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
That approach allows us to evolve the user facing prompts without breaking
|
883
|
-
the language model interface.
|
884
|
-
*/
|
885
|
-
prompt: LanguageModelV1Prompt;
|
812
|
+
The seed (integer) to use for random sampling. If set and supported
|
813
|
+
by the model, calls will generate deterministic results.
|
814
|
+
*/
|
815
|
+
seed?: number;
|
886
816
|
/**
|
887
|
-
|
888
|
-
|
889
|
-
|
817
|
+
The tools that are available for the model.
|
818
|
+
*/
|
819
|
+
tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
|
820
|
+
/**
|
821
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
822
|
+
*/
|
823
|
+
toolChoice?: LanguageModelV2ToolChoice;
|
824
|
+
/**
|
825
|
+
Abort signal for cancelling the operation.
|
826
|
+
*/
|
827
|
+
abortSignal?: AbortSignal;
|
828
|
+
/**
|
829
|
+
Additional HTTP headers to be sent with the request.
|
830
|
+
Only applicable for HTTP-based providers.
|
831
|
+
*/
|
832
|
+
headers?: Record<string, string | undefined>;
|
833
|
+
/**
|
834
|
+
* Additional provider-specific options. They are passed through
|
835
|
+
* to the provider from the AI SDK and enable provider-specific
|
836
|
+
* functionality that can be fully encapsulated in the provider.
|
890
837
|
*/
|
891
|
-
|
838
|
+
providerOptions?: SharedV2ProviderOptions;
|
892
839
|
};
|
893
840
|
|
894
841
|
/**
|
895
842
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
896
843
|
some settings might not be supported, which can lead to suboptimal results.
|
897
844
|
*/
|
898
|
-
type
|
845
|
+
type LanguageModelV2CallWarning = {
|
899
846
|
type: 'unsupported-setting';
|
900
|
-
setting: keyof
|
847
|
+
setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
|
901
848
|
details?: string;
|
902
849
|
} | {
|
903
850
|
type: 'unsupported-tool';
|
904
|
-
tool:
|
851
|
+
tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
|
905
852
|
details?: string;
|
906
853
|
} | {
|
907
854
|
type: 'other';
|
@@ -909,230 +856,247 @@ type LanguageModelV1CallWarning = {
|
|
909
856
|
};
|
910
857
|
|
911
858
|
/**
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
- `stop`: model generated stop sequence
|
916
|
-
- `length`: model generated maximum number of tokens
|
917
|
-
- `content-filter`: content filter violation stopped the model
|
918
|
-
- `tool-calls`: model triggered tool calls
|
919
|
-
- `error`: model stopped because of an error
|
920
|
-
- `other`: model stopped for other reasons
|
921
|
-
- `unknown`: the model has not transmitted a finish reason
|
859
|
+
A file that has been generated by the model.
|
860
|
+
Generated files as base64 encoded strings or binary data.
|
861
|
+
The files should be returned without any unnecessary conversion.
|
922
862
|
*/
|
923
|
-
type
|
924
|
-
|
925
|
-
type LanguageModelV1FunctionToolCall = {
|
926
|
-
toolCallType: 'function';
|
927
|
-
toolCallId: string;
|
928
|
-
toolName: string;
|
863
|
+
type LanguageModelV2File = {
|
864
|
+
type: 'file';
|
929
865
|
/**
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
866
|
+
The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
|
867
|
+
|
868
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
869
|
+
*/
|
870
|
+
mediaType: string;
|
871
|
+
/**
|
872
|
+
Generated file data as base64 encoded strings or binary data.
|
873
|
+
|
874
|
+
The file data should be returned without any unnecessary conversion.
|
875
|
+
If the API returns base64 encoded strings, the file data should be returned
|
876
|
+
as base64 encoded strings. If the API returns binary data, the file data should
|
877
|
+
be returned as binary data.
|
878
|
+
*/
|
879
|
+
data: string | Uint8Array;
|
934
880
|
};
|
935
881
|
|
936
882
|
/**
|
937
|
-
|
883
|
+
Reasoning that the model has generated.
|
938
884
|
*/
|
939
|
-
type
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
}
|
885
|
+
type LanguageModelV2Reasoning = {
|
886
|
+
type: 'reasoning';
|
887
|
+
text: string;
|
888
|
+
/**
|
889
|
+
* Optional provider-specific metadata for the reasoning part.
|
890
|
+
*/
|
891
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
892
|
+
};
|
947
893
|
|
948
894
|
/**
|
949
|
-
|
895
|
+
A source that has been used as input to generate the response.
|
950
896
|
*/
|
951
|
-
type
|
897
|
+
type LanguageModelV2Source = {
|
898
|
+
type: 'source';
|
952
899
|
/**
|
953
|
-
|
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.
|
900
|
+
* A URL source. This is return by web search RAG models.
|
958
901
|
*/
|
959
|
-
|
902
|
+
sourceType: 'url';
|
960
903
|
/**
|
961
|
-
|
904
|
+
* The ID of the source.
|
962
905
|
*/
|
963
|
-
|
906
|
+
id: string;
|
964
907
|
/**
|
965
|
-
|
908
|
+
* The URL of the source.
|
966
909
|
*/
|
967
|
-
|
910
|
+
url: string;
|
968
911
|
/**
|
969
|
-
|
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.
|
912
|
+
* The title of the source.
|
975
913
|
*/
|
976
|
-
|
914
|
+
title?: string;
|
977
915
|
/**
|
978
|
-
|
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.
|
916
|
+
* Additional provider metadata for the source.
|
982
917
|
*/
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
918
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
919
|
+
};
|
920
|
+
|
921
|
+
/**
|
922
|
+
Text that the model has generated.
|
923
|
+
*/
|
924
|
+
type LanguageModelV2Text = {
|
925
|
+
type: 'text';
|
926
|
+
/**
|
927
|
+
The text content.
|
928
|
+
*/
|
929
|
+
text: string;
|
930
|
+
};
|
931
|
+
|
932
|
+
/**
|
933
|
+
Tool calls that the model has generated.
|
934
|
+
*/
|
935
|
+
type LanguageModelV2ToolCall = {
|
936
|
+
type: 'tool-call';
|
937
|
+
toolCallType: 'function';
|
938
|
+
toolCallId: string;
|
939
|
+
toolName: string;
|
940
|
+
/**
|
941
|
+
Stringified JSON object with the tool call arguments. Must match the
|
942
|
+
parameters schema of the tool.
|
943
|
+
*/
|
944
|
+
args: string;
|
945
|
+
};
|
946
|
+
|
947
|
+
type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall;
|
948
|
+
|
949
|
+
/**
|
950
|
+
Reason why a language model finished generating a response.
|
951
|
+
|
952
|
+
Can be one of the following:
|
953
|
+
- `stop`: model generated stop sequence
|
954
|
+
- `length`: model generated maximum number of tokens
|
955
|
+
- `content-filter`: content filter violation stopped the model
|
956
|
+
- `tool-calls`: model triggered tool calls
|
957
|
+
- `error`: model stopped because of an error
|
958
|
+
- `other`: model stopped for other reasons
|
959
|
+
- `unknown`: the model has not transmitted a finish reason
|
960
|
+
*/
|
961
|
+
type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
962
|
+
|
963
|
+
interface LanguageModelV2ResponseMetadata {
|
964
|
+
/**
|
965
|
+
ID for the generated response, if the provider sends one.
|
966
|
+
*/
|
967
|
+
id?: string;
|
968
|
+
/**
|
969
|
+
Timestamp for the start of the generated response, if the provider sends one.
|
999
970
|
*/
|
1000
|
-
|
971
|
+
timestamp?: Date;
|
1001
972
|
/**
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
973
|
+
The ID of the response model that was used to generate the response, if the provider sends one.
|
974
|
+
*/
|
975
|
+
modelId?: string;
|
976
|
+
}
|
977
|
+
|
978
|
+
type LanguageModelV2ToolCallDelta = {
|
979
|
+
type: 'tool-call-delta';
|
980
|
+
toolCallType: 'function';
|
981
|
+
toolCallId: string;
|
982
|
+
toolName: string;
|
983
|
+
argsTextDelta: string;
|
984
|
+
};
|
985
|
+
|
986
|
+
/**
|
987
|
+
* Usage information for a language model call.
|
988
|
+
*/
|
989
|
+
type LanguageModelV2Usage = {
|
990
|
+
/**
|
991
|
+
* The number of input (prompt) tokens used.
|
1007
992
|
*/
|
1008
|
-
|
993
|
+
inputTokens: number | undefined;
|
994
|
+
/**
|
995
|
+
* The number of output (completion) tokens used.
|
996
|
+
*/
|
997
|
+
outputTokens: number | undefined;
|
998
|
+
};
|
999
|
+
|
1000
|
+
type LanguageModelV2StreamPart = LanguageModelV2Content | {
|
1001
|
+
type: 'reasoning-part-finish';
|
1002
|
+
} | LanguageModelV2ToolCallDelta | {
|
1003
|
+
type: 'stream-start';
|
1004
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
1005
|
+
} | ({
|
1006
|
+
type: 'response-metadata';
|
1007
|
+
} & LanguageModelV2ResponseMetadata) | {
|
1008
|
+
type: 'finish';
|
1009
|
+
usage: LanguageModelV2Usage;
|
1010
|
+
finishReason: LanguageModelV2FinishReason;
|
1011
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1012
|
+
} | {
|
1013
|
+
type: 'error';
|
1014
|
+
error: unknown;
|
1015
|
+
};
|
1016
|
+
|
1017
|
+
/**
|
1018
|
+
Specification for a language model that implements the language model interface version 2.
|
1019
|
+
*/
|
1020
|
+
type LanguageModelV2 = {
|
1021
|
+
/**
|
1022
|
+
The language model must specify which language model interface
|
1023
|
+
version it implements. This will allow us to evolve the language
|
1024
|
+
model interface and retain backwards compatibility. The different
|
1025
|
+
implementation versions can be handled as a discriminated union
|
1026
|
+
on our side.
|
1027
|
+
*/
|
1028
|
+
readonly specificationVersion: 'v2';
|
1029
|
+
/**
|
1030
|
+
Name of the provider for logging purposes.
|
1031
|
+
*/
|
1032
|
+
readonly provider: string;
|
1033
|
+
/**
|
1034
|
+
Provider-specific model ID for logging purposes.
|
1035
|
+
*/
|
1036
|
+
readonly modelId: string;
|
1037
|
+
/**
|
1038
|
+
* Returns a map of supported URL patterns for the model.
|
1039
|
+
* The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
|
1040
|
+
* and the values are arrays of regular expressions that match the URL paths.
|
1041
|
+
*
|
1042
|
+
* The matching should be against lower-case URLs.
|
1043
|
+
*
|
1044
|
+
* Matched URLs are supported natively by the model and are not downloaded.
|
1045
|
+
*
|
1046
|
+
* @returns A promise resolving to a map of supported URL patterns.
|
1047
|
+
*/
|
1048
|
+
getSupportedUrls(): PromiseLike<Record<string, RegExp[]>>;
|
1009
1049
|
/**
|
1010
1050
|
Generates a language model output (non-streaming).
|
1011
1051
|
|
1012
1052
|
Naming: "do" prefix to prevent accidental direct usage of the method
|
1013
1053
|
by the user.
|
1014
1054
|
*/
|
1015
|
-
doGenerate(options:
|
1016
|
-
/**
|
1017
|
-
Text that the model has generated.
|
1018
|
-
Can be undefined if the model did not generate any text.
|
1019
|
-
*/
|
1020
|
-
text?: string;
|
1021
|
-
/**
|
1022
|
-
Reasoning that the model has generated.
|
1023
|
-
Can be undefined if the model does not support reasoning.
|
1024
|
-
*/
|
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
|
-
}>;
|
1036
|
-
/**
|
1037
|
-
Generated files as base64 encoded strings or binary data.
|
1038
|
-
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
|
-
*/
|
1043
|
-
files?: Array<{
|
1044
|
-
data: string | Uint8Array;
|
1045
|
-
mimeType: string;
|
1046
|
-
}>;
|
1055
|
+
doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
|
1047
1056
|
/**
|
1048
|
-
|
1049
|
-
Can be undefined if the model did not generate any tool calls.
|
1057
|
+
Ordered content that the model has generated.
|
1050
1058
|
*/
|
1051
|
-
|
1059
|
+
content: Array<LanguageModelV2Content>;
|
1052
1060
|
/**
|
1053
1061
|
Finish reason.
|
1054
1062
|
*/
|
1055
|
-
finishReason:
|
1063
|
+
finishReason: LanguageModelV2FinishReason;
|
1056
1064
|
/**
|
1057
1065
|
Usage information.
|
1058
1066
|
*/
|
1059
|
-
usage:
|
1060
|
-
promptTokens: number;
|
1061
|
-
completionTokens: number;
|
1062
|
-
};
|
1067
|
+
usage: LanguageModelV2Usage;
|
1063
1068
|
/**
|
1064
|
-
|
1069
|
+
Additional provider-specific metadata. They are passed through
|
1070
|
+
from the provider to the AI SDK and enable provider-specific
|
1071
|
+
results that can be fully encapsulated in the provider.
|
1065
1072
|
*/
|
1066
|
-
|
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
|
-
};
|
1078
|
-
/**
|
1079
|
-
Optional response information for telemetry and debugging purposes.
|
1080
|
-
*/
|
1081
|
-
rawResponse?: {
|
1082
|
-
/**
|
1083
|
-
Response headers.
|
1084
|
-
*/
|
1085
|
-
headers?: Record<string, string>;
|
1086
|
-
/**
|
1087
|
-
Response body.
|
1088
|
-
*/
|
1089
|
-
body?: unknown;
|
1090
|
-
};
|
1073
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1091
1074
|
/**
|
1092
1075
|
Optional request information for telemetry and debugging purposes.
|
1093
1076
|
*/
|
1094
1077
|
request?: {
|
1095
1078
|
/**
|
1096
|
-
|
1097
|
-
Non-HTTP(s) providers should not set this.
|
1079
|
+
Request HTTP body that was sent to the provider API.
|
1098
1080
|
*/
|
1099
|
-
body?:
|
1081
|
+
body?: unknown;
|
1100
1082
|
};
|
1101
1083
|
/**
|
1102
1084
|
Optional response information for telemetry and debugging purposes.
|
1103
1085
|
*/
|
1104
|
-
response?: {
|
1086
|
+
response?: LanguageModelV2ResponseMetadata & {
|
1105
1087
|
/**
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
/**
|
1110
|
-
Timestamp for the start of the generated response, if the provider sends one.
|
1111
|
-
*/
|
1112
|
-
timestamp?: Date;
|
1088
|
+
Response headers.
|
1089
|
+
*/
|
1090
|
+
headers?: SharedV2Headers;
|
1113
1091
|
/**
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1092
|
+
Response HTTP body.
|
1093
|
+
*/
|
1094
|
+
body?: unknown;
|
1117
1095
|
};
|
1118
|
-
warnings?: LanguageModelV1CallWarning[];
|
1119
|
-
/**
|
1120
|
-
Additional provider-specific metadata. They are passed through
|
1121
|
-
from the provider to the AI SDK and enable provider-specific
|
1122
|
-
results that can be fully encapsulated in the provider.
|
1123
|
-
*/
|
1124
|
-
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1125
|
-
/**
|
1126
|
-
Sources that have been used as input to generate the response.
|
1127
|
-
*/
|
1128
|
-
sources?: LanguageModelV1Source[];
|
1129
1096
|
/**
|
1130
|
-
|
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
|
1097
|
+
Warnings for the call, e.g. unsupported settings.
|
1134
1098
|
*/
|
1135
|
-
|
1099
|
+
warnings: Array<LanguageModelV2CallWarning>;
|
1136
1100
|
}>;
|
1137
1101
|
/**
|
1138
1102
|
Generates a language model output (streaming).
|
@@ -1142,105 +1106,209 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1142
1106
|
*
|
1143
1107
|
@return A stream of higher-level language model output parts.
|
1144
1108
|
*/
|
1145
|
-
doStream(options:
|
1146
|
-
stream: ReadableStream<
|
1109
|
+
doStream(options: LanguageModelV2CallOptions): PromiseLike<{
|
1110
|
+
stream: ReadableStream<LanguageModelV2StreamPart>;
|
1147
1111
|
/**
|
1148
|
-
|
1112
|
+
Optional request information for telemetry and debugging purposes.
|
1149
1113
|
*/
|
1150
|
-
|
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;
|
1114
|
+
request?: {
|
1156
1115
|
/**
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
rawSettings: Record<string, unknown>;
|
1116
|
+
Request HTTP body that was sent to the provider API.
|
1117
|
+
*/
|
1118
|
+
body?: unknown;
|
1161
1119
|
};
|
1162
1120
|
/**
|
1163
|
-
Optional
|
1121
|
+
Optional response data.
|
1164
1122
|
*/
|
1165
|
-
|
1123
|
+
response?: {
|
1166
1124
|
/**
|
1167
1125
|
Response headers.
|
1168
1126
|
*/
|
1169
|
-
headers?:
|
1127
|
+
headers?: SharedV2Headers;
|
1170
1128
|
};
|
1129
|
+
}>;
|
1130
|
+
};
|
1131
|
+
|
1132
|
+
/**
|
1133
|
+
* Experimental middleware for LanguageModelV2.
|
1134
|
+
* This type defines the structure for middleware that can be used to modify
|
1135
|
+
* the behavior of LanguageModelV2 operations.
|
1136
|
+
*/
|
1137
|
+
type LanguageModelV2Middleware = {
|
1138
|
+
/**
|
1139
|
+
* Middleware specification version. Use `v2` for the current version.
|
1140
|
+
*/
|
1141
|
+
middlewareVersion?: 'v2' | undefined;
|
1142
|
+
/**
|
1143
|
+
* Transforms the parameters before they are passed to the language model.
|
1144
|
+
* @param options - Object containing the type of operation and the parameters.
|
1145
|
+
* @param options.type - The type of operation ('generate' or 'stream').
|
1146
|
+
* @param options.params - The original parameters for the language model call.
|
1147
|
+
* @returns A promise that resolves to the transformed parameters.
|
1148
|
+
*/
|
1149
|
+
transformParams?: (options: {
|
1150
|
+
type: 'generate' | 'stream';
|
1151
|
+
params: LanguageModelV2CallOptions;
|
1152
|
+
}) => PromiseLike<LanguageModelV2CallOptions>;
|
1153
|
+
/**
|
1154
|
+
* Wraps the generate operation of the language model.
|
1155
|
+
* @param options - Object containing the generate function, parameters, and model.
|
1156
|
+
* @param options.doGenerate - The original generate function.
|
1157
|
+
* @param options.doStream - The original stream function.
|
1158
|
+
* @param options.params - The parameters for the generate call. If the
|
1159
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1160
|
+
* @param options.model - The language model instance.
|
1161
|
+
* @returns A promise that resolves to the result of the generate operation.
|
1162
|
+
*/
|
1163
|
+
wrapGenerate?: (options: {
|
1164
|
+
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
1165
|
+
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
1166
|
+
params: LanguageModelV2CallOptions;
|
1167
|
+
model: LanguageModelV2;
|
1168
|
+
}) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
|
1169
|
+
/**
|
1170
|
+
* Wraps the stream operation of the language model.
|
1171
|
+
*
|
1172
|
+
* @param options - Object containing the stream function, parameters, and model.
|
1173
|
+
* @param options.doGenerate - The original generate function.
|
1174
|
+
* @param options.doStream - The original stream function.
|
1175
|
+
* @param options.params - The parameters for the stream call. If the
|
1176
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1177
|
+
* @param options.model - The language model instance.
|
1178
|
+
* @returns A promise that resolves to the result of the stream operation.
|
1179
|
+
*/
|
1180
|
+
wrapStream?: (options: {
|
1181
|
+
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
1182
|
+
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
1183
|
+
params: LanguageModelV2CallOptions;
|
1184
|
+
model: LanguageModelV2;
|
1185
|
+
}) => PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
1186
|
+
};
|
1187
|
+
|
1188
|
+
/**
|
1189
|
+
* Additional provider-specific metadata. They are passed through
|
1190
|
+
* to the provider from the AI SDK and enable provider-specific
|
1191
|
+
* functionality that can be fully encapsulated in the provider.
|
1192
|
+
*
|
1193
|
+
* This enables us to quickly ship provider-specific functionality
|
1194
|
+
* without affecting the core AI SDK.
|
1195
|
+
*
|
1196
|
+
* The outer record is keyed by the provider name, and the inner
|
1197
|
+
* record is keyed by the provider-specific metadata key.
|
1198
|
+
*
|
1199
|
+
* ```ts
|
1200
|
+
* {
|
1201
|
+
* "anthropic": {
|
1202
|
+
* "cacheControl": { "type": "ephemeral" }
|
1203
|
+
* }
|
1204
|
+
* }
|
1205
|
+
* ```
|
1206
|
+
*/
|
1207
|
+
type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
1208
|
+
|
1209
|
+
/**
|
1210
|
+
* A source that has been used as input to generate the response.
|
1211
|
+
*/
|
1212
|
+
type LanguageModelV1Source = {
|
1213
|
+
/**
|
1214
|
+
* A URL source. This is return by web search RAG models.
|
1215
|
+
*/
|
1216
|
+
sourceType: 'url';
|
1217
|
+
/**
|
1218
|
+
* The ID of the source.
|
1219
|
+
*/
|
1220
|
+
id: string;
|
1221
|
+
/**
|
1222
|
+
* The URL of the source.
|
1223
|
+
*/
|
1224
|
+
url: string;
|
1225
|
+
/**
|
1226
|
+
* The title of the source.
|
1227
|
+
*/
|
1228
|
+
title?: string;
|
1229
|
+
/**
|
1230
|
+
* Additional provider metadata for the source.
|
1231
|
+
*/
|
1232
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1233
|
+
};
|
1234
|
+
|
1235
|
+
type LanguageModelV1CallSettings = {
|
1236
|
+
/**
|
1237
|
+
Maximum number of tokens to generate.
|
1238
|
+
*/
|
1239
|
+
maxTokens?: number;
|
1240
|
+
/**
|
1241
|
+
Temperature setting.
|
1242
|
+
|
1243
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
1244
|
+
*/
|
1245
|
+
temperature?: number;
|
1246
|
+
/**
|
1247
|
+
Stop sequences.
|
1248
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
1249
|
+
Providers may have limits on the number of stop sequences.
|
1250
|
+
*/
|
1251
|
+
stopSequences?: string[];
|
1252
|
+
/**
|
1253
|
+
Nucleus sampling.
|
1254
|
+
|
1255
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
1256
|
+
*/
|
1257
|
+
topP?: number;
|
1258
|
+
/**
|
1259
|
+
Only sample from the top K options for each subsequent token.
|
1260
|
+
|
1261
|
+
Used to remove "long tail" low probability responses.
|
1262
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
1263
|
+
*/
|
1264
|
+
topK?: number;
|
1265
|
+
/**
|
1266
|
+
Presence penalty setting. It affects the likelihood of the model to
|
1267
|
+
repeat information that is already in the prompt.
|
1268
|
+
*/
|
1269
|
+
presencePenalty?: number;
|
1270
|
+
/**
|
1271
|
+
Frequency penalty setting. It affects the likelihood of the model
|
1272
|
+
to repeatedly use the same words or phrases.
|
1273
|
+
*/
|
1274
|
+
frequencyPenalty?: number;
|
1275
|
+
/**
|
1276
|
+
Response format. The output can either be text or JSON. Default is text.
|
1277
|
+
|
1278
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1279
|
+
*/
|
1280
|
+
responseFormat?: {
|
1281
|
+
type: 'text';
|
1282
|
+
} | {
|
1283
|
+
type: 'json';
|
1171
1284
|
/**
|
1172
|
-
|
1285
|
+
* JSON schema that the generated output should conform to.
|
1173
1286
|
*/
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
Non-HTTP(s) providers should not set this.
|
1287
|
+
schema?: JSONSchema7;
|
1288
|
+
/**
|
1289
|
+
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1178
1290
|
*/
|
1179
|
-
|
1180
|
-
};
|
1291
|
+
name?: string;
|
1181
1292
|
/**
|
1182
|
-
|
1293
|
+
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1183
1294
|
*/
|
1184
|
-
|
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;
|
1295
|
+
description?: string;
|
1296
|
+
};
|
1205
1297
|
/**
|
1206
|
-
|
1207
|
-
|
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.
|
1298
|
+
The seed (integer) to use for random sampling. If set and supported
|
1299
|
+
by the model, calls will generate deterministic results.
|
1211
1300
|
*/
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
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;
|
1238
|
-
};
|
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;
|
1301
|
+
seed?: number;
|
1302
|
+
/**
|
1303
|
+
Abort signal for cancelling the operation.
|
1304
|
+
*/
|
1305
|
+
abortSignal?: AbortSignal;
|
1306
|
+
/**
|
1307
|
+
Additional HTTP headers to be sent with the request.
|
1308
|
+
Only applicable for HTTP-based providers.
|
1309
|
+
*/
|
1310
|
+
headers?: Record<string, string | undefined>;
|
1311
|
+
};
|
1244
1312
|
|
1245
1313
|
/**
|
1246
1314
|
A tool has a name, a description, and a set of parameters.
|
@@ -1248,7 +1316,7 @@ A tool has a name, a description, and a set of parameters.
|
|
1248
1316
|
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
1249
1317
|
map the user-facing tool definitions to this format.
|
1250
1318
|
*/
|
1251
|
-
type
|
1319
|
+
type LanguageModelV1FunctionTool = {
|
1252
1320
|
/**
|
1253
1321
|
The type of the tool (always 'function').
|
1254
1322
|
*/
|
@@ -1269,29 +1337,6 @@ type LanguageModelV2FunctionTool = {
|
|
1269
1337
|
parameters: JSONSchema7;
|
1270
1338
|
};
|
1271
1339
|
|
1272
|
-
/**
|
1273
|
-
* Additional provider-specific options.
|
1274
|
-
* Options are additional input to the provider.
|
1275
|
-
* They are passed through to the provider from the AI SDK
|
1276
|
-
* and enable provider-specific functionality
|
1277
|
-
* that can be fully encapsulated in the provider.
|
1278
|
-
*
|
1279
|
-
* This enables us to quickly ship provider-specific functionality
|
1280
|
-
* without affecting the core AI SDK.
|
1281
|
-
*
|
1282
|
-
* The outer record is keyed by the provider name, and the inner
|
1283
|
-
* record is keyed by the provider-specific metadata key.
|
1284
|
-
*
|
1285
|
-
* ```ts
|
1286
|
-
* {
|
1287
|
-
* "anthropic": {
|
1288
|
-
* "cacheControl": { "type": "ephemeral" }
|
1289
|
-
* }
|
1290
|
-
* }
|
1291
|
-
* ```
|
1292
|
-
*/
|
1293
|
-
type LanguageModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
|
1294
|
-
|
1295
1340
|
/**
|
1296
1341
|
A prompt is a list of messages.
|
1297
1342
|
|
@@ -1301,47 +1346,47 @@ tool calls. The validation happens at runtime.
|
|
1301
1346
|
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
1302
1347
|
user-facing prompt types such as chat or instruction prompts to this format.
|
1303
1348
|
*/
|
1304
|
-
type
|
1305
|
-
type
|
1349
|
+
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
1350
|
+
type LanguageModelV1Message = ({
|
1306
1351
|
role: 'system';
|
1307
1352
|
content: string;
|
1308
1353
|
} | {
|
1309
1354
|
role: 'user';
|
1310
|
-
content: Array<
|
1355
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
|
1311
1356
|
} | {
|
1312
1357
|
role: 'assistant';
|
1313
|
-
content: Array<
|
1358
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1FilePart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
|
1314
1359
|
} | {
|
1315
1360
|
role: 'tool';
|
1316
|
-
content: Array<
|
1361
|
+
content: Array<LanguageModelV1ToolResultPart>;
|
1317
1362
|
}) & {
|
1318
1363
|
/**
|
1319
|
-
* Additional provider-specific
|
1364
|
+
* Additional provider-specific metadata. They are passed through
|
1320
1365
|
* to the provider from the AI SDK and enable provider-specific
|
1321
1366
|
* functionality that can be fully encapsulated in the provider.
|
1322
1367
|
*/
|
1323
|
-
|
1368
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1324
1369
|
};
|
1325
1370
|
/**
|
1326
1371
|
Text content part of a prompt. It contains a string of text.
|
1327
1372
|
*/
|
1328
|
-
interface
|
1373
|
+
interface LanguageModelV1TextPart {
|
1329
1374
|
type: 'text';
|
1330
1375
|
/**
|
1331
1376
|
The text content.
|
1332
1377
|
*/
|
1333
1378
|
text: string;
|
1334
1379
|
/**
|
1335
|
-
* Additional provider-specific
|
1380
|
+
* Additional provider-specific metadata. They are passed through
|
1336
1381
|
* to the provider from the AI SDK and enable provider-specific
|
1337
1382
|
* functionality that can be fully encapsulated in the provider.
|
1338
1383
|
*/
|
1339
|
-
|
1384
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1340
1385
|
}
|
1341
1386
|
/**
|
1342
1387
|
Reasoning content part of a prompt. It contains a string of reasoning text.
|
1343
1388
|
*/
|
1344
|
-
interface
|
1389
|
+
interface LanguageModelV1ReasoningPart {
|
1345
1390
|
type: 'reasoning';
|
1346
1391
|
/**
|
1347
1392
|
The reasoning text.
|
@@ -1352,32 +1397,32 @@ interface LanguageModelV2ReasoningPart {
|
|
1352
1397
|
*/
|
1353
1398
|
signature?: string;
|
1354
1399
|
/**
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1400
|
+
Additional provider-specific metadata. They are passed through
|
1401
|
+
to the provider from the AI SDK and enable provider-specific
|
1402
|
+
functionality that can be fully encapsulated in the provider.
|
1358
1403
|
*/
|
1359
|
-
|
1404
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1360
1405
|
}
|
1361
1406
|
/**
|
1362
1407
|
Redacted reasoning content part of a prompt.
|
1363
1408
|
*/
|
1364
|
-
interface
|
1409
|
+
interface LanguageModelV1RedactedReasoningPart {
|
1365
1410
|
type: 'redacted-reasoning';
|
1366
1411
|
/**
|
1367
1412
|
Redacted reasoning data.
|
1368
1413
|
*/
|
1369
1414
|
data: string;
|
1370
1415
|
/**
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1416
|
+
Additional provider-specific metadata. They are passed through
|
1417
|
+
to the provider from the AI SDK and enable provider-specific
|
1418
|
+
functionality that can be fully encapsulated in the provider.
|
1374
1419
|
*/
|
1375
|
-
|
1420
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1376
1421
|
}
|
1377
1422
|
/**
|
1378
1423
|
Image content part of a prompt. It contains an image.
|
1379
1424
|
*/
|
1380
|
-
interface
|
1425
|
+
interface LanguageModelV1ImagePart {
|
1381
1426
|
type: 'image';
|
1382
1427
|
/**
|
1383
1428
|
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
@@ -1388,16 +1433,16 @@ interface LanguageModelV2ImagePart {
|
|
1388
1433
|
*/
|
1389
1434
|
mimeType?: string;
|
1390
1435
|
/**
|
1391
|
-
* Additional provider-specific
|
1436
|
+
* Additional provider-specific metadata. They are passed through
|
1392
1437
|
* to the provider from the AI SDK and enable provider-specific
|
1393
1438
|
* functionality that can be fully encapsulated in the provider.
|
1394
1439
|
*/
|
1395
|
-
|
1440
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1396
1441
|
}
|
1397
1442
|
/**
|
1398
1443
|
File content part of a prompt. It contains a file.
|
1399
1444
|
*/
|
1400
|
-
interface
|
1445
|
+
interface LanguageModelV1FilePart {
|
1401
1446
|
type: 'file';
|
1402
1447
|
/**
|
1403
1448
|
* Optional filename of the file.
|
@@ -1412,16 +1457,16 @@ interface LanguageModelV2FilePart {
|
|
1412
1457
|
*/
|
1413
1458
|
mimeType: string;
|
1414
1459
|
/**
|
1415
|
-
* Additional provider-specific
|
1460
|
+
* Additional provider-specific metadata. They are passed through
|
1416
1461
|
* to the provider from the AI SDK and enable provider-specific
|
1417
1462
|
* functionality that can be fully encapsulated in the provider.
|
1418
1463
|
*/
|
1419
|
-
|
1464
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1420
1465
|
}
|
1421
1466
|
/**
|
1422
1467
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
1423
1468
|
*/
|
1424
|
-
interface
|
1469
|
+
interface LanguageModelV1ToolCallPart {
|
1425
1470
|
type: 'tool-call';
|
1426
1471
|
/**
|
1427
1472
|
ID of the tool call. This ID is used to match the tool call with the tool result.
|
@@ -1436,16 +1481,16 @@ interface LanguageModelV2ToolCallPart {
|
|
1436
1481
|
*/
|
1437
1482
|
args: unknown;
|
1438
1483
|
/**
|
1439
|
-
* Additional provider-specific
|
1484
|
+
* Additional provider-specific metadata. They are passed through
|
1440
1485
|
* to the provider from the AI SDK and enable provider-specific
|
1441
1486
|
* functionality that can be fully encapsulated in the provider.
|
1442
1487
|
*/
|
1443
|
-
|
1488
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1444
1489
|
}
|
1445
1490
|
/**
|
1446
1491
|
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
1447
1492
|
*/
|
1448
|
-
interface
|
1493
|
+
interface LanguageModelV1ToolResultPart {
|
1449
1494
|
type: 'tool-result';
|
1450
1495
|
/**
|
1451
1496
|
ID of the tool call that this result is associated with.
|
@@ -1485,17 +1530,17 @@ Mime type of the image.
|
|
1485
1530
|
mimeType?: string;
|
1486
1531
|
}>;
|
1487
1532
|
/**
|
1488
|
-
* Additional provider-specific
|
1533
|
+
* Additional provider-specific metadata. They are passed through
|
1489
1534
|
* to the provider from the AI SDK and enable provider-specific
|
1490
1535
|
* functionality that can be fully encapsulated in the provider.
|
1491
1536
|
*/
|
1492
|
-
|
1537
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1493
1538
|
}
|
1494
1539
|
|
1495
1540
|
/**
|
1496
1541
|
The configuration of a tool that is defined by the provider.
|
1497
1542
|
*/
|
1498
|
-
type
|
1543
|
+
type LanguageModelV1ProviderDefinedTool = {
|
1499
1544
|
/**
|
1500
1545
|
The type of the tool (always 'provider-defined').
|
1501
1546
|
*/
|
@@ -1514,7 +1559,7 @@ type LanguageModelV2ProviderDefinedTool = {
|
|
1514
1559
|
args: Record<string, unknown>;
|
1515
1560
|
};
|
1516
1561
|
|
1517
|
-
type
|
1562
|
+
type LanguageModelV1ToolChoice = {
|
1518
1563
|
type: 'auto';
|
1519
1564
|
} | {
|
1520
1565
|
type: 'none';
|
@@ -1525,7 +1570,7 @@ type LanguageModelV2ToolChoice = {
|
|
1525
1570
|
toolName: string;
|
1526
1571
|
};
|
1527
1572
|
|
1528
|
-
type
|
1573
|
+
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
1529
1574
|
/**
|
1530
1575
|
Whether the user provided the input as messages or as
|
1531
1576
|
a prompt. This can help guide non-chat models in the
|
@@ -1534,62 +1579,29 @@ type LanguageModelV2CallOptions = {
|
|
1534
1579
|
*/
|
1535
1580
|
inputFormat: 'messages' | 'prompt';
|
1536
1581
|
/**
|
1537
|
-
|
1582
|
+
The mode affects the behavior of the language model. It is required to
|
1583
|
+
support provider-independent streaming and generation of structured objects.
|
1584
|
+
The model can take this information and e.g. configure json mode, the correct
|
1585
|
+
low level grammar, etc. It can also be used to optimize the efficiency of the
|
1586
|
+
streaming, e.g. tool-delta stream parts are only needed in the
|
1587
|
+
object-tool mode.
|
1538
1588
|
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
the language model interface.
|
1543
|
-
*/
|
1544
|
-
prompt: LanguageModelV2Prompt;
|
1545
|
-
/**
|
1546
|
-
Maximum number of tokens to generate.
|
1589
|
+
@deprecated mode will be removed in v2.
|
1590
|
+
All necessary settings will be directly supported through the call settings,
|
1591
|
+
in particular responseFormat, toolChoice, and tools.
|
1547
1592
|
*/
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
Providers may have limits on the number of stop sequences.
|
1559
|
-
*/
|
1560
|
-
stopSequences?: string[];
|
1561
|
-
/**
|
1562
|
-
Nucleus sampling.
|
1563
|
-
|
1564
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
1565
|
-
*/
|
1566
|
-
topP?: number;
|
1567
|
-
/**
|
1568
|
-
Only sample from the top K options for each subsequent token.
|
1569
|
-
|
1570
|
-
Used to remove "long tail" low probability responses.
|
1571
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
1572
|
-
*/
|
1573
|
-
topK?: number;
|
1574
|
-
/**
|
1575
|
-
Presence penalty setting. It affects the likelihood of the model to
|
1576
|
-
repeat information that is already in the prompt.
|
1577
|
-
*/
|
1578
|
-
presencePenalty?: number;
|
1579
|
-
/**
|
1580
|
-
Frequency penalty setting. It affects the likelihood of the model
|
1581
|
-
to repeatedly use the same words or phrases.
|
1582
|
-
*/
|
1583
|
-
frequencyPenalty?: number;
|
1584
|
-
/**
|
1585
|
-
Response format. The output can either be text or JSON. Default is text.
|
1586
|
-
|
1587
|
-
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1588
|
-
*/
|
1589
|
-
responseFormat?: {
|
1590
|
-
type: 'text';
|
1593
|
+
mode: {
|
1594
|
+
type: 'regular';
|
1595
|
+
/**
|
1596
|
+
The tools that are available for the model.
|
1597
|
+
*/
|
1598
|
+
tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
|
1599
|
+
/**
|
1600
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
1601
|
+
*/
|
1602
|
+
toolChoice?: LanguageModelV1ToolChoice;
|
1591
1603
|
} | {
|
1592
|
-
type: 'json';
|
1604
|
+
type: 'object-json';
|
1593
1605
|
/**
|
1594
1606
|
* JSON schema that the generated output should conform to.
|
1595
1607
|
*/
|
@@ -1602,48 +1614,38 @@ type LanguageModelV2CallOptions = {
|
|
1602
1614
|
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1603
1615
|
*/
|
1604
1616
|
description?: string;
|
1617
|
+
} | {
|
1618
|
+
type: 'object-tool';
|
1619
|
+
tool: LanguageModelV1FunctionTool;
|
1605
1620
|
};
|
1606
1621
|
/**
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
/**
|
1616
|
-
Specifies how the tool should be selected. Defaults to 'auto'.
|
1617
|
-
*/
|
1618
|
-
toolChoice?: LanguageModelV2ToolChoice;
|
1619
|
-
/**
|
1620
|
-
Abort signal for cancelling the operation.
|
1621
|
-
*/
|
1622
|
-
abortSignal?: AbortSignal;
|
1623
|
-
/**
|
1624
|
-
Additional HTTP headers to be sent with the request.
|
1625
|
-
Only applicable for HTTP-based providers.
|
1626
|
-
*/
|
1627
|
-
headers?: Record<string, string | undefined>;
|
1622
|
+
A language mode prompt is a standardized prompt type.
|
1623
|
+
|
1624
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
1625
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
1626
|
+
That approach allows us to evolve the user facing prompts without breaking
|
1627
|
+
the language model interface.
|
1628
|
+
*/
|
1629
|
+
prompt: LanguageModelV1Prompt;
|
1628
1630
|
/**
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1631
|
+
Additional provider-specific metadata.
|
1632
|
+
The metadata is passed through to the provider from the AI SDK and enables
|
1633
|
+
provider-specific functionality that can be fully encapsulated in the provider.
|
1632
1634
|
*/
|
1633
|
-
|
1635
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1634
1636
|
};
|
1635
1637
|
|
1636
1638
|
/**
|
1637
1639
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
1638
1640
|
some settings might not be supported, which can lead to suboptimal results.
|
1639
1641
|
*/
|
1640
|
-
type
|
1642
|
+
type LanguageModelV1CallWarning = {
|
1641
1643
|
type: 'unsupported-setting';
|
1642
|
-
setting:
|
1644
|
+
setting: keyof LanguageModelV1CallSettings;
|
1643
1645
|
details?: string;
|
1644
1646
|
} | {
|
1645
1647
|
type: 'unsupported-tool';
|
1646
|
-
tool:
|
1648
|
+
tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
|
1647
1649
|
details?: string;
|
1648
1650
|
} | {
|
1649
1651
|
type: 'other';
|
@@ -1662,9 +1664,9 @@ Can be one of the following:
|
|
1662
1664
|
- `other`: model stopped for other reasons
|
1663
1665
|
- `unknown`: the model has not transmitted a finish reason
|
1664
1666
|
*/
|
1665
|
-
type
|
1667
|
+
type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
1666
1668
|
|
1667
|
-
type
|
1669
|
+
type LanguageModelV1FunctionToolCall = {
|
1668
1670
|
toolCallType: 'function';
|
1669
1671
|
toolCallId: string;
|
1670
1672
|
toolName: string;
|
@@ -1678,7 +1680,7 @@ type LanguageModelV2FunctionToolCall = {
|
|
1678
1680
|
/**
|
1679
1681
|
Log probabilities for each token and its top log probabilities.
|
1680
1682
|
*/
|
1681
|
-
type
|
1683
|
+
type LanguageModelV1LogProbs = Array<{
|
1682
1684
|
token: string;
|
1683
1685
|
logprob: number;
|
1684
1686
|
topLogprobs: Array<{
|
@@ -1688,58 +1690,9 @@ type LanguageModelV2LogProbs = Array<{
|
|
1688
1690
|
}>;
|
1689
1691
|
|
1690
1692
|
/**
|
1691
|
-
|
1692
|
-
* Metadata are additional outputs from the provider.
|
1693
|
-
* They are passed through to the provider from the AI SDK
|
1694
|
-
* and enable provider-specific functionality
|
1695
|
-
* that can be fully encapsulated in the provider.
|
1696
|
-
*
|
1697
|
-
* This enables us to quickly ship provider-specific functionality
|
1698
|
-
* without affecting the core AI SDK.
|
1699
|
-
*
|
1700
|
-
* The outer record is keyed by the provider name, and the inner
|
1701
|
-
* record is keyed by the provider-specific metadata key.
|
1702
|
-
*
|
1703
|
-
* ```ts
|
1704
|
-
* {
|
1705
|
-
* "anthropic": {
|
1706
|
-
* "cacheControl": { "type": "ephemeral" }
|
1707
|
-
* }
|
1708
|
-
* }
|
1709
|
-
* ```
|
1710
|
-
*/
|
1711
|
-
type LanguageModelV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
|
1712
|
-
|
1713
|
-
/**
|
1714
|
-
* A source that has been used as input to generate the response.
|
1715
|
-
*/
|
1716
|
-
type LanguageModelV2Source = {
|
1717
|
-
/**
|
1718
|
-
* A URL source. This is return by web search RAG models.
|
1719
|
-
*/
|
1720
|
-
sourceType: 'url';
|
1721
|
-
/**
|
1722
|
-
* The ID of the source.
|
1723
|
-
*/
|
1724
|
-
id: string;
|
1725
|
-
/**
|
1726
|
-
* The URL of the source.
|
1727
|
-
*/
|
1728
|
-
url: string;
|
1729
|
-
/**
|
1730
|
-
* The title of the source.
|
1731
|
-
*/
|
1732
|
-
title?: string;
|
1733
|
-
/**
|
1734
|
-
* Additional provider metadata for the source.
|
1735
|
-
*/
|
1736
|
-
providerMetadata?: LanguageModelV2ProviderMetadata;
|
1737
|
-
};
|
1738
|
-
|
1739
|
-
/**
|
1740
|
-
Specification for a language model that implements the language model interface version 2.
|
1693
|
+
Specification for a language model that implements the language model interface version 1.
|
1741
1694
|
*/
|
1742
|
-
type
|
1695
|
+
type LanguageModelV1 = {
|
1743
1696
|
/**
|
1744
1697
|
The language model must specify which language model interface
|
1745
1698
|
version it implements. This will allow us to evolve the language
|
@@ -1747,7 +1700,7 @@ type LanguageModelV2 = {
|
|
1747
1700
|
implementation versions can be handled as a discriminated union
|
1748
1701
|
on our side.
|
1749
1702
|
*/
|
1750
|
-
readonly specificationVersion: '
|
1703
|
+
readonly specificationVersion: 'v1';
|
1751
1704
|
/**
|
1752
1705
|
Name of the provider for logging purposes.
|
1753
1706
|
*/
|
@@ -1764,7 +1717,7 @@ type LanguageModelV2 = {
|
|
1764
1717
|
This is needed to generate the best objects possible w/o requiring the
|
1765
1718
|
user to explicitly specify the object generation mode.
|
1766
1719
|
*/
|
1767
|
-
readonly defaultObjectGenerationMode:
|
1720
|
+
readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
|
1768
1721
|
/**
|
1769
1722
|
Flag whether this model supports image URLs. Default is `true`.
|
1770
1723
|
|
@@ -1803,7 +1756,7 @@ type LanguageModelV2 = {
|
|
1803
1756
|
Naming: "do" prefix to prevent accidental direct usage of the method
|
1804
1757
|
by the user.
|
1805
1758
|
*/
|
1806
|
-
doGenerate(options:
|
1759
|
+
doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
|
1807
1760
|
/**
|
1808
1761
|
Text that the model has generated.
|
1809
1762
|
Can be undefined if the model did not generate any text.
|
@@ -1839,11 +1792,11 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1839
1792
|
Tool calls that the model has generated.
|
1840
1793
|
Can be undefined if the model did not generate any tool calls.
|
1841
1794
|
*/
|
1842
|
-
toolCalls?: Array<
|
1795
|
+
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
1843
1796
|
/**
|
1844
1797
|
Finish reason.
|
1845
1798
|
*/
|
1846
|
-
finishReason:
|
1799
|
+
finishReason: LanguageModelV1FinishReason;
|
1847
1800
|
/**
|
1848
1801
|
Usage information.
|
1849
1802
|
*/
|
@@ -1906,24 +1859,24 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1906
1859
|
*/
|
1907
1860
|
modelId?: string;
|
1908
1861
|
};
|
1909
|
-
warnings?:
|
1862
|
+
warnings?: LanguageModelV1CallWarning[];
|
1910
1863
|
/**
|
1911
1864
|
Additional provider-specific metadata. They are passed through
|
1912
1865
|
from the provider to the AI SDK and enable provider-specific
|
1913
1866
|
results that can be fully encapsulated in the provider.
|
1914
1867
|
*/
|
1915
|
-
providerMetadata?:
|
1868
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
1916
1869
|
/**
|
1917
1870
|
Sources that have been used as input to generate the response.
|
1918
1871
|
*/
|
1919
|
-
sources?:
|
1872
|
+
sources?: LanguageModelV1Source[];
|
1920
1873
|
/**
|
1921
1874
|
Logprobs for the completion.
|
1922
1875
|
`undefined` if the mode does not support logprobs or if was not enabled
|
1923
1876
|
|
1924
1877
|
@deprecated will be changed into a provider-specific extension in v2
|
1925
1878
|
*/
|
1926
|
-
logprobs?:
|
1879
|
+
logprobs?: LanguageModelV1LogProbs;
|
1927
1880
|
}>;
|
1928
1881
|
/**
|
1929
1882
|
Generates a language model output (streaming).
|
@@ -1933,8 +1886,8 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1933
1886
|
*
|
1934
1887
|
@return A stream of higher-level language model output parts.
|
1935
1888
|
*/
|
1936
|
-
doStream(options:
|
1937
|
-
stream: ReadableStream<
|
1889
|
+
doStream(options: LanguageModelV1CallOptions): PromiseLike<{
|
1890
|
+
stream: ReadableStream<LanguageModelV1StreamPart>;
|
1938
1891
|
/**
|
1939
1892
|
Raw prompt and setting information for observability provider integration.
|
1940
1893
|
*/
|
@@ -1972,10 +1925,10 @@ An optional signature for verifying that the reasoning originated from the model
|
|
1972
1925
|
/**
|
1973
1926
|
Warnings for the call, e.g. unsupported settings.
|
1974
1927
|
*/
|
1975
|
-
warnings?: Array<
|
1928
|
+
warnings?: Array<LanguageModelV1CallWarning>;
|
1976
1929
|
}>;
|
1977
1930
|
};
|
1978
|
-
type
|
1931
|
+
type LanguageModelV1StreamPart = {
|
1979
1932
|
type: 'text-delta';
|
1980
1933
|
textDelta: string;
|
1981
1934
|
} | {
|
@@ -1989,7 +1942,7 @@ type LanguageModelV2StreamPart = {
|
|
1989
1942
|
data: string;
|
1990
1943
|
} | {
|
1991
1944
|
type: 'source';
|
1992
|
-
source:
|
1945
|
+
source: LanguageModelV1Source;
|
1993
1946
|
} | {
|
1994
1947
|
type: 'file';
|
1995
1948
|
mimeType: string;
|
@@ -2003,7 +1956,7 @@ be returned as binary data.
|
|
2003
1956
|
data: string | Uint8Array;
|
2004
1957
|
} | ({
|
2005
1958
|
type: 'tool-call';
|
2006
|
-
} &
|
1959
|
+
} & LanguageModelV1FunctionToolCall) | {
|
2007
1960
|
type: 'tool-call-delta';
|
2008
1961
|
toolCallType: 'function';
|
2009
1962
|
toolCallId: string;
|
@@ -2016,13 +1969,13 @@ be returned as binary data.
|
|
2016
1969
|
modelId?: string;
|
2017
1970
|
} | {
|
2018
1971
|
type: 'finish';
|
2019
|
-
finishReason:
|
2020
|
-
providerMetadata?:
|
1972
|
+
finishReason: LanguageModelV1FinishReason;
|
1973
|
+
providerMetadata?: LanguageModelV1ProviderMetadata;
|
2021
1974
|
usage: {
|
2022
1975
|
promptTokens: number;
|
2023
1976
|
completionTokens: number;
|
2024
1977
|
};
|
2025
|
-
logprobs?:
|
1978
|
+
logprobs?: LanguageModelV1LogProbs;
|
2026
1979
|
} | {
|
2027
1980
|
type: 'error';
|
2028
1981
|
error: unknown;
|
@@ -2031,67 +1984,294 @@ be returned as binary data.
|
|
2031
1984
|
The object generation modes available for use with a model. `undefined`
|
2032
1985
|
represents no support for object generation.
|
2033
1986
|
*/
|
2034
|
-
type
|
1987
|
+
type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
|
1988
|
+
|
1989
|
+
type TranscriptionModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
|
1990
|
+
type TranscriptionModelV1CallOptions = {
|
1991
|
+
/**
|
1992
|
+
Audio data to transcribe.
|
1993
|
+
Accepts a `Uint8Array` or `string`, where `string` is a base64 encoded audio file.
|
1994
|
+
*/
|
1995
|
+
audio: Uint8Array | string;
|
1996
|
+
/**
|
1997
|
+
The IANA media type of the audio data.
|
1998
|
+
|
1999
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
2000
|
+
*/
|
2001
|
+
mediaType: string;
|
2002
|
+
/**
|
2003
|
+
Additional provider-specific options that are passed through to the provider
|
2004
|
+
as body parameters.
|
2005
|
+
|
2006
|
+
The outer record is keyed by the provider name, and the inner
|
2007
|
+
record is keyed by the provider-specific metadata key.
|
2008
|
+
```ts
|
2009
|
+
{
|
2010
|
+
"openai": {
|
2011
|
+
"timestampGranularities": ["word"]
|
2012
|
+
}
|
2013
|
+
}
|
2014
|
+
```
|
2015
|
+
*/
|
2016
|
+
providerOptions?: TranscriptionModelV1ProviderOptions;
|
2017
|
+
/**
|
2018
|
+
Abort signal for cancelling the operation.
|
2019
|
+
*/
|
2020
|
+
abortSignal?: AbortSignal;
|
2021
|
+
/**
|
2022
|
+
Additional HTTP headers to be sent with the request.
|
2023
|
+
Only applicable for HTTP-based providers.
|
2024
|
+
*/
|
2025
|
+
headers?: Record<string, string | undefined>;
|
2026
|
+
};
|
2035
2027
|
|
2036
2028
|
/**
|
2037
|
-
|
2038
|
-
|
2039
|
-
* the behavior of LanguageModelV2 operations.
|
2029
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
2030
|
+
some settings might not be supported, which can lead to suboptimal results.
|
2040
2031
|
*/
|
2041
|
-
type
|
2032
|
+
type TranscriptionModelV1CallWarning = {
|
2033
|
+
type: 'unsupported-setting';
|
2034
|
+
setting: keyof TranscriptionModelV1CallOptions;
|
2035
|
+
details?: string;
|
2036
|
+
} | {
|
2037
|
+
type: 'other';
|
2038
|
+
message: string;
|
2039
|
+
};
|
2040
|
+
|
2041
|
+
/**
|
2042
|
+
Transcription model specification version 1.
|
2043
|
+
*/
|
2044
|
+
type TranscriptionModelV1 = {
|
2042
2045
|
/**
|
2043
|
-
|
2046
|
+
The transcription model must specify which transcription model interface
|
2047
|
+
version it implements. This will allow us to evolve the transcription
|
2048
|
+
model interface and retain backwards compatibility. The different
|
2049
|
+
implementation versions can be handled as a discriminated union
|
2050
|
+
on our side.
|
2044
2051
|
*/
|
2045
|
-
|
2052
|
+
readonly specificationVersion: 'v1';
|
2046
2053
|
/**
|
2047
|
-
|
2048
|
-
* @param options - Object containing the type of operation and the parameters.
|
2049
|
-
* @param options.type - The type of operation ('generate' or 'stream').
|
2050
|
-
* @param options.params - The original parameters for the language model call.
|
2051
|
-
* @returns A promise that resolves to the transformed parameters.
|
2054
|
+
Name of the provider for logging purposes.
|
2052
2055
|
*/
|
2053
|
-
|
2054
|
-
type: 'generate' | 'stream';
|
2055
|
-
params: LanguageModelV2CallOptions;
|
2056
|
-
}) => PromiseLike<LanguageModelV2CallOptions>;
|
2056
|
+
readonly provider: string;
|
2057
2057
|
/**
|
2058
|
-
|
2059
|
-
* @param options - Object containing the generate function, parameters, and model.
|
2060
|
-
* @param options.doGenerate - The original generate function.
|
2061
|
-
* @param options.doStream - The original stream function.
|
2062
|
-
* @param options.params - The parameters for the generate call. If the
|
2063
|
-
* `transformParams` middleware is used, this will be the transformed parameters.
|
2064
|
-
* @param options.model - The language model instance.
|
2065
|
-
* @returns A promise that resolves to the result of the generate operation.
|
2058
|
+
Provider-specific model ID for logging purposes.
|
2066
2059
|
*/
|
2067
|
-
|
2068
|
-
doGenerate: () => ReturnType<LanguageModelV2['doGenerate']>;
|
2069
|
-
doStream: () => ReturnType<LanguageModelV2['doStream']>;
|
2070
|
-
params: LanguageModelV2CallOptions;
|
2071
|
-
model: LanguageModelV2;
|
2072
|
-
}) => Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
|
2060
|
+
readonly modelId: string;
|
2073
2061
|
/**
|
2074
|
-
|
2062
|
+
Generates a transcript.
|
2063
|
+
*/
|
2064
|
+
doGenerate(options: TranscriptionModelV1CallOptions): PromiseLike<{
|
2065
|
+
/**
|
2066
|
+
* The complete transcribed text from the audio.
|
2067
|
+
*/
|
2068
|
+
text: string;
|
2069
|
+
/**
|
2070
|
+
* Array of transcript segments with timing information.
|
2071
|
+
* Each segment represents a portion of the transcribed text with start and end times.
|
2072
|
+
*/
|
2073
|
+
segments: Array<{
|
2074
|
+
/**
|
2075
|
+
* The text content of this segment.
|
2076
|
+
*/
|
2077
|
+
text: string;
|
2078
|
+
/**
|
2079
|
+
* The start time of this segment in seconds.
|
2080
|
+
*/
|
2081
|
+
startSecond: number;
|
2082
|
+
/**
|
2083
|
+
* The end time of this segment in seconds.
|
2084
|
+
*/
|
2085
|
+
endSecond: number;
|
2086
|
+
}>;
|
2087
|
+
/**
|
2088
|
+
* The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
|
2089
|
+
* May be undefined if the language couldn't be detected.
|
2090
|
+
*/
|
2091
|
+
language: string | undefined;
|
2092
|
+
/**
|
2093
|
+
* The total duration of the audio file in seconds.
|
2094
|
+
* May be undefined if the duration couldn't be determined.
|
2095
|
+
*/
|
2096
|
+
durationInSeconds: number | undefined;
|
2097
|
+
/**
|
2098
|
+
Warnings for the call, e.g. unsupported settings.
|
2099
|
+
*/
|
2100
|
+
warnings: Array<TranscriptionModelV1CallWarning>;
|
2101
|
+
/**
|
2102
|
+
Optional request information for telemetry and debugging purposes.
|
2103
|
+
*/
|
2104
|
+
request?: {
|
2105
|
+
/**
|
2106
|
+
Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
|
2107
|
+
Non-HTTP(s) providers should not set this.
|
2108
|
+
*/
|
2109
|
+
body?: string;
|
2110
|
+
};
|
2111
|
+
/**
|
2112
|
+
Response information for telemetry and debugging purposes.
|
2113
|
+
*/
|
2114
|
+
response: {
|
2115
|
+
/**
|
2116
|
+
Timestamp for the start of the generated response.
|
2117
|
+
*/
|
2118
|
+
timestamp: Date;
|
2119
|
+
/**
|
2120
|
+
The ID of the response model that was used to generate the response.
|
2121
|
+
*/
|
2122
|
+
modelId: string;
|
2123
|
+
/**
|
2124
|
+
Response headers.
|
2125
|
+
*/
|
2126
|
+
headers?: SharedV2Headers;
|
2127
|
+
/**
|
2128
|
+
Response body.
|
2129
|
+
*/
|
2130
|
+
body?: unknown;
|
2131
|
+
};
|
2132
|
+
/**
|
2133
|
+
Additional provider-specific metadata. They are passed through
|
2134
|
+
from the provider to the AI SDK and enable provider-specific
|
2135
|
+
results that can be fully encapsulated in the provider.
|
2136
|
+
*/
|
2137
|
+
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
2138
|
+
}>;
|
2139
|
+
};
|
2140
|
+
|
2141
|
+
type SpeechModelV1ProviderOptions = Record<string, Record<string, JSONValue>>;
|
2142
|
+
type SpeechModelV1CallOptions = {
|
2143
|
+
/**
|
2144
|
+
* Text to convert to speech.
|
2145
|
+
*/
|
2146
|
+
text: string;
|
2147
|
+
/**
|
2148
|
+
* The voice to use for speech synthesis.
|
2149
|
+
* This is provider-specific and may be a voice ID, name, or other identifier.
|
2150
|
+
*/
|
2151
|
+
voice?: string;
|
2152
|
+
/**
|
2153
|
+
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
2154
|
+
*/
|
2155
|
+
outputFormat?: string;
|
2156
|
+
/**
|
2157
|
+
* Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
2158
|
+
*/
|
2159
|
+
instructions?: string;
|
2160
|
+
/**
|
2161
|
+
* The speed of the speech generation.
|
2162
|
+
*/
|
2163
|
+
speed?: number;
|
2164
|
+
/**
|
2165
|
+
* Additional provider-specific options that are passed through to the provider
|
2166
|
+
* as body parameters.
|
2075
2167
|
*
|
2076
|
-
*
|
2077
|
-
*
|
2078
|
-
*
|
2079
|
-
*
|
2080
|
-
*
|
2081
|
-
*
|
2082
|
-
*
|
2168
|
+
* The outer record is keyed by the provider name, and the inner
|
2169
|
+
* record is keyed by the provider-specific metadata key.
|
2170
|
+
* ```ts
|
2171
|
+
* {
|
2172
|
+
* "openai": {}
|
2173
|
+
* }
|
2174
|
+
* ```
|
2083
2175
|
*/
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2176
|
+
providerOptions?: SpeechModelV1ProviderOptions;
|
2177
|
+
/**
|
2178
|
+
* Abort signal for cancelling the operation.
|
2179
|
+
*/
|
2180
|
+
abortSignal?: AbortSignal;
|
2181
|
+
/**
|
2182
|
+
* Additional HTTP headers to be sent with the request.
|
2183
|
+
* Only applicable for HTTP-based providers.
|
2184
|
+
*/
|
2185
|
+
headers?: Record<string, string | undefined>;
|
2186
|
+
};
|
2187
|
+
|
2188
|
+
/**
|
2189
|
+
* Warning from the model provider for this call. The call will proceed, but e.g.
|
2190
|
+
* some settings might not be supported, which can lead to suboptimal results.
|
2191
|
+
*/
|
2192
|
+
type SpeechModelV1CallWarning = {
|
2193
|
+
type: 'unsupported-setting';
|
2194
|
+
setting: keyof SpeechModelV1CallOptions;
|
2195
|
+
details?: string;
|
2196
|
+
} | {
|
2197
|
+
type: 'other';
|
2198
|
+
message: string;
|
2090
2199
|
};
|
2200
|
+
|
2091
2201
|
/**
|
2092
|
-
*
|
2202
|
+
* Speech model specification version 1.
|
2093
2203
|
*/
|
2094
|
-
type
|
2204
|
+
type SpeechModelV1 = {
|
2205
|
+
/**
|
2206
|
+
* The speech model must specify which speech model interface
|
2207
|
+
* version it implements. This will allow us to evolve the speech
|
2208
|
+
* model interface and retain backwards compatibility. The different
|
2209
|
+
* implementation versions can be handled as a discriminated union
|
2210
|
+
* on our side.
|
2211
|
+
*/
|
2212
|
+
readonly specificationVersion: 'v1';
|
2213
|
+
/**
|
2214
|
+
* Name of the provider for logging purposes.
|
2215
|
+
*/
|
2216
|
+
readonly provider: string;
|
2217
|
+
/**
|
2218
|
+
* Provider-specific model ID for logging purposes.
|
2219
|
+
*/
|
2220
|
+
readonly modelId: string;
|
2221
|
+
/**
|
2222
|
+
* Generates speech audio from text.
|
2223
|
+
*/
|
2224
|
+
doGenerate(options: SpeechModelV1CallOptions): PromiseLike<{
|
2225
|
+
/**
|
2226
|
+
* Generated audio as an ArrayBuffer.
|
2227
|
+
* The audio should be returned without any unnecessary conversion.
|
2228
|
+
* If the API returns base64 encoded strings, the audio should be returned
|
2229
|
+
* as base64 encoded strings. If the API returns binary data, the audio
|
2230
|
+
* should be returned as binary data.
|
2231
|
+
*/
|
2232
|
+
audio: string | Uint8Array;
|
2233
|
+
/**
|
2234
|
+
* Warnings for the call, e.g. unsupported settings.
|
2235
|
+
*/
|
2236
|
+
warnings: Array<SpeechModelV1CallWarning>;
|
2237
|
+
/**
|
2238
|
+
* Optional request information for telemetry and debugging purposes.
|
2239
|
+
*/
|
2240
|
+
request?: {
|
2241
|
+
/**
|
2242
|
+
* Response body (available only for providers that use HTTP requests).
|
2243
|
+
*/
|
2244
|
+
body?: unknown;
|
2245
|
+
};
|
2246
|
+
/**
|
2247
|
+
* Response information for telemetry and debugging purposes.
|
2248
|
+
*/
|
2249
|
+
response: {
|
2250
|
+
/**
|
2251
|
+
* Timestamp for the start of the generated response.
|
2252
|
+
*/
|
2253
|
+
timestamp: Date;
|
2254
|
+
/**
|
2255
|
+
* The ID of the response model that was used to generate the response.
|
2256
|
+
*/
|
2257
|
+
modelId: string;
|
2258
|
+
/**
|
2259
|
+
* Response headers.
|
2260
|
+
*/
|
2261
|
+
headers?: SharedV2Headers;
|
2262
|
+
/**
|
2263
|
+
* Response body.
|
2264
|
+
*/
|
2265
|
+
body?: unknown;
|
2266
|
+
};
|
2267
|
+
/**
|
2268
|
+
* Additional provider-specific metadata. They are passed through
|
2269
|
+
* from the provider to the AI SDK and enable provider-specific
|
2270
|
+
* results that can be fully encapsulated in the provider.
|
2271
|
+
*/
|
2272
|
+
providerMetadata?: Record<string, Record<string, JSONValue>>;
|
2273
|
+
}>;
|
2274
|
+
};
|
2095
2275
|
|
2096
2276
|
/**
|
2097
2277
|
* Provider for language, text embedding, and image generation models.
|
@@ -2118,7 +2298,7 @@ interface ProviderV1 {
|
|
2118
2298
|
|
2119
2299
|
@throws {NoSuchModelError} If no such model exists.
|
2120
2300
|
*/
|
2121
|
-
textEmbeddingModel(modelId: string):
|
2301
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
|
2122
2302
|
/**
|
2123
2303
|
Returns the image model with the given id.
|
2124
2304
|
The model id is then passed to the provider function to get the model.
|
@@ -2127,7 +2307,25 @@ interface ProviderV1 {
|
|
2127
2307
|
|
2128
2308
|
@returns {ImageModel} The image model associated with the id
|
2129
2309
|
*/
|
2130
|
-
readonly imageModel?: (modelId: string) =>
|
2310
|
+
readonly imageModel?: (modelId: string) => ImageModelV2;
|
2311
|
+
/**
|
2312
|
+
Returns the transcription model with the given id.
|
2313
|
+
The model id is then passed to the provider function to get the model.
|
2314
|
+
|
2315
|
+
@param {string} modelId - The id of the model to return.
|
2316
|
+
|
2317
|
+
@returns {TranscriptionModel} The transcription model associated with the id
|
2318
|
+
*/
|
2319
|
+
readonly transcriptionModel?: (modelId: string) => TranscriptionModelV1;
|
2320
|
+
/**
|
2321
|
+
Returns the speech model with the given id.
|
2322
|
+
The model id is then passed to the provider function to get the model.
|
2323
|
+
|
2324
|
+
@param {string} modelId - The id of the model to return.
|
2325
|
+
|
2326
|
+
@returns {SpeechModel} The speech model associated with the id
|
2327
|
+
*/
|
2328
|
+
readonly speechModel?: (modelId: string) => SpeechModelV1;
|
2131
2329
|
}
|
2132
2330
|
|
2133
2331
|
/**
|
@@ -2155,7 +2353,7 @@ interface ProviderV2 {
|
|
2155
2353
|
|
2156
2354
|
@throws {NoSuchModelError} If no such model exists.
|
2157
2355
|
*/
|
2158
|
-
textEmbeddingModel(modelId: string):
|
2356
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
|
2159
2357
|
/**
|
2160
2358
|
Returns the image model with the given id.
|
2161
2359
|
The model id is then passed to the provider function to get the model.
|
@@ -2164,7 +2362,7 @@ interface ProviderV2 {
|
|
2164
2362
|
|
2165
2363
|
@returns {ImageModel} The image model associated with the id
|
2166
2364
|
*/
|
2167
|
-
readonly imageModel: (modelId: string) =>
|
2365
|
+
readonly imageModel: (modelId: string) => ImageModelV2;
|
2168
2366
|
}
|
2169
2367
|
|
2170
|
-
export { AISDKError, APICallError, type
|
2368
|
+
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, 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 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 LanguageModelV2ToolCallDelta, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV1, type ProviderV2, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV1, type SpeechModelV1CallOptions, type SpeechModelV1CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV1, type TranscriptionModelV1CallOptions, type TranscriptionModelV1CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|