@ai-sdk/openai 4.0.35 → 4.0.36
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 +11 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -12
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +24 -11
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +6 -2
- package/package.json +3 -3
- package/src/chat/openai-chat-language-model-options.ts +4 -1
- package/src/chat/openai-chat-language-model.ts +2 -1
- package/src/responses/convert-to-openai-responses-input.ts +13 -3
- package/src/responses/openai-responses-language-model-options.ts +4 -1
- package/src/responses/openai-responses-language-model.ts +9 -1
- package/src/responses/openai-responses-prepare-tools.ts +5 -0
package/docs/03-openai.mdx
CHANGED
|
@@ -217,10 +217,12 @@ The following provider options are available:
|
|
|
217
217
|
`.nullable()`.
|
|
218
218
|
</Note>
|
|
219
219
|
|
|
220
|
-
- **serviceTier** _'auto' | 'flex' | 'priority' | 'default'_
|
|
220
|
+
- **serviceTier** _'auto' | 'flex' | 'priority' | 'fast' | 'default'_
|
|
221
221
|
Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
222
222
|
at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
223
223
|
Set to 'priority' for faster processing with Enterprise access (available for gpt-4, gpt-5, gpt-5-mini, o3, o4-mini; gpt-5-nano is not supported).
|
|
224
|
+
'fast' is OpenAI's newer name for the 'priority' tier; the two are interchangeable, and responses from
|
|
225
|
+
gpt-5.6 and earlier report `serviceTier: 'priority'` for either.
|
|
224
226
|
|
|
225
227
|
Defaults to 'auto'.
|
|
226
228
|
|
|
@@ -1991,11 +1993,13 @@ The following optional provider options are available for OpenAI chat models:
|
|
|
1991
1993
|
|
|
1992
1994
|
Parameters for prediction mode.
|
|
1993
1995
|
|
|
1994
|
-
- **serviceTier** _'auto' | 'flex' | 'priority' | 'default'_
|
|
1996
|
+
- **serviceTier** _'auto' | 'flex' | 'priority' | 'fast' | 'default'_
|
|
1995
1997
|
|
|
1996
1998
|
Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
1997
1999
|
at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
1998
2000
|
Set to 'priority' for faster processing with Enterprise access (available for gpt-4, gpt-5, gpt-5-mini, o3, o4-mini; gpt-5-nano is not supported).
|
|
2001
|
+
'fast' is OpenAI's newer name for the 'priority' tier; the two are interchangeable, and responses from
|
|
2002
|
+
gpt-5.6 and earlier report `serviceTier: 'priority'` for either.
|
|
1999
2003
|
|
|
2000
2004
|
Defaults to 'auto'.
|
|
2001
2005
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.7",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.25"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "22.19.19",
|
|
@@ -138,11 +138,14 @@ export const openaiLanguageModelChatOptions = lazySchema(() =>
|
|
|
138
138
|
* Project settings. Unless otherwise configured, the Project will use 'default'.
|
|
139
139
|
* - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
140
140
|
* - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
|
|
141
|
+
* - 'fast': OpenAI's newer name for the 'priority' tier. Interchangeable with it.
|
|
141
142
|
* - 'default': The request will be processed with the standard pricing and performance for the selected model.
|
|
142
143
|
*
|
|
143
144
|
* @default 'auto'
|
|
144
145
|
*/
|
|
145
|
-
serviceTier: z
|
|
146
|
+
serviceTier: z
|
|
147
|
+
.enum(['auto', 'flex', 'priority', 'fast', 'default'])
|
|
148
|
+
.optional(),
|
|
146
149
|
|
|
147
150
|
/**
|
|
148
151
|
* Whether to use strict JSON schema validation.
|
|
@@ -308,7 +308,8 @@ export class OpenAIChatLanguageModel implements LanguageModelV4 {
|
|
|
308
308
|
|
|
309
309
|
// Validate priority processing support
|
|
310
310
|
if (
|
|
311
|
-
openaiOptions.serviceTier === 'priority'
|
|
311
|
+
(openaiOptions.serviceTier === 'priority' ||
|
|
312
|
+
openaiOptions.serviceTier === 'fast') &&
|
|
312
313
|
!modelCapabilities.supportsPriorityProcessing
|
|
313
314
|
) {
|
|
314
315
|
warnings.push({
|
|
@@ -98,6 +98,7 @@ export async function convertToOpenAIResponsesInput({
|
|
|
98
98
|
hasApplyPatchTool = false,
|
|
99
99
|
hasComputerTool = false,
|
|
100
100
|
customProviderToolNames,
|
|
101
|
+
outputSchemaToolNames,
|
|
101
102
|
}: {
|
|
102
103
|
prompt: LanguageModelV4Prompt;
|
|
103
104
|
toolNameMapping: ToolNameMapping;
|
|
@@ -114,6 +115,7 @@ export async function convertToOpenAIResponsesInput({
|
|
|
114
115
|
hasApplyPatchTool?: boolean;
|
|
115
116
|
hasComputerTool?: boolean;
|
|
116
117
|
customProviderToolNames?: Set<string>;
|
|
118
|
+
outputSchemaToolNames?: Set<string>;
|
|
117
119
|
}): Promise<{
|
|
118
120
|
input: OpenAIResponsesInput;
|
|
119
121
|
warnings: Array<SharedV4Warning>;
|
|
@@ -1141,14 +1143,22 @@ export async function convertToOpenAIResponsesInput({
|
|
|
1141
1143
|
}
|
|
1142
1144
|
|
|
1143
1145
|
let contentValue: OpenAIResponsesFunctionCallOutput['output'];
|
|
1146
|
+
// `output` is always a string, but for functions with output_schema
|
|
1147
|
+
// OpenAI parses the contents of that string as JSON. Text-like results
|
|
1148
|
+
// therefore need JSON.stringify to become valid JSON string literals.
|
|
1149
|
+
const hasOutputSchema = outputSchemaToolNames?.has(part.toolName);
|
|
1144
1150
|
switch (output.type) {
|
|
1145
1151
|
case 'text':
|
|
1146
1152
|
case 'error-text':
|
|
1147
|
-
contentValue =
|
|
1153
|
+
contentValue = hasOutputSchema
|
|
1154
|
+
? JSON.stringify(output.value)
|
|
1155
|
+
: output.value;
|
|
1148
1156
|
break;
|
|
1149
|
-
case 'execution-denied':
|
|
1150
|
-
|
|
1157
|
+
case 'execution-denied': {
|
|
1158
|
+
const reason = output.reason ?? 'Tool call execution denied.';
|
|
1159
|
+
contentValue = hasOutputSchema ? JSON.stringify(reason) : reason;
|
|
1151
1160
|
break;
|
|
1161
|
+
}
|
|
1152
1162
|
case 'json':
|
|
1153
1163
|
case 'error-json':
|
|
1154
1164
|
contentValue = JSON.stringify(output.value);
|
|
@@ -293,10 +293,13 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
|
293
293
|
* Service tier for the request.
|
|
294
294
|
* Set to 'flex' for 50% cheaper processing at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
295
295
|
* Set to 'priority' for faster processing with Enterprise access (available for gpt-4, gpt-5, gpt-5-mini, o3, o4-mini; gpt-5-nano is not supported).
|
|
296
|
+
* Set to 'fast' for the same tier as 'priority' (OpenAI's newer name for it).
|
|
296
297
|
*
|
|
297
298
|
* Defaults to 'auto'.
|
|
298
299
|
*/
|
|
299
|
-
serviceTier: z
|
|
300
|
+
serviceTier: z
|
|
301
|
+
.enum(['auto', 'flex', 'priority', 'fast', 'default'])
|
|
302
|
+
.nullish(),
|
|
300
303
|
|
|
301
304
|
/**
|
|
302
305
|
* Whether to store the generation. Defaults to `true`.
|
|
@@ -322,6 +322,10 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
322
322
|
});
|
|
323
323
|
|
|
324
324
|
const customProviderToolNames = new Set<string>();
|
|
325
|
+
// OpenAI requires function_call_output.output to contain valid JSON when the
|
|
326
|
+
// function declares output_schema. Preserve the affected SDK tool names so
|
|
327
|
+
// prompt conversion can apply that encoding only to their results.
|
|
328
|
+
const outputSchemaToolNames = new Set<string>();
|
|
325
329
|
const {
|
|
326
330
|
tools: openaiTools,
|
|
327
331
|
toolChoice: openaiToolChoice,
|
|
@@ -332,6 +336,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
332
336
|
allowedTools: openaiOptions?.allowedTools ?? undefined,
|
|
333
337
|
toolNameMapping,
|
|
334
338
|
customProviderToolNames,
|
|
339
|
+
outputSchemaToolNames,
|
|
335
340
|
});
|
|
336
341
|
|
|
337
342
|
const { input, warnings: inputWarnings } =
|
|
@@ -358,6 +363,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
358
363
|
customProviderToolNames.size > 0
|
|
359
364
|
? customProviderToolNames
|
|
360
365
|
: undefined,
|
|
366
|
+
outputSchemaToolNames:
|
|
367
|
+
outputSchemaToolNames.size > 0 ? outputSchemaToolNames : undefined,
|
|
361
368
|
});
|
|
362
369
|
|
|
363
370
|
warnings.push(...inputWarnings);
|
|
@@ -574,7 +581,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
574
581
|
|
|
575
582
|
// Validate priority processing support
|
|
576
583
|
if (
|
|
577
|
-
openaiOptions?.serviceTier === 'priority'
|
|
584
|
+
(openaiOptions?.serviceTier === 'priority' ||
|
|
585
|
+
openaiOptions?.serviceTier === 'fast') &&
|
|
578
586
|
!modelCapabilities.supportsPriorityProcessing
|
|
579
587
|
) {
|
|
580
588
|
warnings.push({
|
|
@@ -42,6 +42,7 @@ export async function prepareResponsesTools({
|
|
|
42
42
|
allowedTools,
|
|
43
43
|
toolNameMapping,
|
|
44
44
|
customProviderToolNames,
|
|
45
|
+
outputSchemaToolNames,
|
|
45
46
|
}: {
|
|
46
47
|
tools: LanguageModelV4CallOptions['tools'];
|
|
47
48
|
toolChoice: LanguageModelV4CallOptions['toolChoice'] | undefined;
|
|
@@ -51,6 +52,7 @@ export async function prepareResponsesTools({
|
|
|
51
52
|
};
|
|
52
53
|
toolNameMapping?: ToolNameMapping;
|
|
53
54
|
customProviderToolNames?: Set<string>;
|
|
55
|
+
outputSchemaToolNames?: Set<string>;
|
|
54
56
|
}): Promise<{
|
|
55
57
|
tools?: Array<OpenAIResponsesTool>;
|
|
56
58
|
toolChoice?:
|
|
@@ -98,6 +100,9 @@ export async function prepareResponsesTools({
|
|
|
98
100
|
const openaiOptions = tool.providerOptions?.openai as
|
|
99
101
|
| OpenAIToolOptions
|
|
100
102
|
| undefined;
|
|
103
|
+
if (openaiOptions?.outputSchema != null) {
|
|
104
|
+
outputSchemaToolNames?.add(tool.name);
|
|
105
|
+
}
|
|
101
106
|
const openaiFunctionTool = prepareFunctionTool({
|
|
102
107
|
tool,
|
|
103
108
|
options: openaiOptions,
|