@ai-sdk/openai 1.3.22 → 2.0.0-alpha.2
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 +239 -45
- package/dist/index.d.mts +31 -183
- package/dist/index.d.ts +31 -183
- package/dist/index.js +947 -1114
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +942 -1109
- package/dist/index.mjs.map +1 -1
- package/{internal/dist → dist/internal}/index.d.mts +157 -166
- package/{internal/dist → dist/internal}/index.d.ts +157 -166
- package/{internal/dist → dist/internal}/index.js +917 -1067
- package/dist/internal/index.js.map +1 -0
- package/{internal/dist → dist/internal}/index.mjs +914 -1068
- package/dist/internal/index.mjs.map +1 -0
- package/internal.d.ts +1 -0
- package/package.json +19 -18
- package/internal/dist/index.js.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,133 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV2, ProviderV2, EmbeddingModelV2, ImageModelV2, TranscriptionModelV1, SpeechModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
|
|
6
|
-
interface OpenAIChatSettings {
|
|
7
|
-
/**
|
|
8
|
-
Modify the likelihood of specified tokens appearing in the completion.
|
|
9
|
-
|
|
10
|
-
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
11
|
-
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
12
|
-
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
13
|
-
the bias is added to the logits generated by the model prior to sampling.
|
|
14
|
-
The exact effect will vary per model, but values between -1 and 1 should
|
|
15
|
-
decrease or increase likelihood of selection; values like -100 or 100
|
|
16
|
-
should result in a ban or exclusive selection of the relevant token.
|
|
17
|
-
|
|
18
|
-
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
19
|
-
token from being generated.
|
|
20
|
-
*/
|
|
21
|
-
logitBias?: Record<number, number>;
|
|
22
|
-
/**
|
|
23
|
-
Return the log probabilities of the tokens. Including logprobs will increase
|
|
24
|
-
the response size and can slow down response times. However, it can
|
|
25
|
-
be useful to better understand how the model is behaving.
|
|
26
|
-
|
|
27
|
-
Setting to true will return the log probabilities of the tokens that
|
|
28
|
-
were generated.
|
|
29
|
-
|
|
30
|
-
Setting to a number will return the log probabilities of the top n
|
|
31
|
-
tokens that were generated.
|
|
32
|
-
*/
|
|
33
|
-
logprobs?: boolean | number;
|
|
34
|
-
/**
|
|
35
|
-
Whether to enable parallel function calling during tool use. Default to true.
|
|
36
|
-
*/
|
|
37
|
-
parallelToolCalls?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
Whether to use structured outputs. Defaults to false.
|
|
40
|
-
|
|
41
|
-
When enabled, tool calls and object generation will be strict and follow the provided schema.
|
|
42
|
-
*/
|
|
43
|
-
structuredOutputs?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
Whether to use legacy function calling. Defaults to false.
|
|
46
|
-
|
|
47
|
-
Required by some open source inference engines which do not support the `tools` API. May also
|
|
48
|
-
provide a workaround for `parallelToolCalls` resulting in the provider buffering tool calls,
|
|
49
|
-
which causes `streamObject` to be non-streaming.
|
|
50
|
-
|
|
51
|
-
Prefer setting `parallelToolCalls: false` over this option.
|
|
52
|
-
|
|
53
|
-
@deprecated this API is supported but deprecated by OpenAI.
|
|
54
|
-
*/
|
|
55
|
-
useLegacyFunctionCalling?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
A unique identifier representing your end-user, which can help OpenAI to
|
|
58
|
-
monitor and detect abuse. Learn more.
|
|
59
|
-
*/
|
|
60
|
-
user?: string;
|
|
61
|
-
/**
|
|
62
|
-
Automatically download images and pass the image as data to the model.
|
|
63
|
-
OpenAI supports image URLs for public models, so this is only needed for
|
|
64
|
-
private models or when the images are not publicly accessible.
|
|
65
|
-
|
|
66
|
-
Defaults to `false`.
|
|
67
|
-
*/
|
|
68
|
-
downloadImages?: boolean;
|
|
69
|
-
/**
|
|
70
|
-
Simulates streaming by using a normal generate call and returning it as a stream.
|
|
71
|
-
Enable this if the model that you are using does not support streaming.
|
|
72
|
-
|
|
73
|
-
Defaults to `false`.
|
|
74
|
-
|
|
75
|
-
@deprecated Use `simulateStreamingMiddleware` instead.
|
|
76
|
-
*/
|
|
77
|
-
simulateStreaming?: boolean;
|
|
78
|
-
/**
|
|
79
|
-
Reasoning effort for reasoning models. Defaults to `medium`.
|
|
80
|
-
*/
|
|
81
|
-
reasoningEffort?: 'low' | 'medium' | 'high';
|
|
82
|
-
}
|
|
83
6
|
|
|
84
7
|
type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
|
|
85
|
-
interface OpenAICompletionSettings {
|
|
86
|
-
/**
|
|
87
|
-
Echo back the prompt in addition to the completion.
|
|
88
|
-
*/
|
|
89
|
-
echo?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
Modify the likelihood of specified tokens appearing in the completion.
|
|
92
|
-
|
|
93
|
-
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
94
|
-
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
95
|
-
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
96
|
-
the bias is added to the logits generated by the model prior to sampling.
|
|
97
|
-
The exact effect will vary per model, but values between -1 and 1 should
|
|
98
|
-
decrease or increase likelihood of selection; values like -100 or 100
|
|
99
|
-
should result in a ban or exclusive selection of the relevant token.
|
|
100
|
-
|
|
101
|
-
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
102
|
-
token from being generated.
|
|
103
|
-
*/
|
|
104
|
-
logitBias?: Record<number, number>;
|
|
105
|
-
/**
|
|
106
|
-
Return the log probabilities of the tokens. Including logprobs will increase
|
|
107
|
-
the response size and can slow down response times. However, it can
|
|
108
|
-
be useful to better understand how the model is behaving.
|
|
109
|
-
|
|
110
|
-
Setting to true will return the log probabilities of the tokens that
|
|
111
|
-
were generated.
|
|
112
|
-
|
|
113
|
-
Setting to a number will return the log probabilities of the top n
|
|
114
|
-
tokens that were generated.
|
|
115
|
-
*/
|
|
116
|
-
logprobs?: boolean | number;
|
|
117
|
-
/**
|
|
118
|
-
The suffix that comes after a completion of inserted text.
|
|
119
|
-
*/
|
|
120
|
-
suffix?: string;
|
|
121
|
-
/**
|
|
122
|
-
A unique identifier representing your end-user, which can help OpenAI to
|
|
123
|
-
monitor and detect abuse. Learn more.
|
|
124
|
-
*/
|
|
125
|
-
user?: string;
|
|
126
|
-
}
|
|
127
8
|
|
|
128
9
|
type OpenAICompletionConfig = {
|
|
129
10
|
provider: string;
|
|
130
|
-
compatibility: 'strict' | 'compatible';
|
|
131
11
|
headers: () => Record<string, string | undefined>;
|
|
132
12
|
url: (options: {
|
|
133
13
|
modelId: string;
|
|
@@ -135,53 +15,22 @@ type OpenAICompletionConfig = {
|
|
|
135
15
|
}) => string;
|
|
136
16
|
fetch?: FetchFunction;
|
|
137
17
|
};
|
|
138
|
-
declare class OpenAICompletionLanguageModel implements
|
|
139
|
-
readonly specificationVersion = "
|
|
140
|
-
readonly defaultObjectGenerationMode: undefined;
|
|
18
|
+
declare class OpenAICompletionLanguageModel implements LanguageModelV2 {
|
|
19
|
+
readonly specificationVersion = "v2";
|
|
141
20
|
readonly modelId: OpenAICompletionModelId;
|
|
142
|
-
readonly settings: OpenAICompletionSettings;
|
|
143
21
|
private readonly config;
|
|
144
|
-
|
|
22
|
+
private get providerOptionsName();
|
|
23
|
+
constructor(modelId: OpenAICompletionModelId, config: OpenAICompletionConfig);
|
|
145
24
|
get provider(): string;
|
|
25
|
+
readonly supportedUrls: Record<string, RegExp[]>;
|
|
146
26
|
private getArgs;
|
|
147
|
-
doGenerate(options: Parameters<
|
|
148
|
-
doStream(options: Parameters<
|
|
27
|
+
doGenerate(options: Parameters<LanguageModelV2['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
|
|
28
|
+
doStream(options: Parameters<LanguageModelV2['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
|
149
29
|
}
|
|
150
30
|
|
|
151
31
|
type OpenAIEmbeddingModelId = 'text-embedding-3-small' | 'text-embedding-3-large' | 'text-embedding-ada-002' | (string & {});
|
|
152
|
-
interface OpenAIEmbeddingSettings {
|
|
153
|
-
/**
|
|
154
|
-
Override the maximum number of embeddings per call.
|
|
155
|
-
*/
|
|
156
|
-
maxEmbeddingsPerCall?: number;
|
|
157
|
-
/**
|
|
158
|
-
Override the parallelism of embedding calls.
|
|
159
|
-
*/
|
|
160
|
-
supportsParallelCalls?: boolean;
|
|
161
|
-
/**
|
|
162
|
-
The number of dimensions the resulting output embeddings should have.
|
|
163
|
-
Only supported in text-embedding-3 and later models.
|
|
164
|
-
*/
|
|
165
|
-
dimensions?: number;
|
|
166
|
-
/**
|
|
167
|
-
A unique identifier representing your end-user, which can help OpenAI to
|
|
168
|
-
monitor and detect abuse. Learn more.
|
|
169
|
-
*/
|
|
170
|
-
user?: string;
|
|
171
|
-
}
|
|
172
32
|
|
|
173
33
|
type OpenAIImageModelId = 'gpt-image-1' | 'dall-e-3' | 'dall-e-2' | (string & {});
|
|
174
|
-
interface OpenAIImageSettings {
|
|
175
|
-
/**
|
|
176
|
-
Override the maximum number of images per call (default is dependent on the
|
|
177
|
-
model, or 1 for an unknown model).
|
|
178
|
-
*/
|
|
179
|
-
maxImagesPerCall?: number;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-4o-transcribe' | (string & {});
|
|
183
|
-
|
|
184
|
-
type OpenAIResponsesModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
|
|
185
34
|
|
|
186
35
|
declare const WebSearchPreviewParameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
187
36
|
declare function webSearchPreviewTool({ searchContextSize, userLocation, }?: {
|
|
@@ -203,50 +52,55 @@ declare const openaiTools: {
|
|
|
203
52
|
webSearchPreview: typeof webSearchPreviewTool;
|
|
204
53
|
};
|
|
205
54
|
|
|
55
|
+
type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-4o-transcribe' | (string & {});
|
|
56
|
+
|
|
57
|
+
type OpenAIResponsesModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
|
|
58
|
+
|
|
206
59
|
type OpenAISpeechModelId = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | (string & {});
|
|
207
60
|
|
|
208
|
-
interface OpenAIProvider extends
|
|
209
|
-
(modelId: 'gpt-3.5-turbo-instruct'
|
|
210
|
-
(modelId: OpenAIChatModelId
|
|
61
|
+
interface OpenAIProvider extends ProviderV2 {
|
|
62
|
+
(modelId: 'gpt-3.5-turbo-instruct'): OpenAICompletionLanguageModel;
|
|
63
|
+
(modelId: OpenAIChatModelId): LanguageModelV2;
|
|
211
64
|
/**
|
|
212
65
|
Creates an OpenAI model for text generation.
|
|
213
66
|
*/
|
|
214
|
-
languageModel(modelId: 'gpt-3.5-turbo-instruct'
|
|
215
|
-
languageModel(modelId: OpenAIChatModelId
|
|
67
|
+
languageModel(modelId: 'gpt-3.5-turbo-instruct'): OpenAICompletionLanguageModel;
|
|
68
|
+
languageModel(modelId: OpenAIChatModelId): LanguageModelV2;
|
|
216
69
|
/**
|
|
217
70
|
Creates an OpenAI chat model for text generation.
|
|
218
71
|
*/
|
|
219
|
-
chat(modelId: OpenAIChatModelId
|
|
72
|
+
chat(modelId: OpenAIChatModelId): LanguageModelV2;
|
|
220
73
|
/**
|
|
221
74
|
Creates an OpenAI responses API model for text generation.
|
|
222
75
|
*/
|
|
223
|
-
responses(modelId: OpenAIResponsesModelId):
|
|
76
|
+
responses(modelId: OpenAIResponsesModelId): LanguageModelV2;
|
|
224
77
|
/**
|
|
225
78
|
Creates an OpenAI completion model for text generation.
|
|
226
79
|
*/
|
|
227
|
-
completion(modelId: OpenAICompletionModelId
|
|
80
|
+
completion(modelId: OpenAICompletionModelId): LanguageModelV2;
|
|
228
81
|
/**
|
|
229
82
|
Creates a model for text embeddings.
|
|
230
83
|
*/
|
|
231
|
-
embedding(modelId: OpenAIEmbeddingModelId
|
|
84
|
+
embedding(modelId: OpenAIEmbeddingModelId): EmbeddingModelV2<string>;
|
|
232
85
|
/**
|
|
233
86
|
Creates a model for text embeddings.
|
|
234
87
|
|
|
235
88
|
@deprecated Use `textEmbeddingModel` instead.
|
|
236
89
|
*/
|
|
237
|
-
textEmbedding(modelId: OpenAIEmbeddingModelId
|
|
90
|
+
textEmbedding(modelId: OpenAIEmbeddingModelId): EmbeddingModelV2<string>;
|
|
238
91
|
/**
|
|
239
92
|
Creates a model for text embeddings.
|
|
240
93
|
*/
|
|
241
|
-
textEmbeddingModel(modelId: OpenAIEmbeddingModelId
|
|
94
|
+
textEmbeddingModel(modelId: OpenAIEmbeddingModelId): EmbeddingModelV2<string>;
|
|
242
95
|
/**
|
|
243
96
|
Creates a model for image generation.
|
|
97
|
+
@deprecated Use `imageModel` instead.
|
|
244
98
|
*/
|
|
245
|
-
image(modelId: OpenAIImageModelId
|
|
99
|
+
image(modelId: OpenAIImageModelId): ImageModelV2;
|
|
246
100
|
/**
|
|
247
101
|
Creates a model for image generation.
|
|
248
102
|
*/
|
|
249
|
-
imageModel(modelId: OpenAIImageModelId
|
|
103
|
+
imageModel(modelId: OpenAIImageModelId): ImageModelV2;
|
|
250
104
|
/**
|
|
251
105
|
Creates a model for transcription.
|
|
252
106
|
*/
|
|
@@ -282,12 +136,6 @@ interface OpenAIProviderSettings {
|
|
|
282
136
|
*/
|
|
283
137
|
headers?: Record<string, string>;
|
|
284
138
|
/**
|
|
285
|
-
OpenAI compatibility mode. Should be set to `strict` when using the OpenAI API,
|
|
286
|
-
and `compatible` when using 3rd party providers. In `compatible` mode, newer
|
|
287
|
-
information such as streamOptions are not being sent. Defaults to 'compatible'.
|
|
288
|
-
*/
|
|
289
|
-
compatibility?: 'strict' | 'compatible';
|
|
290
|
-
/**
|
|
291
139
|
Provider name. Overrides the `openai` default name for 3rd party providers.
|
|
292
140
|
*/
|
|
293
141
|
name?: string;
|
|
@@ -302,7 +150,7 @@ Create an OpenAI provider instance.
|
|
|
302
150
|
*/
|
|
303
151
|
declare function createOpenAI(options?: OpenAIProviderSettings): OpenAIProvider;
|
|
304
152
|
/**
|
|
305
|
-
Default OpenAI provider instance.
|
|
153
|
+
Default OpenAI provider instance.
|
|
306
154
|
*/
|
|
307
155
|
declare const openai: OpenAIProvider;
|
|
308
156
|
|
|
@@ -318,20 +166,20 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
|
|
|
318
166
|
reasoningSummary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
319
167
|
}, "strip", z.ZodTypeAny, {
|
|
320
168
|
user?: string | null | undefined;
|
|
169
|
+
parallelToolCalls?: boolean | null | undefined;
|
|
170
|
+
reasoningEffort?: string | null | undefined;
|
|
321
171
|
store?: boolean | null | undefined;
|
|
322
172
|
metadata?: any;
|
|
323
|
-
reasoningEffort?: string | null | undefined;
|
|
324
|
-
parallelToolCalls?: boolean | null | undefined;
|
|
325
173
|
previousResponseId?: string | null | undefined;
|
|
326
174
|
strictSchemas?: boolean | null | undefined;
|
|
327
175
|
instructions?: string | null | undefined;
|
|
328
176
|
reasoningSummary?: string | null | undefined;
|
|
329
177
|
}, {
|
|
330
178
|
user?: string | null | undefined;
|
|
179
|
+
parallelToolCalls?: boolean | null | undefined;
|
|
180
|
+
reasoningEffort?: string | null | undefined;
|
|
331
181
|
store?: boolean | null | undefined;
|
|
332
182
|
metadata?: any;
|
|
333
|
-
reasoningEffort?: string | null | undefined;
|
|
334
|
-
parallelToolCalls?: boolean | null | undefined;
|
|
335
183
|
previousResponseId?: string | null | undefined;
|
|
336
184
|
strictSchemas?: boolean | null | undefined;
|
|
337
185
|
instructions?: string | null | undefined;
|