@ai-sdk/openai 4.0.105 → 4.0.106
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 +15 -0
- package/dist/index.d.ts +49 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +570 -188
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +524 -150
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +91 -5
- package/package.json +3 -3
- package/src/chat/openai-chat-language-model.ts +27 -20
- package/src/completion/openai-completion-language-model.ts +11 -3
- package/src/embedding/openai-embedding-model.ts +2 -1
- package/src/files/openai-files.ts +10 -8
- package/src/image/openai-image-model-options.ts +10 -20
- package/src/image/openai-image-model.ts +10 -21
- package/src/live/openai-realtime-model-live.ts +15 -16
- package/src/openai-batch.ts +22 -6
- package/src/openai-config.ts +2 -1
- package/src/openai-decision-model.ts +2 -1
- package/src/openai-model-catalog.ts +935 -0
- package/src/openai-provider.ts +18 -13
- package/src/realtime/openai-realtime-factory.ts +6 -6
- package/src/realtime/openai-realtime-model.ts +7 -3
- package/src/resolve-openai-reasoning-effort.ts +45 -0
- package/src/responses/openai-responses-language-model.ts +28 -22
- package/src/skills/openai-skills.ts +4 -2
- package/src/speech/openai-speech-model.ts +5 -1
- package/src/speech-translation/openai-speech-translation-model.ts +5 -1
- package/src/transcription/openai-transcription-model.ts +25 -56
- package/src/openai-language-model-capabilities.ts +0 -196
package/dist/internal/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APICallError, InvalidPromptError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError, isJSONObject } from "@ai-sdk/provider";
|
|
2
|
-
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, convertToFormData, createBinaryResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, downloadBlob, experimental_toolCaller, generateId, getTopLevelMediaType, isCustomReasoning, isNonNullable, isRecord, lazySchema, mapReasoningToProviderEffort, mediaTypeToExtension, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateTypes, waitForWebSocketBufferDrain, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, convertToFormData, createBinaryResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, downloadBlob, experimental_toolCaller, generateId, getTopLevelMediaType, isCustomReasoning, isNonNullable, isRecord, lazySchema, mapReasoningToProviderEffort, mediaTypeToExtension, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateTypes, waitForWebSocketBufferDrain, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
//#region src/openai-error.ts
|
|
5
5
|
const openaiErrorDataSchema = () => z.object({ error: z.object({
|
|
@@ -14,54 +14,182 @@ const openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
14
14
|
errorToMessage: (data) => data.error.message
|
|
15
15
|
});
|
|
16
16
|
//#endregion
|
|
17
|
-
//#region src/openai-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
//#region src/openai-model-catalog.ts
|
|
18
|
+
/**
|
|
19
|
+
* Options accepted under `providerOptions.openai`. Language options are the
|
|
20
|
+
* Responses API options. The `satisfies` check keeps this list in sync with
|
|
21
|
+
* the option schema.
|
|
22
|
+
*/
|
|
23
|
+
const openaiProviderOptions = { language: {
|
|
24
|
+
conversation: { description: "OpenAI Conversation ID to continue." },
|
|
25
|
+
include: { description: "Extra fields to include in the response." },
|
|
26
|
+
includeWebSearchSources: { description: "Include web search action sources." },
|
|
27
|
+
instructions: { description: "Instructions for the model." },
|
|
28
|
+
logprobs: { description: "Return token log probabilities." },
|
|
29
|
+
maxToolCalls: { description: "Maximum number of built-in tool calls." },
|
|
30
|
+
metadata: { description: "Metadata to store with the generation." },
|
|
31
|
+
parallelToolCalls: { description: "Whether to use parallel tool calls." },
|
|
32
|
+
previousResponseId: { description: "Previous response ID to continue." },
|
|
33
|
+
promptCacheKey: { description: "Cache key for prompt caching." },
|
|
34
|
+
promptCacheOptions: { description: "Prompt cache mode, TTL, and prewarm." },
|
|
35
|
+
promptCacheRetention: { description: "Prompt cache retention policy." },
|
|
36
|
+
reasoningEffort: { description: "Reasoning effort." },
|
|
37
|
+
reasoningEffortUpdate: { description: "Reasoning effort update from this response onward." },
|
|
38
|
+
reasoningMode: { description: "Standard or pro reasoning mode." },
|
|
39
|
+
reasoningContext: { description: "Which reasoning items can be used." },
|
|
40
|
+
reasoningSummary: { description: "Reasoning summary output." },
|
|
41
|
+
safetyIdentifier: { description: "Identifier for safety monitoring." },
|
|
42
|
+
serviceTier: { description: "Service tier for the request." },
|
|
43
|
+
store: { description: "Whether to store the generation." },
|
|
44
|
+
passThroughUnsupportedFiles: { description: "Send non-image file types as generic input files." },
|
|
45
|
+
strictJsonSchema: { description: "Use strict JSON schema validation." },
|
|
46
|
+
textVerbosity: { description: "Verbosity of text responses." },
|
|
47
|
+
truncation: { description: "Output truncation behavior." },
|
|
48
|
+
user: { description: "End-user identifier for abuse monitoring." },
|
|
49
|
+
systemMessageMode: { description: "System message role override." },
|
|
50
|
+
forceReasoning: { description: "Treat the model as a reasoning model." },
|
|
51
|
+
contextManagement: { description: "Server-side context compaction." },
|
|
52
|
+
compactionTrigger: { description: "Request explicit compaction." },
|
|
53
|
+
allowedTools: { description: "Restrict callable tools to a subset." }
|
|
54
|
+
} };
|
|
55
|
+
const configurableNonReasoning = { capabilities: { language: { reasoning: {
|
|
56
|
+
support: true,
|
|
57
|
+
efforts: [
|
|
58
|
+
"none",
|
|
59
|
+
"low",
|
|
60
|
+
"medium",
|
|
61
|
+
"high",
|
|
62
|
+
"xhigh",
|
|
63
|
+
"max"
|
|
64
|
+
],
|
|
65
|
+
sampling: "reasoning-effort-none"
|
|
66
|
+
} } } };
|
|
67
|
+
const openaiLanguageModelEntries = Object.fromEntries(Object.entries({
|
|
68
|
+
"gpt-6-astra": {},
|
|
69
|
+
"gpt-6.1-sol": {},
|
|
70
|
+
"gpt-6.1-terra": configurableNonReasoning,
|
|
71
|
+
"gpt-6-luna": configurableNonReasoning,
|
|
72
|
+
"gpt-6-sol": configurableNonReasoning,
|
|
73
|
+
"gpt-5.6": {},
|
|
74
|
+
"gpt-5.6-luna": {},
|
|
75
|
+
"gpt-5.6-sol": {},
|
|
76
|
+
"gpt-5.6-terra": {},
|
|
77
|
+
"gpt-5.5": {},
|
|
78
|
+
"gpt-5.4-pro": {},
|
|
79
|
+
"gpt-5.4": {},
|
|
80
|
+
"gpt-5.4-mini": {},
|
|
81
|
+
"gpt-5.4-nano": {},
|
|
82
|
+
"gpt-5.3-chat-latest": {},
|
|
83
|
+
"gpt-5.2-pro": {},
|
|
84
|
+
"gpt-5.2-chat-latest": {},
|
|
85
|
+
"gpt-5.2": {},
|
|
86
|
+
"gpt-5.1-codex-mini": {},
|
|
87
|
+
"gpt-5.1-codex": {},
|
|
88
|
+
"gpt-5.1-chat-latest": {},
|
|
89
|
+
"gpt-5.1": {},
|
|
90
|
+
"gpt-5-pro": {},
|
|
91
|
+
"gpt-5": {},
|
|
92
|
+
"gpt-5-mini": {},
|
|
93
|
+
"gpt-5-nano": {},
|
|
94
|
+
"gpt-5-codex": {},
|
|
95
|
+
"gpt-5-chat-latest": { capabilities: { language: {
|
|
96
|
+
objectGeneration: false,
|
|
97
|
+
tools: {
|
|
98
|
+
usage: false,
|
|
99
|
+
streaming: false,
|
|
100
|
+
async: false
|
|
101
|
+
}
|
|
102
|
+
} } },
|
|
103
|
+
"gpt-4.1": {},
|
|
104
|
+
"gpt-4.1-mini": {},
|
|
105
|
+
"gpt-4.1-nano": {},
|
|
106
|
+
"gpt-4o": {},
|
|
107
|
+
"gpt-4o-mini": {}
|
|
108
|
+
}).map(([modelId, definition]) => [modelId, createOpenAILanguageModelEntry(modelId, definition)]));
|
|
109
|
+
function createOpenAILanguageModelEntry(modelId, definition) {
|
|
28
110
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
29
111
|
const gptVersion = getGptVersion(modelId);
|
|
112
|
+
const isRecognizedModelFamily = oSeriesVersion != null || gptVersion != null || /^gpt-4o(?:-|$)/.test(modelId);
|
|
30
113
|
const isGptChatModel = gptVersion?.minor == null && (gptVersion?.variant?.startsWith("chat") ?? false);
|
|
31
114
|
const isGptNanoModel = gptVersion?.variant?.startsWith("nano") ?? false;
|
|
32
115
|
const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
|
|
116
|
+
const isGpt56OrLaterModel = isGpt6OrLaterModel || gptVersion?.major === 5 && (gptVersion.minor ?? 0) >= 6;
|
|
33
117
|
const isStandardGpt5Model = gptVersion?.major === 5 && (gptVersion.variant == null || /^(?:(?:mini|nano|sol|luna|terra)(?:-\d{4}-\d{2}-\d{2})?|\d{4}-\d{2}-\d{2})$/.test(gptVersion.variant));
|
|
34
|
-
const isGpt6OrLaterModelWithNoneEffort = modelId === "gpt-6-sol" || modelId === "gpt-6-luna" || modelId === "gpt-6.1-terra";
|
|
35
118
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
36
119
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
37
120
|
const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
38
|
-
const
|
|
39
|
-
const
|
|
121
|
+
const reasoningSampling = definition?.capabilities?.language?.reasoning?.sampling ?? (!isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && (gptVersion.minor ?? 0) >= 1) ? "reasoning-effort-none" : "unsupported");
|
|
122
|
+
const sampling = !isRecognizedModelFamily ? "unknown" : !isReasoningModel ? true : reasoningSampling === "reasoning-effort-none" ? { condition: "Only when reasoning effort is none." } : false;
|
|
123
|
+
const chatTemperatureSupportedWithoutReasoning = !modelId.startsWith("gpt-4o-search-preview") && !modelId.startsWith("gpt-4o-mini-search-preview");
|
|
124
|
+
const entry = {
|
|
125
|
+
capabilities: { language: {
|
|
126
|
+
inputs: definition?.capabilities?.language?.inputs ?? {
|
|
127
|
+
image: definition != null ? true : "unknown",
|
|
128
|
+
audio: definition != null ? false : "unknown"
|
|
129
|
+
},
|
|
130
|
+
objectGeneration: definition?.capabilities?.language?.objectGeneration ?? (definition != null ? true : "unknown"),
|
|
131
|
+
tools: definition?.capabilities?.language?.tools ?? {
|
|
132
|
+
usage: definition != null ? true : "unknown",
|
|
133
|
+
streaming: definition != null ? true : "unknown",
|
|
134
|
+
async: isGpt6OrLaterModel
|
|
135
|
+
},
|
|
136
|
+
reasoning: {
|
|
137
|
+
support: isRecognizedModelFamily ? isReasoningModel : "unknown",
|
|
138
|
+
efforts: definition?.capabilities?.language?.reasoning?.efforts ?? (isGpt6OrLaterModel ? [
|
|
139
|
+
"low",
|
|
140
|
+
"medium",
|
|
141
|
+
"high",
|
|
142
|
+
"xhigh",
|
|
143
|
+
"max"
|
|
144
|
+
] : isStandardGpt5Model ? getGpt5ReasoningEfforts(gptVersion.minor ?? 0) : void 0),
|
|
145
|
+
sampling: reasoningSampling
|
|
146
|
+
},
|
|
147
|
+
sampling: {
|
|
148
|
+
temperature: chatTemperatureSupportedWithoutReasoning ? sampling : { condition: "Not supported by Chat Completions search preview models." },
|
|
149
|
+
topP: sampling,
|
|
150
|
+
logprobs: isReasoningModel && !isGpt6OrLaterModel ? { condition: reasoningSampling === "reasoning-effort-none" ? "Chat Completions requires reasoning effort none; Responses support is model-dependent." : "Not supported by Chat Completions while reasoning; Responses support is model-dependent." } : sampling
|
|
151
|
+
},
|
|
152
|
+
serviceTiers: {
|
|
153
|
+
flex: supportsFlexProcessing,
|
|
154
|
+
priority: supportsPriorityProcessing
|
|
155
|
+
},
|
|
156
|
+
configurationUpdates: isGpt6OrLaterModel,
|
|
157
|
+
promptCache: {
|
|
158
|
+
retention: !isGpt6OrLaterModel,
|
|
159
|
+
options: isRecognizedModelFamily ? isGpt56OrLaterModel : "unknown"
|
|
160
|
+
},
|
|
161
|
+
endpoints: {
|
|
162
|
+
chat: {
|
|
163
|
+
temperatureWithoutReasoning: chatTemperatureSupportedWithoutReasoning,
|
|
164
|
+
functionToolsWithReasoning: !(gptVersion?.major === 5 && (gptVersion.minor ?? 0) >= 6)
|
|
165
|
+
},
|
|
166
|
+
responses: { logprobsRequireNonReasoning: isGpt6OrLaterModel }
|
|
167
|
+
}
|
|
168
|
+
} },
|
|
169
|
+
requestConfig: { language: { systemMessageMode: definition?.requestConfig?.language?.systemMessageMode ?? (isReasoningModel ? "developer" : "system") } }
|
|
170
|
+
};
|
|
171
|
+
const { language } = entry.capabilities;
|
|
40
172
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"high",
|
|
56
|
-
"xhigh",
|
|
57
|
-
"max"
|
|
58
|
-
] : isStandardGpt5Model ? getGpt5ReasoningEfforts(gptVersion.minor ?? 0) : void 0,
|
|
59
|
-
supportsChatFunctionToolsWithReasoning: !(gptVersion?.major === 5 && (gptVersion.minor ?? 0) >= 6),
|
|
60
|
-
isReasoningModel,
|
|
61
|
-
systemMessageMode,
|
|
62
|
-
supportsNonReasoningParameters
|
|
173
|
+
...entry,
|
|
174
|
+
providerOptions: { language: declareProviderOptions(openaiProviderOptions.language, definition != null ? true : "unknown", {
|
|
175
|
+
logprobs: language.sampling.logprobs,
|
|
176
|
+
maxToolCalls: language.tools.usage,
|
|
177
|
+
parallelToolCalls: language.tools.usage,
|
|
178
|
+
allowedTools: language.tools.usage,
|
|
179
|
+
reasoningEffort: language.reasoning.support,
|
|
180
|
+
reasoningSummary: language.reasoning.support,
|
|
181
|
+
reasoningMode: language.reasoning.support,
|
|
182
|
+
reasoningContext: language.reasoning.support,
|
|
183
|
+
reasoningEffortUpdate: language.configurationUpdates,
|
|
184
|
+
promptCacheOptions: language.promptCache.options,
|
|
185
|
+
promptCacheRetention: language.promptCache.retention
|
|
186
|
+
}) }
|
|
63
187
|
};
|
|
64
188
|
}
|
|
189
|
+
/** Applies one default support value to every option, except the listed ones. */
|
|
190
|
+
function declareProviderOptions(definitions, support, exceptions) {
|
|
191
|
+
return Object.fromEntries(Object.keys(definitions).map((option) => [option, exceptions[option] ?? support]));
|
|
192
|
+
}
|
|
65
193
|
function getGpt5ReasoningEfforts(minor) {
|
|
66
194
|
if (minor === 0) return [
|
|
67
195
|
"minimal",
|
|
@@ -97,27 +225,303 @@ function getOSeriesVersion(modelId) {
|
|
|
97
225
|
}
|
|
98
226
|
function getGptVersion(modelId) {
|
|
99
227
|
const match = /^gpt-(\d+)(?:\.(\d+))?(?:-(.+))?$/.exec(modelId);
|
|
100
|
-
|
|
101
|
-
return {
|
|
228
|
+
return match == null ? void 0 : {
|
|
102
229
|
major: Number(match[1]),
|
|
103
230
|
minor: match[2] == null ? void 0 : Number(match[2]),
|
|
104
231
|
variant: match[3]
|
|
105
232
|
};
|
|
106
233
|
}
|
|
234
|
+
const openaiEmbeddingModelEntries = {
|
|
235
|
+
"text-embedding-3-large": { capabilities: { embedding: {
|
|
236
|
+
defaultDimensions: 3072,
|
|
237
|
+
customDimensions: true
|
|
238
|
+
} } },
|
|
239
|
+
"text-embedding-3-small": { capabilities: { embedding: {
|
|
240
|
+
defaultDimensions: 1536,
|
|
241
|
+
customDimensions: true
|
|
242
|
+
} } },
|
|
243
|
+
"text-embedding-ada-002": { capabilities: { embedding: {
|
|
244
|
+
defaultDimensions: 1536,
|
|
245
|
+
customDimensions: false
|
|
246
|
+
} } }
|
|
247
|
+
};
|
|
248
|
+
const gptImageSizes = [
|
|
249
|
+
"1024x1024",
|
|
250
|
+
"1536x1024",
|
|
251
|
+
"1024x1536"
|
|
252
|
+
];
|
|
253
|
+
const customImageSizes = { description: "Standard presets and custom dimensions" };
|
|
254
|
+
function createGptImageEntry(sizes) {
|
|
255
|
+
return {
|
|
256
|
+
capabilities: { image: {
|
|
257
|
+
sizes,
|
|
258
|
+
fileInput: true,
|
|
259
|
+
maskInput: true,
|
|
260
|
+
maxImagesPerCall: 10
|
|
261
|
+
} },
|
|
262
|
+
requestConfig: { image: { responseFormat: "provider-default" } }
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const openaiImageModelEntries = {
|
|
266
|
+
"gpt-image-2.5-flare": createGptImageEntry(customImageSizes),
|
|
267
|
+
"gpt-image-2.5-sunburst": createGptImageEntry(customImageSizes),
|
|
268
|
+
"gpt-image-2": createGptImageEntry(gptImageSizes),
|
|
269
|
+
"gpt-image-1.5": createGptImageEntry(gptImageSizes),
|
|
270
|
+
"gpt-image-1-mini": createGptImageEntry(gptImageSizes),
|
|
271
|
+
"gpt-image-1": createGptImageEntry(gptImageSizes),
|
|
272
|
+
"dall-e-3": {
|
|
273
|
+
capabilities: { image: {
|
|
274
|
+
sizes: [
|
|
275
|
+
"1024x1024",
|
|
276
|
+
"1792x1024",
|
|
277
|
+
"1024x1792"
|
|
278
|
+
],
|
|
279
|
+
fileInput: false,
|
|
280
|
+
maskInput: false,
|
|
281
|
+
maxImagesPerCall: 1
|
|
282
|
+
} },
|
|
283
|
+
requestConfig: { image: { responseFormat: "b64_json" } }
|
|
284
|
+
},
|
|
285
|
+
"dall-e-2": {
|
|
286
|
+
capabilities: { image: {
|
|
287
|
+
sizes: [
|
|
288
|
+
"256x256",
|
|
289
|
+
"512x512",
|
|
290
|
+
"1024x1024"
|
|
291
|
+
],
|
|
292
|
+
fileInput: true,
|
|
293
|
+
maskInput: true,
|
|
294
|
+
maxImagesPerCall: 10
|
|
295
|
+
} },
|
|
296
|
+
requestConfig: { image: { responseFormat: "b64_json" } }
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const imageModelAliases = {
|
|
300
|
+
"gpt-image-2.5-flare-2026-09-08": openaiImageModelEntries["gpt-image-2.5-flare"],
|
|
301
|
+
"gpt-image-2.5-sunburst-2026-09-08": openaiImageModelEntries["gpt-image-2.5-sunburst"],
|
|
302
|
+
"chatgpt-image-latest": createGptImageEntry({ description: "Unknown" })
|
|
303
|
+
};
|
|
304
|
+
function resolveOpenAIImageModelEntry(modelId) {
|
|
305
|
+
if (Object.prototype.hasOwnProperty.call(openaiImageModelEntries, modelId)) return openaiImageModelEntries[modelId];
|
|
306
|
+
if (Object.prototype.hasOwnProperty.call(imageModelAliases, modelId)) return imageModelAliases[modelId];
|
|
307
|
+
return {
|
|
308
|
+
capabilities: { image: {
|
|
309
|
+
sizes: { description: "Unknown" },
|
|
310
|
+
fileInput: "unknown",
|
|
311
|
+
maskInput: "unknown",
|
|
312
|
+
maxImagesPerCall: modelId.startsWith("gpt-image-") ? 10 : 1
|
|
313
|
+
} },
|
|
314
|
+
requestConfig: { image: { responseFormat: modelId.startsWith("chatgpt-image-") || modelId.startsWith("gpt-image-") ? "provider-default" : "b64_json" } }
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const openaiImageModelMaxImagesPerCall = Object.fromEntries(Object.entries({
|
|
318
|
+
...openaiImageModelEntries,
|
|
319
|
+
...imageModelAliases
|
|
320
|
+
}).map(([modelId, entry]) => [modelId, entry.capabilities.image.maxImagesPerCall ?? 1]));
|
|
321
|
+
const defaultTranscriptionRequestConfig = { languageField: "language" };
|
|
322
|
+
const openaiTranscriptionModelEntries = {
|
|
323
|
+
"whisper-1": {
|
|
324
|
+
capabilities: { transcription: {
|
|
325
|
+
transcription: true,
|
|
326
|
+
streaming: false,
|
|
327
|
+
streamingDelay: false,
|
|
328
|
+
duration: true,
|
|
329
|
+
segments: true,
|
|
330
|
+
language: true
|
|
331
|
+
} },
|
|
332
|
+
requestConfig: { transcription: {
|
|
333
|
+
...defaultTranscriptionRequestConfig,
|
|
334
|
+
responseFormat: "verbose_json"
|
|
335
|
+
} }
|
|
336
|
+
},
|
|
337
|
+
"gpt-4o-mini-transcribe": {
|
|
338
|
+
capabilities: { transcription: {
|
|
339
|
+
transcription: true,
|
|
340
|
+
streaming: false,
|
|
341
|
+
streamingDelay: false,
|
|
342
|
+
duration: false,
|
|
343
|
+
segments: false,
|
|
344
|
+
language: false
|
|
345
|
+
} },
|
|
346
|
+
requestConfig: { transcription: defaultTranscriptionRequestConfig }
|
|
347
|
+
},
|
|
348
|
+
"gpt-4o-transcribe": {
|
|
349
|
+
capabilities: { transcription: {
|
|
350
|
+
transcription: true,
|
|
351
|
+
streaming: false,
|
|
352
|
+
streamingDelay: false,
|
|
353
|
+
duration: false,
|
|
354
|
+
segments: false,
|
|
355
|
+
language: false
|
|
356
|
+
} },
|
|
357
|
+
requestConfig: { transcription: defaultTranscriptionRequestConfig }
|
|
358
|
+
},
|
|
359
|
+
"gpt-4o-transcribe-diarize": {
|
|
360
|
+
capabilities: { transcription: {
|
|
361
|
+
transcription: true,
|
|
362
|
+
streaming: false,
|
|
363
|
+
streamingDelay: false,
|
|
364
|
+
duration: true,
|
|
365
|
+
segments: true,
|
|
366
|
+
language: false
|
|
367
|
+
} },
|
|
368
|
+
requestConfig: { transcription: {
|
|
369
|
+
...defaultTranscriptionRequestConfig,
|
|
370
|
+
responseFormat: "diarized_json",
|
|
371
|
+
chunkingStrategy: "auto"
|
|
372
|
+
} }
|
|
373
|
+
},
|
|
374
|
+
"gpt-transcribe": {
|
|
375
|
+
capabilities: { transcription: {
|
|
376
|
+
transcription: true,
|
|
377
|
+
streaming: true,
|
|
378
|
+
streamingDelay: false,
|
|
379
|
+
duration: false,
|
|
380
|
+
segments: false,
|
|
381
|
+
language: true
|
|
382
|
+
} },
|
|
383
|
+
requestConfig: { transcription: { languageField: "languages" } }
|
|
384
|
+
},
|
|
385
|
+
"gpt-live-transcribe": {
|
|
386
|
+
capabilities: { transcription: {
|
|
387
|
+
transcription: false,
|
|
388
|
+
streaming: true,
|
|
389
|
+
streamingDelay: true,
|
|
390
|
+
duration: false,
|
|
391
|
+
segments: false,
|
|
392
|
+
language: false
|
|
393
|
+
} },
|
|
394
|
+
requestConfig: { transcription: { languageField: "languages" } }
|
|
395
|
+
},
|
|
396
|
+
"gpt-realtime-whisper": {
|
|
397
|
+
capabilities: { transcription: {
|
|
398
|
+
transcription: false,
|
|
399
|
+
streaming: true,
|
|
400
|
+
streamingDelay: true,
|
|
401
|
+
duration: false,
|
|
402
|
+
segments: false,
|
|
403
|
+
language: false
|
|
404
|
+
} },
|
|
405
|
+
requestConfig: { transcription: defaultTranscriptionRequestConfig }
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
const transcriptionSnapshotModelIds = [
|
|
409
|
+
"gpt-transcribe",
|
|
410
|
+
"gpt-live-transcribe",
|
|
411
|
+
"gpt-realtime-whisper"
|
|
412
|
+
];
|
|
413
|
+
function resolveOpenAITranscriptionModelEntry(modelId) {
|
|
414
|
+
if (Object.prototype.hasOwnProperty.call(openaiTranscriptionModelEntries, modelId)) return openaiTranscriptionModelEntries[modelId];
|
|
415
|
+
for (const baseModelId of transcriptionSnapshotModelIds) if (modelId.startsWith(`${baseModelId}-`)) return openaiTranscriptionModelEntries[baseModelId];
|
|
416
|
+
return {
|
|
417
|
+
capabilities: { transcription: {
|
|
418
|
+
transcription: "unknown",
|
|
419
|
+
streaming: "unknown",
|
|
420
|
+
streamingDelay: "unknown",
|
|
421
|
+
duration: "unknown",
|
|
422
|
+
segments: "unknown",
|
|
423
|
+
language: "unknown"
|
|
424
|
+
} },
|
|
425
|
+
requestConfig: { transcription: defaultTranscriptionRequestConfig }
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
const openaiSpeechTranslationModelEntries = { "gpt-realtime-translate": { capabilities: { speechTranslation: {
|
|
429
|
+
translatedAudio: true,
|
|
430
|
+
translatedText: true,
|
|
431
|
+
sourceTranscript: true
|
|
432
|
+
} } } };
|
|
433
|
+
const openaiSpeechModelEntries = {
|
|
434
|
+
"tts-1": { capabilities: { speech: { instructions: false } } },
|
|
435
|
+
"tts-1-hd": { capabilities: { speech: { instructions: false } } },
|
|
436
|
+
"gpt-4o-mini-tts": { capabilities: { speech: { instructions: true } } }
|
|
437
|
+
};
|
|
438
|
+
const liveModelEntry = {
|
|
439
|
+
capabilities: { realtime: {
|
|
440
|
+
conversation: "continuous",
|
|
441
|
+
transports: ["websocket", "webrtc"],
|
|
442
|
+
connections: ["server-websocket", "webrtc"]
|
|
443
|
+
} },
|
|
444
|
+
requestConfig: { realtime: {
|
|
445
|
+
api: "live",
|
|
446
|
+
startup: "session-start",
|
|
447
|
+
finalization: "session-close"
|
|
448
|
+
} }
|
|
449
|
+
};
|
|
450
|
+
const realtimeModelEntries = {
|
|
451
|
+
"gpt-live-1": liveModelEntry,
|
|
452
|
+
"gpt-realtime": {
|
|
453
|
+
capabilities: { realtime: {
|
|
454
|
+
conversation: "turn-based",
|
|
455
|
+
transports: ["websocket"],
|
|
456
|
+
connections: ["client-secret-websocket"]
|
|
457
|
+
} },
|
|
458
|
+
requestConfig: { realtime: {
|
|
459
|
+
api: "realtime",
|
|
460
|
+
startup: "session-update",
|
|
461
|
+
finalization: "transport-close"
|
|
462
|
+
} }
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
({ ...liveModelEntry.capabilities.realtime }), liveModelEntry.requestConfig.realtime.startup, liveModelEntry.requestConfig.realtime.finalization;
|
|
107
466
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* top-level reasoning value is mapped to the closest effort that the model
|
|
112
|
-
* family supports, or sent directly when the supported efforts are not known.
|
|
467
|
+
* The catalog consumed by request builders and documentation. Source declarations
|
|
468
|
+
* are grouped by operation; entries for the same model combine their sections.
|
|
469
|
+
* An absent section is undeclared, not an instruction to reject a request.
|
|
113
470
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
471
|
+
const openaiModelCatalog = combineModelEntries([
|
|
472
|
+
openaiLanguageModelEntries,
|
|
473
|
+
openaiEmbeddingModelEntries,
|
|
474
|
+
openaiImageModelEntries,
|
|
475
|
+
openaiTranscriptionModelEntries,
|
|
476
|
+
openaiSpeechTranslationModelEntries,
|
|
477
|
+
openaiSpeechModelEntries,
|
|
478
|
+
realtimeModelEntries
|
|
479
|
+
]);
|
|
480
|
+
function combineModelEntries(catalogs) {
|
|
481
|
+
const entries = /* @__PURE__ */ new Map();
|
|
482
|
+
for (const catalog of catalogs) for (const [modelId, entry] of Object.entries(catalog)) {
|
|
483
|
+
const previous = entries.get(modelId);
|
|
484
|
+
entries.set(modelId, {
|
|
485
|
+
capabilities: {
|
|
486
|
+
...previous?.capabilities,
|
|
487
|
+
...entry.capabilities
|
|
488
|
+
},
|
|
489
|
+
...previous?.providerOptions != null || entry.providerOptions != null ? { providerOptions: {
|
|
490
|
+
...previous?.providerOptions,
|
|
491
|
+
...entry.providerOptions
|
|
492
|
+
} } : {},
|
|
493
|
+
...previous?.requestConfig != null || entry.requestConfig != null ? { requestConfig: {
|
|
494
|
+
...previous?.requestConfig,
|
|
495
|
+
...entry.requestConfig
|
|
496
|
+
} } : {}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
return Object.fromEntries(entries);
|
|
500
|
+
}
|
|
501
|
+
function findModelEntry(modelId) {
|
|
502
|
+
return Object.prototype.hasOwnProperty.call(openaiModelCatalog, modelId) ? openaiModelCatalog[modelId] : void 0;
|
|
503
|
+
}
|
|
504
|
+
function getOpenAILanguageModelEntry(modelId) {
|
|
505
|
+
const entry = findModelEntry(modelId);
|
|
506
|
+
return entry?.capabilities.language != null && entry.providerOptions?.language != null && entry.requestConfig?.language != null ? {
|
|
507
|
+
capabilities: { language: entry.capabilities.language },
|
|
508
|
+
providerOptions: { language: entry.providerOptions.language },
|
|
509
|
+
requestConfig: { language: entry.requestConfig.language }
|
|
510
|
+
} : createOpenAILanguageModelEntry(modelId);
|
|
511
|
+
}
|
|
512
|
+
function getOpenAIImageModelEntry(modelId) {
|
|
513
|
+
const entry = findModelEntry(modelId);
|
|
514
|
+
return entry?.capabilities.image != null && entry.requestConfig?.image != null ? {
|
|
515
|
+
capabilities: { image: entry.capabilities.image },
|
|
516
|
+
requestConfig: { image: entry.requestConfig.image }
|
|
517
|
+
} : resolveOpenAIImageModelEntry(modelId);
|
|
518
|
+
}
|
|
519
|
+
function getOpenAITranscriptionModelEntry(modelId) {
|
|
520
|
+
const entry = findModelEntry(modelId);
|
|
521
|
+
return entry?.capabilities.transcription != null && entry.requestConfig?.transcription != null ? {
|
|
522
|
+
capabilities: { transcription: entry.capabilities.transcription },
|
|
523
|
+
requestConfig: { transcription: entry.requestConfig.transcription }
|
|
524
|
+
} : resolveOpenAITranscriptionModelEntry(modelId);
|
|
121
525
|
}
|
|
122
526
|
//#endregion
|
|
123
527
|
//#region src/openai-stream-error.ts
|
|
@@ -268,6 +672,26 @@ function isRetryableStreamError(error, statusCode) {
|
|
|
268
672
|
return isRetryableStatusCode(statusCode);
|
|
269
673
|
}
|
|
270
674
|
//#endregion
|
|
675
|
+
//#region src/resolve-openai-reasoning-effort.ts
|
|
676
|
+
const allOpenAIReasoningEfforts = [
|
|
677
|
+
"none",
|
|
678
|
+
"minimal",
|
|
679
|
+
"low",
|
|
680
|
+
"medium",
|
|
681
|
+
"high",
|
|
682
|
+
"xhigh",
|
|
683
|
+
"max"
|
|
684
|
+
];
|
|
685
|
+
/** Resolve portable reasoning against the efforts declared by the catalog. */
|
|
686
|
+
function resolveOpenAIReasoningEffort({ providerReasoningEffort, reasoning, supportedReasoningEfforts, warnings }) {
|
|
687
|
+
return mapReasoningToProviderEffort({
|
|
688
|
+
reasoning,
|
|
689
|
+
providerOptionsEffort: providerReasoningEffort,
|
|
690
|
+
effortMap: Object.fromEntries((supportedReasoningEfforts ?? allOpenAIReasoningEfforts).map((effort) => [effort, effort])),
|
|
691
|
+
warnings
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
//#endregion
|
|
271
695
|
//#region src/chat/convert-openai-chat-usage.ts
|
|
272
696
|
function convertOpenAIChatUsage(usage) {
|
|
273
697
|
if (usage == null) return createNullLanguageModelUsage();
|
|
@@ -990,8 +1414,8 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
990
1414
|
providerOptions,
|
|
991
1415
|
schema: openaiLanguageModelChatOptions
|
|
992
1416
|
}) ?? {};
|
|
993
|
-
const modelCapabilities =
|
|
994
|
-
const requiresNoReasoningEffort = !modelCapabilities.
|
|
1417
|
+
const { capabilities: { language: modelCapabilities }, requestConfig: { language: modelRequestConfig } } = getOpenAILanguageModelEntry(this.modelId);
|
|
1418
|
+
const requiresNoReasoningEffort = !modelCapabilities.endpoints.chat.functionToolsWithReasoning && openaiOptions.reasoningEffort == null && (tools?.some((tool) => tool.type === "function") ?? false);
|
|
995
1419
|
if (requiresNoReasoningEffort && isCustomReasoning(reasoning) && reasoning !== "none") warnings.push({
|
|
996
1420
|
type: "compatibility",
|
|
997
1421
|
feature: "reasoning",
|
|
@@ -1000,10 +1424,10 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1000
1424
|
const resolvedReasoningEffort = requiresNoReasoningEffort ? "none" : resolveOpenAIReasoningEffort({
|
|
1001
1425
|
providerReasoningEffort: openaiOptions.reasoningEffort,
|
|
1002
1426
|
reasoning,
|
|
1003
|
-
supportedReasoningEfforts: modelCapabilities.
|
|
1427
|
+
supportedReasoningEfforts: modelCapabilities.reasoning.efforts?.filter((effort) => effort !== "max"),
|
|
1004
1428
|
warnings
|
|
1005
1429
|
});
|
|
1006
|
-
const isReasoningModel = openaiOptions.forceReasoning ?? modelCapabilities.
|
|
1430
|
+
const isReasoningModel = openaiOptions.forceReasoning ?? modelCapabilities.reasoning.support === true;
|
|
1007
1431
|
if (topK != null) warnings.push({
|
|
1008
1432
|
type: "unsupported",
|
|
1009
1433
|
feature: "topK"
|
|
@@ -1015,7 +1439,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1015
1439
|
});
|
|
1016
1440
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages({
|
|
1017
1441
|
prompt,
|
|
1018
|
-
systemMessageMode: openaiOptions.systemMessageMode ?? (isReasoningModel ? "developer" :
|
|
1442
|
+
systemMessageMode: openaiOptions.systemMessageMode ?? (isReasoningModel ? "developer" : modelRequestConfig.systemMessageMode)
|
|
1019
1443
|
});
|
|
1020
1444
|
warnings.push(...messageWarnings);
|
|
1021
1445
|
const strictJsonSchema = openaiOptions.strictJsonSchema ?? true;
|
|
@@ -1057,7 +1481,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1057
1481
|
safety_identifier: openaiOptions.safetyIdentifier,
|
|
1058
1482
|
messages
|
|
1059
1483
|
};
|
|
1060
|
-
if (modelCapabilities.
|
|
1484
|
+
if (!modelCapabilities.promptCache.retention && baseArgs.prompt_cache_retention != null) {
|
|
1061
1485
|
baseArgs.prompt_cache_retention = void 0;
|
|
1062
1486
|
warnings.push({
|
|
1063
1487
|
type: "unsupported",
|
|
@@ -1066,7 +1490,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1066
1490
|
});
|
|
1067
1491
|
}
|
|
1068
1492
|
if (isReasoningModel) {
|
|
1069
|
-
if (resolvedReasoningEffort !== "none" ||
|
|
1493
|
+
if (resolvedReasoningEffort !== "none" || modelCapabilities.reasoning.sampling !== "reasoning-effort-none") {
|
|
1070
1494
|
if (baseArgs.temperature != null) {
|
|
1071
1495
|
baseArgs.temperature = void 0;
|
|
1072
1496
|
warnings.push({
|
|
@@ -1125,7 +1549,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1125
1549
|
if (baseArgs.max_completion_tokens == null) baseArgs.max_completion_tokens = baseArgs.max_tokens;
|
|
1126
1550
|
baseArgs.max_tokens = void 0;
|
|
1127
1551
|
}
|
|
1128
|
-
} else if (
|
|
1552
|
+
} else if (!modelCapabilities.endpoints.chat.temperatureWithoutReasoning) {
|
|
1129
1553
|
if (baseArgs.temperature != null) {
|
|
1130
1554
|
baseArgs.temperature = void 0;
|
|
1131
1555
|
warnings.push({
|
|
@@ -1135,7 +1559,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1135
1559
|
});
|
|
1136
1560
|
}
|
|
1137
1561
|
}
|
|
1138
|
-
if (openaiOptions.serviceTier === "flex" && !modelCapabilities.
|
|
1562
|
+
if (openaiOptions.serviceTier === "flex" && !modelCapabilities.serviceTiers.flex) {
|
|
1139
1563
|
warnings.push({
|
|
1140
1564
|
type: "unsupported",
|
|
1141
1565
|
feature: "serviceTier",
|
|
@@ -1143,7 +1567,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1143
1567
|
});
|
|
1144
1568
|
baseArgs.service_tier = void 0;
|
|
1145
1569
|
}
|
|
1146
|
-
if ((openaiOptions.serviceTier === "priority" || openaiOptions.serviceTier === "fast") && !modelCapabilities.
|
|
1570
|
+
if ((openaiOptions.serviceTier === "priority" || openaiOptions.serviceTier === "fast") && !modelCapabilities.serviceTiers.priority) {
|
|
1147
1571
|
warnings.push({
|
|
1148
1572
|
type: "unsupported",
|
|
1149
1573
|
feature: "serviceTier",
|
|
@@ -1171,7 +1595,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1171
1595
|
path: "/chat/completions",
|
|
1172
1596
|
modelId: this.config.requestModelId ?? this.modelId
|
|
1173
1597
|
}),
|
|
1174
|
-
headers: combineHeaders(this.config.headers
|
|
1598
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
1175
1599
|
body,
|
|
1176
1600
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1177
1601
|
successfulResponseHandler: createJsonResponseHandler(openaiChatResponseSchema),
|
|
@@ -1237,7 +1661,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1237
1661
|
});
|
|
1238
1662
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1239
1663
|
url,
|
|
1240
|
-
headers: combineHeaders(this.config.headers
|
|
1664
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
1241
1665
|
body,
|
|
1242
1666
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1243
1667
|
successfulResponseHandler: createEventSourceResponseHandler(openaiChatChunkSchema),
|
|
@@ -1614,7 +2038,7 @@ var OpenAICompletionLanguageModel = class OpenAICompletionLanguageModel {
|
|
|
1614
2038
|
path: "/completions",
|
|
1615
2039
|
modelId: this.config.requestModelId ?? this.modelId
|
|
1616
2040
|
}),
|
|
1617
|
-
headers: combineHeaders(this.config.headers
|
|
2041
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
1618
2042
|
body: args,
|
|
1619
2043
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1620
2044
|
successfulResponseHandler: createJsonResponseHandler(openaiCompletionResponseSchema),
|
|
@@ -1657,7 +2081,7 @@ var OpenAICompletionLanguageModel = class OpenAICompletionLanguageModel {
|
|
|
1657
2081
|
});
|
|
1658
2082
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1659
2083
|
url,
|
|
1660
|
-
headers: combineHeaders(this.config.headers
|
|
2084
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
1661
2085
|
body,
|
|
1662
2086
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1663
2087
|
successfulResponseHandler: createEventSourceResponseHandler(openaiCompletionChunkSchema),
|
|
@@ -1820,7 +2244,7 @@ var OpenAIEmbeddingModel = class OpenAIEmbeddingModel {
|
|
|
1820
2244
|
path: "/embeddings",
|
|
1821
2245
|
modelId: this.modelId
|
|
1822
2246
|
}),
|
|
1823
|
-
headers: combineHeaders(this.config.headers
|
|
2247
|
+
headers: combineHeaders(await resolve(this.config.headers), headers),
|
|
1824
2248
|
body: {
|
|
1825
2249
|
model: this.modelId,
|
|
1826
2250
|
input: values,
|
|
@@ -1868,25 +2292,12 @@ const openaiImageResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
1868
2292
|
})));
|
|
1869
2293
|
//#endregion
|
|
1870
2294
|
//#region src/image/openai-image-model-options.ts
|
|
1871
|
-
const modelMaxImagesPerCall =
|
|
1872
|
-
"dall-e-3": 1,
|
|
1873
|
-
"dall-e-2": 10,
|
|
1874
|
-
"gpt-image-1": 10,
|
|
1875
|
-
"gpt-image-1-mini": 10,
|
|
1876
|
-
"gpt-image-1.5": 10,
|
|
1877
|
-
"gpt-image-2": 10,
|
|
1878
|
-
"gpt-image-2.5-flare": 10,
|
|
1879
|
-
"gpt-image-2.5-flare-2026-09-08": 10,
|
|
1880
|
-
"gpt-image-2.5-sunburst": 10,
|
|
1881
|
-
"gpt-image-2.5-sunburst-2026-09-08": 10,
|
|
1882
|
-
"chatgpt-image-latest": 10
|
|
1883
|
-
};
|
|
1884
|
-
const defaultResponseFormatPrefixes = ["chatgpt-image-", "gpt-image-"];
|
|
2295
|
+
const modelMaxImagesPerCall = openaiImageModelMaxImagesPerCall;
|
|
1885
2296
|
function hasDefaultResponseFormat(modelId) {
|
|
1886
|
-
return
|
|
2297
|
+
return getOpenAIImageModelEntry(modelId).requestConfig.image.responseFormat === "provider-default";
|
|
1887
2298
|
}
|
|
1888
2299
|
function getMaxImagesPerCall(modelId) {
|
|
1889
|
-
return
|
|
2300
|
+
return getOpenAIImageModelEntry(modelId).capabilities.image.maxImagesPerCall ?? 1;
|
|
1890
2301
|
}
|
|
1891
2302
|
const baseImageModelOptionsObject = () => z.object({
|
|
1892
2303
|
/**
|
|
@@ -1971,23 +2382,13 @@ var OpenAIImageModel = class OpenAIImageModel {
|
|
|
1971
2382
|
}
|
|
1972
2383
|
get supportsFileInputs() {
|
|
1973
2384
|
if (this.config.imageInputCapabilities != null) return this.config.imageInputCapabilities.supportsFileInputs;
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
"gpt-image-1",
|
|
1977
|
-
"gpt-image-1-mini",
|
|
1978
|
-
"gpt-image-1.5",
|
|
1979
|
-
"gpt-image-2",
|
|
1980
|
-
"gpt-image-2.5-flare",
|
|
1981
|
-
"gpt-image-2.5-flare-2026-09-08",
|
|
1982
|
-
"gpt-image-2.5-sunburst",
|
|
1983
|
-
"gpt-image-2.5-sunburst-2026-09-08",
|
|
1984
|
-
"chatgpt-image-latest"
|
|
1985
|
-
].includes(this.modelId)) return true;
|
|
1986
|
-
return this.modelId === "dall-e-3" ? false : void 0;
|
|
2385
|
+
const support = getOpenAIImageModelEntry(this.modelId).capabilities.image.fileInput;
|
|
2386
|
+
return typeof support === "boolean" ? support : void 0;
|
|
1987
2387
|
}
|
|
1988
2388
|
get supportsMaskInputs() {
|
|
1989
2389
|
if (this.config.imageInputCapabilities != null) return this.config.imageInputCapabilities.supportsMaskInputs;
|
|
1990
|
-
|
|
2390
|
+
const support = getOpenAIImageModelEntry(this.modelId).capabilities.image.maskInput;
|
|
2391
|
+
return typeof support === "boolean" ? support : void 0;
|
|
1991
2392
|
}
|
|
1992
2393
|
get provider() {
|
|
1993
2394
|
return this.config.provider;
|
|
@@ -2020,7 +2421,7 @@ var OpenAIImageModel = class OpenAIImageModel {
|
|
|
2020
2421
|
path: "/images/edits",
|
|
2021
2422
|
modelId: this.modelId
|
|
2022
2423
|
}),
|
|
2023
|
-
headers: combineHeaders(this.config.headers
|
|
2424
|
+
headers: combineHeaders(await resolve(this.config.headers), headers),
|
|
2024
2425
|
formData: convertToFormData({
|
|
2025
2426
|
model: this.modelId,
|
|
2026
2427
|
prompt,
|
|
@@ -2074,7 +2475,7 @@ var OpenAIImageModel = class OpenAIImageModel {
|
|
|
2074
2475
|
path: "/images/generations",
|
|
2075
2476
|
modelId: this.modelId
|
|
2076
2477
|
}),
|
|
2077
|
-
headers: combineHeaders(this.config.headers
|
|
2478
|
+
headers: combineHeaders(await resolve(this.config.headers), headers),
|
|
2078
2479
|
body: {
|
|
2079
2480
|
model: this.modelId,
|
|
2080
2481
|
prompt,
|
|
@@ -2242,34 +2643,6 @@ const openAITranscriptionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
2242
2643
|
})));
|
|
2243
2644
|
//#endregion
|
|
2244
2645
|
//#region src/transcription/openai-transcription-model.ts
|
|
2245
|
-
/**
|
|
2246
|
-
* Whether `modelId` is `base` or one of its dated snapshots
|
|
2247
|
-
* (e.g. `gpt-realtime-whisper-2026-01-01`).
|
|
2248
|
-
*/
|
|
2249
|
-
function isModelOrSnapshot(modelId, base) {
|
|
2250
|
-
return modelId === base || modelId.startsWith(`${base}-`);
|
|
2251
|
-
}
|
|
2252
|
-
/**
|
|
2253
|
-
* Model IDs that stream over the realtime transcription WebSocket and do not
|
|
2254
|
-
* support the REST transcription endpoint.
|
|
2255
|
-
*/
|
|
2256
|
-
function isRealtimeTranscriptionModelId(modelId) {
|
|
2257
|
-
return isModelOrSnapshot(modelId, "gpt-realtime-whisper") || isModelOrSnapshot(modelId, "gpt-live-transcribe");
|
|
2258
|
-
}
|
|
2259
|
-
/**
|
|
2260
|
-
* Model IDs that support streaming transcription. `gpt-transcribe` also
|
|
2261
|
-
* supports the REST transcription endpoint.
|
|
2262
|
-
*/
|
|
2263
|
-
function supportsStreamingTranscription(modelId) {
|
|
2264
|
-
return isRealtimeTranscriptionModelId(modelId) || isModelOrSnapshot(modelId, "gpt-transcribe");
|
|
2265
|
-
}
|
|
2266
|
-
/**
|
|
2267
|
-
* Models whose realtime transcription session takes a `languages` list
|
|
2268
|
-
* instead of the singular `language` field.
|
|
2269
|
-
*/
|
|
2270
|
-
function usesLanguagesList(modelId) {
|
|
2271
|
-
return isModelOrSnapshot(modelId, "gpt-live-transcribe") || isModelOrSnapshot(modelId, "gpt-transcribe");
|
|
2272
|
-
}
|
|
2273
2646
|
const languageMap = {
|
|
2274
2647
|
afrikaans: "af",
|
|
2275
2648
|
arabic: "ar",
|
|
@@ -2362,10 +2735,10 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2362
2735
|
formData.append("model", this.modelId);
|
|
2363
2736
|
const fileExtension = mediaTypeToExtension(mediaType);
|
|
2364
2737
|
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
2365
|
-
const
|
|
2366
|
-
const responseFormat = openAIOptions?.responseFormat ??
|
|
2738
|
+
const { transcription: requestConfig } = getOpenAITranscriptionModelEntry(this.modelId).requestConfig;
|
|
2739
|
+
const responseFormat = openAIOptions?.responseFormat ?? requestConfig.responseFormat;
|
|
2367
2740
|
const timestampGranularities = openAIOptions?.timestampGranularities ?? (responseFormat === "verbose_json" ? ["segment"] : void 0);
|
|
2368
|
-
const chunkingStrategy = openAIOptions?.chunkingStrategy ??
|
|
2741
|
+
const chunkingStrategy = openAIOptions?.chunkingStrategy ?? requestConfig.chunkingStrategy;
|
|
2369
2742
|
const transcriptionModelOptions = {
|
|
2370
2743
|
response_format: responseFormat,
|
|
2371
2744
|
include: openAIOptions?.include,
|
|
@@ -2390,7 +2763,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2390
2763
|
};
|
|
2391
2764
|
}
|
|
2392
2765
|
async doGenerate(options) {
|
|
2393
|
-
if (
|
|
2766
|
+
if (getOpenAITranscriptionModelEntry(this.modelId).capabilities.transcription.transcription === false) throw new UnsupportedFunctionalityError({ functionality: `non-streaming transcription with ${this.modelId}` });
|
|
2394
2767
|
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
2395
2768
|
const { formData, warnings } = await this.getArgs(options);
|
|
2396
2769
|
const { value: response, responseHeaders, rawValue: rawResponse } = await postFormDataToApi({
|
|
@@ -2398,7 +2771,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2398
2771
|
path: "/audio/transcriptions",
|
|
2399
2772
|
modelId: this.modelId
|
|
2400
2773
|
}),
|
|
2401
|
-
headers: combineHeaders(this.config.headers
|
|
2774
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
2402
2775
|
formData,
|
|
2403
2776
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2404
2777
|
successfulResponseHandler: createJsonResponseHandler(openaiTranscriptionResponseSchema),
|
|
@@ -2440,7 +2813,8 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2440
2813
|
};
|
|
2441
2814
|
}
|
|
2442
2815
|
async doStream(options) {
|
|
2443
|
-
|
|
2816
|
+
const entry = getOpenAITranscriptionModelEntry(this.modelId);
|
|
2817
|
+
if (entry.capabilities.transcription.streaming !== true) throw new UnsupportedFunctionalityError({ functionality: `streaming transcription with ${this.modelId}` });
|
|
2444
2818
|
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
2445
2819
|
const openAIOptions = await parseProviderOptions({
|
|
2446
2820
|
provider: "openai",
|
|
@@ -2459,13 +2833,13 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2459
2833
|
feature: `providerOptions.openai.${option}`,
|
|
2460
2834
|
details: `OpenAI streaming transcription does not support ${option}.`
|
|
2461
2835
|
});
|
|
2462
|
-
const supportsDelay =
|
|
2836
|
+
const supportsDelay = entry.capabilities.transcription.streamingDelay === true;
|
|
2463
2837
|
if (!supportsDelay && openAIOptions?.streaming?.delay != null) warnings.push({
|
|
2464
2838
|
type: "unsupported",
|
|
2465
2839
|
feature: "providerOptions.openai.streaming.delay",
|
|
2466
2840
|
details: `OpenAI streaming transcription with ${this.modelId} does not support delay.`
|
|
2467
2841
|
});
|
|
2468
|
-
const headers = combineHeaders(this.config.headers
|
|
2842
|
+
const headers = combineHeaders(await resolve(this.config.headers), options.headers);
|
|
2469
2843
|
const sessionUpdate = buildOpenAIRealtimeTranscriptionSession({
|
|
2470
2844
|
modelId: this.modelId,
|
|
2471
2845
|
inputAudioFormat: options.inputAudioFormat,
|
|
@@ -2617,7 +2991,7 @@ function buildOpenAIRealtimeTranscriptionSession({ modelId, inputAudioFormat, pr
|
|
|
2617
2991
|
},
|
|
2618
2992
|
transcription: {
|
|
2619
2993
|
model: modelId,
|
|
2620
|
-
...providerOptions?.language != null ?
|
|
2994
|
+
...providerOptions?.language != null ? getOpenAITranscriptionModelEntry(modelId).requestConfig.transcription.languageField === "languages" ? { languages: [providerOptions.language] } : { language: providerOptions.language } : {},
|
|
2621
2995
|
...supportsDelay && providerOptions?.streaming?.delay != null ? { delay: providerOptions.streaming.delay } : {}
|
|
2622
2996
|
},
|
|
2623
2997
|
turn_detection: null
|
|
@@ -2723,7 +3097,7 @@ var OpenAISpeechModel = class OpenAISpeechModel {
|
|
|
2723
3097
|
path: "/audio/speech",
|
|
2724
3098
|
modelId: this.modelId
|
|
2725
3099
|
}),
|
|
2726
|
-
headers: combineHeaders(this.config.headers
|
|
3100
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
2727
3101
|
body: requestBody,
|
|
2728
3102
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2729
3103
|
successfulResponseHandler: createBinaryResponseHandler(),
|
|
@@ -6339,7 +6713,7 @@ const openaiResponsesSupportedUrls = {
|
|
|
6339
6713
|
* @see https://developers.openai.com/api/docs/guides/reasoning#change-reasoning-mid-conversation
|
|
6340
6714
|
*/
|
|
6341
6715
|
function getConfigurationUpdateUnsupportedReason({ modelCapabilities, options }) {
|
|
6342
|
-
if (!modelCapabilities.
|
|
6716
|
+
if (!modelCapabilities.configurationUpdates) return "reasoningEffortUpdate is only supported by GPT-6 and later models";
|
|
6343
6717
|
if (options?.reasoningMode === "pro" || options?.contextManagement != null || options?.truncation === "auto") return "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation";
|
|
6344
6718
|
}
|
|
6345
6719
|
var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
@@ -6363,7 +6737,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6363
6737
|
}
|
|
6364
6738
|
static async prepareRequest({ modelId, config, options: { maxOutputTokens, temperature, stopSequences, topP, topK, presencePenalty, frequencyPenalty, seed, prompt, reasoning, providerOptions, tools, toolChoice, responseFormat } }) {
|
|
6365
6739
|
const warnings = [];
|
|
6366
|
-
const modelCapabilities =
|
|
6740
|
+
const { capabilities: { language: modelCapabilities }, requestConfig: { language: modelRequestConfig } } = getOpenAILanguageModelEntry(modelId);
|
|
6367
6741
|
if (topK != null) warnings.push({
|
|
6368
6742
|
type: "unsupported",
|
|
6369
6743
|
feature: "topK"
|
|
@@ -6398,11 +6772,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6398
6772
|
const resolvedReasoningEffort = resolveOpenAIReasoningEffort({
|
|
6399
6773
|
providerReasoningEffort: openaiOptions?.reasoningEffort,
|
|
6400
6774
|
reasoning,
|
|
6401
|
-
supportedReasoningEfforts: modelCapabilities.
|
|
6775
|
+
supportedReasoningEfforts: modelCapabilities.reasoning.efforts,
|
|
6402
6776
|
warnings
|
|
6403
6777
|
});
|
|
6404
6778
|
const resolvedReasoningSummary = openaiOptions?.reasoningSummary !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
6405
|
-
const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.
|
|
6779
|
+
const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.reasoning.support === true;
|
|
6406
6780
|
if (openaiOptions?.conversation && openaiOptions?.previousResponseId) warnings.push({
|
|
6407
6781
|
type: "unsupported",
|
|
6408
6782
|
feature: "conversation",
|
|
@@ -6434,7 +6808,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6434
6808
|
toolNameMapping,
|
|
6435
6809
|
customProviderToolNames,
|
|
6436
6810
|
outputSchemaToolNames,
|
|
6437
|
-
supportsAsyncToolCalling: modelCapabilities.
|
|
6811
|
+
supportsAsyncToolCalling: modelCapabilities.tools.async,
|
|
6438
6812
|
providerOptionsName
|
|
6439
6813
|
});
|
|
6440
6814
|
const configurationUpdateUnsupportedReason = getConfigurationUpdateUnsupportedReason({
|
|
@@ -6444,7 +6818,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6444
6818
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
6445
6819
|
prompt,
|
|
6446
6820
|
toolNameMapping,
|
|
6447
|
-
systemMessageMode: openaiOptions?.systemMessageMode ?? (isReasoningModel ? "developer" :
|
|
6821
|
+
systemMessageMode: openaiOptions?.systemMessageMode ?? (isReasoningModel ? "developer" : modelRequestConfig.systemMessageMode),
|
|
6448
6822
|
providerOptionsName,
|
|
6449
6823
|
configurationUpdateUnsupportedReason,
|
|
6450
6824
|
explicitMessageItemType: config.explicitMessageItemType,
|
|
@@ -6463,7 +6837,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6463
6837
|
outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
|
|
6464
6838
|
});
|
|
6465
6839
|
warnings.push(...inputWarnings);
|
|
6466
|
-
const supportedReasoningEfforts = modelCapabilities.
|
|
6840
|
+
const supportedReasoningEfforts = modelCapabilities.reasoning.efforts;
|
|
6467
6841
|
const getUpdateEffortUnsupportedReason = (effort) => effort != null && supportedReasoningEfforts?.includes(effort) === false ? `${modelId} only supports the following reasoning efforts: ${supportedReasoningEfforts.join(", ")}` : void 0;
|
|
6468
6842
|
for (const item of input) if (item.type === "configuration_update") {
|
|
6469
6843
|
const unsupportedReason = getUpdateEffortUnsupportedReason(item.reasoning.effort);
|
|
@@ -6552,7 +6926,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6552
6926
|
...openaiOptions?.reasoningContext != null && { context: openaiOptions.reasoningContext }
|
|
6553
6927
|
} }
|
|
6554
6928
|
};
|
|
6555
|
-
if (modelCapabilities.
|
|
6929
|
+
if (!modelCapabilities.promptCache.retention && baseArgs.prompt_cache_retention != null) {
|
|
6556
6930
|
baseArgs.prompt_cache_retention = void 0;
|
|
6557
6931
|
warnings.push({
|
|
6558
6932
|
type: "unsupported",
|
|
@@ -6563,7 +6937,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6563
6937
|
if (isReasoningModel) {
|
|
6564
6938
|
let effectiveReasoningEffort = resolvedReasoningEffort;
|
|
6565
6939
|
for (const item of input) if (item.type === "configuration_update") effectiveReasoningEffort = item.reasoning.effort;
|
|
6566
|
-
if (!(effectiveReasoningEffort === "none" && modelCapabilities.
|
|
6940
|
+
if (!(effectiveReasoningEffort === "none" && modelCapabilities.reasoning.sampling === "reasoning-effort-none")) {
|
|
6567
6941
|
if (baseArgs.temperature != null) {
|
|
6568
6942
|
baseArgs.temperature = void 0;
|
|
6569
6943
|
warnings.push({
|
|
@@ -6580,7 +6954,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6580
6954
|
details: "topP is not supported for reasoning models"
|
|
6581
6955
|
});
|
|
6582
6956
|
}
|
|
6583
|
-
if (modelCapabilities.
|
|
6957
|
+
if (modelCapabilities.endpoints.responses.logprobsRequireNonReasoning && (baseArgs.top_logprobs != null || baseArgs.include?.includes("message.output_text.logprobs"))) {
|
|
6584
6958
|
baseArgs.top_logprobs = void 0;
|
|
6585
6959
|
const filteredInclude = baseArgs.include?.filter((value) => value !== "message.output_text.logprobs");
|
|
6586
6960
|
baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
|
|
@@ -6613,7 +6987,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6613
6987
|
details: "reasoningContext is not supported for non-reasoning models"
|
|
6614
6988
|
});
|
|
6615
6989
|
}
|
|
6616
|
-
if (openaiOptions?.serviceTier === "flex" && !modelCapabilities.
|
|
6990
|
+
if (openaiOptions?.serviceTier === "flex" && !modelCapabilities.serviceTiers.flex) {
|
|
6617
6991
|
warnings.push({
|
|
6618
6992
|
type: "unsupported",
|
|
6619
6993
|
feature: "serviceTier",
|
|
@@ -6621,7 +6995,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6621
6995
|
});
|
|
6622
6996
|
delete baseArgs.service_tier;
|
|
6623
6997
|
}
|
|
6624
|
-
if ((openaiOptions?.serviceTier === "priority" || openaiOptions?.serviceTier === "fast") && !modelCapabilities.
|
|
6998
|
+
if ((openaiOptions?.serviceTier === "priority" || openaiOptions?.serviceTier === "fast") && !modelCapabilities.serviceTiers.priority) {
|
|
6625
6999
|
warnings.push({
|
|
6626
7000
|
type: "unsupported",
|
|
6627
7001
|
feature: "serviceTier",
|
|
@@ -6661,7 +7035,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6661
7035
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6662
7036
|
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
6663
7037
|
url,
|
|
6664
|
-
headers: combineHeaders(this.config.headers
|
|
7038
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
6665
7039
|
body,
|
|
6666
7040
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
6667
7041
|
successfulResponseHandler: createJsonResponseHandler(openaiResponsesResponseSchema),
|
|
@@ -7111,7 +7485,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7111
7485
|
});
|
|
7112
7486
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
7113
7487
|
url,
|
|
7114
|
-
headers: combineHeaders(this.config.headers
|
|
7488
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers),
|
|
7115
7489
|
body: {
|
|
7116
7490
|
...body,
|
|
7117
7491
|
stream: true
|