@ai-sdk/openai 3.0.122 → 3.0.124
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 +12 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +99 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -5
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +98 -4
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +98 -4
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +4 -2
- package/package.json +1 -1
- package/src/chat/openai-chat-language-model.ts +2 -1
- package/src/chat/openai-chat-options.ts +2 -1
- package/src/normalize-openai-json-schema.ts +142 -0
- package/src/responses/openai-responses-language-model.ts +2 -1
- package/src/responses/openai-responses-options.ts +2 -1
package/docs/03-openai.mdx
CHANGED
|
@@ -246,12 +246,13 @@ The following provider options are available:
|
|
|
246
246
|
`.nullable()`.
|
|
247
247
|
</Note>
|
|
248
248
|
|
|
249
|
-
- **serviceTier** _'auto' | 'flex' | 'priority' | 'fast' | 'default'_
|
|
249
|
+
- **serviceTier** _'auto' | 'flex' | 'priority' | 'fast' | 'ultrafast' | 'default'_
|
|
250
250
|
Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
251
251
|
at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
252
252
|
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).
|
|
253
253
|
'fast' is OpenAI's newer name for the 'priority' tier; the two are interchangeable, and responses from
|
|
254
254
|
gpt-5.6 and earlier report `serviceTier: 'priority'` for either.
|
|
255
|
+
Set to 'ultrafast' for access-controlled Ultrafast processing (available only for gpt-5.6-sol).
|
|
255
256
|
|
|
256
257
|
Defaults to 'auto'.
|
|
257
258
|
|
|
@@ -1943,13 +1944,14 @@ The following optional provider options are available for OpenAI chat models:
|
|
|
1943
1944
|
|
|
1944
1945
|
Parameters for prediction mode.
|
|
1945
1946
|
|
|
1946
|
-
- **serviceTier** _'auto' | 'flex' | 'priority' | 'fast' | 'default'_
|
|
1947
|
+
- **serviceTier** _'auto' | 'flex' | 'priority' | 'fast' | 'ultrafast' | 'default'_
|
|
1947
1948
|
|
|
1948
1949
|
Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
1949
1950
|
at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
1950
1951
|
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).
|
|
1951
1952
|
'fast' is OpenAI's newer name for the 'priority' tier; the two are interchangeable, and responses from
|
|
1952
1953
|
gpt-5.6 and earlier report `serviceTier: 'priority'` for either.
|
|
1954
|
+
Set to 'ultrafast' for access-controlled Ultrafast processing (available only for gpt-5.6-sol).
|
|
1953
1955
|
|
|
1954
1956
|
Defaults to 'auto'.
|
|
1955
1957
|
|
package/package.json
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '@ai-sdk/provider-utils';
|
|
24
24
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
25
25
|
import { getOpenAILanguageModelCapabilities } from '../openai-language-model-capabilities';
|
|
26
|
+
import { normalizeOpenAIJsonSchema } from '../normalize-openai-json-schema';
|
|
26
27
|
import { throwIfOpenAIStreamErrorBeforeOutput } from '../openai-stream-error';
|
|
27
28
|
import {
|
|
28
29
|
convertOpenAIChatUsage,
|
|
@@ -168,7 +169,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV3 {
|
|
|
168
169
|
? {
|
|
169
170
|
type: 'json_schema',
|
|
170
171
|
json_schema: {
|
|
171
|
-
schema: responseFormat.schema,
|
|
172
|
+
schema: normalizeOpenAIJsonSchema(responseFormat.schema),
|
|
172
173
|
strict: strictJsonSchema,
|
|
173
174
|
name: responseFormat.name ?? 'response',
|
|
174
175
|
description: responseFormat.description,
|
|
@@ -144,12 +144,13 @@ export const openaiLanguageModelChatOptions = lazySchema(() =>
|
|
|
144
144
|
* - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
145
145
|
* - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
|
|
146
146
|
* - 'fast': OpenAI's newer name for the 'priority' tier. Interchangeable with it.
|
|
147
|
+
* - 'ultrafast': Access-controlled Ultrafast processing. Only available for gpt-5.6-sol.
|
|
147
148
|
* - 'default': The request will be processed with the standard pricing and performance for the selected model.
|
|
148
149
|
*
|
|
149
150
|
* @default 'auto'
|
|
150
151
|
*/
|
|
151
152
|
serviceTier: z
|
|
152
|
-
.enum(['auto', 'flex', 'priority', 'fast', 'default'])
|
|
153
|
+
.enum(['auto', 'flex', 'priority', 'fast', 'ultrafast', 'default'])
|
|
153
154
|
.optional(),
|
|
154
155
|
|
|
155
156
|
/**
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { JSONSchema7, JSONSchema7Definition } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OpenAI does not support `allOf`. Zod 4 uses a singleton `allOf` wrapper for
|
|
5
|
+
* recursive references, which can be rewritten to a direct reference.
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeOpenAIJsonSchema(schema: JSONSchema7): JSONSchema7 {
|
|
8
|
+
const normalizedSchema = normalizeSchema(schema, true) as JSONSchema7;
|
|
9
|
+
const reference = getSingletonReference(normalizedSchema);
|
|
10
|
+
|
|
11
|
+
if (reference == null) {
|
|
12
|
+
return normalizedSchema;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema;
|
|
16
|
+
const referencedSchema = getLocalReferenceSchema(reference, normalizedSchema);
|
|
17
|
+
|
|
18
|
+
// OpenAI requires an object at the schema root, so expand local root refs.
|
|
19
|
+
return typeof referencedSchema !== 'object' || referencedSchema == null
|
|
20
|
+
? normalizedSchema
|
|
21
|
+
: { ...referencedSchema, ...schemaWithoutAllOf };
|
|
22
|
+
|
|
23
|
+
function normalizeSchema(
|
|
24
|
+
schema: JSONSchema7Definition,
|
|
25
|
+
isRoot = false,
|
|
26
|
+
): JSONSchema7Definition {
|
|
27
|
+
if (typeof schema !== 'object' || schema == null) {
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const normalizedSchema: JSONSchema7 = { ...schema };
|
|
32
|
+
|
|
33
|
+
if (normalizedSchema.properties != null) {
|
|
34
|
+
normalizedSchema.properties = normalizeSchemaRecord(
|
|
35
|
+
normalizedSchema.properties,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (normalizedSchema.patternProperties != null) {
|
|
40
|
+
normalizedSchema.patternProperties = normalizeSchemaRecord(
|
|
41
|
+
normalizedSchema.patternProperties,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (normalizedSchema.definitions != null) {
|
|
46
|
+
normalizedSchema.definitions = normalizeSchemaRecord(
|
|
47
|
+
normalizedSchema.definitions,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (normalizedSchema.$defs != null) {
|
|
52
|
+
normalizedSchema.$defs = normalizeSchemaRecord(normalizedSchema.$defs);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (normalizedSchema.items != null) {
|
|
56
|
+
normalizedSchema.items = Array.isArray(normalizedSchema.items)
|
|
57
|
+
? normalizedSchema.items.map(item => normalizeSchema(item))
|
|
58
|
+
: normalizeSchema(normalizedSchema.items);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (normalizedSchema.allOf != null) {
|
|
62
|
+
normalizedSchema.allOf = normalizedSchema.allOf.map(item =>
|
|
63
|
+
normalizeSchema(item),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (normalizedSchema.anyOf != null) {
|
|
68
|
+
normalizedSchema.anyOf = normalizedSchema.anyOf.map(item =>
|
|
69
|
+
normalizeSchema(item),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (normalizedSchema.oneOf != null) {
|
|
74
|
+
normalizedSchema.oneOf = normalizedSchema.oneOf.map(item =>
|
|
75
|
+
normalizeSchema(item),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
typeof normalizedSchema.additionalProperties === 'object' &&
|
|
81
|
+
normalizedSchema.additionalProperties != null
|
|
82
|
+
) {
|
|
83
|
+
normalizedSchema.additionalProperties = normalizeSchema(
|
|
84
|
+
normalizedSchema.additionalProperties,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const reference = getSingletonReference(normalizedSchema);
|
|
89
|
+
|
|
90
|
+
if (reference == null || isRoot) {
|
|
91
|
+
return normalizedSchema;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema;
|
|
95
|
+
return { ...schemaWithoutAllOf, $ref: reference };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizeSchemaRecord(
|
|
99
|
+
record: Record<string, JSONSchema7Definition>,
|
|
100
|
+
): Record<string, JSONSchema7Definition> {
|
|
101
|
+
return Object.fromEntries(
|
|
102
|
+
Object.entries(record).map(([key, value]) => [
|
|
103
|
+
key,
|
|
104
|
+
normalizeSchema(value),
|
|
105
|
+
]),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getSingletonReference(schema: JSONSchema7): string | undefined {
|
|
110
|
+
if (schema.allOf?.length !== 1) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const [allOfSchema] = schema.allOf;
|
|
115
|
+
return typeof allOfSchema === 'object' &&
|
|
116
|
+
allOfSchema != null &&
|
|
117
|
+
Object.keys(allOfSchema).length === 1 &&
|
|
118
|
+
typeof allOfSchema.$ref === 'string'
|
|
119
|
+
? allOfSchema.$ref
|
|
120
|
+
: undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getLocalReferenceSchema(
|
|
124
|
+
reference: string,
|
|
125
|
+
schema: JSONSchema7,
|
|
126
|
+
): JSONSchema7Definition | undefined {
|
|
127
|
+
const match = /^#\/(definitions|\$defs)\/(.+)$/.exec(reference);
|
|
128
|
+
|
|
129
|
+
if (match == null) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const [, keyword, encodedName] = match;
|
|
134
|
+
const name = encodedName.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
135
|
+
const definition =
|
|
136
|
+
keyword === 'definitions'
|
|
137
|
+
? schema.definitions?.[name]
|
|
138
|
+
: schema.$defs?.[name];
|
|
139
|
+
|
|
140
|
+
return definition;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
import type { OpenAIConfig } from '../openai-config';
|
|
31
31
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
32
32
|
import { getOpenAILanguageModelCapabilities } from '../openai-language-model-capabilities';
|
|
33
|
+
import { normalizeOpenAIJsonSchema } from '../normalize-openai-json-schema';
|
|
33
34
|
import {
|
|
34
35
|
createOpenAIProviderStreamError,
|
|
35
36
|
throwIfOpenAIStreamErrorBeforeOutput,
|
|
@@ -422,7 +423,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
422
423
|
strict: strictJsonSchema,
|
|
423
424
|
name: responseFormat.name ?? 'response',
|
|
424
425
|
description: responseFormat.description,
|
|
425
|
-
schema: responseFormat.schema,
|
|
426
|
+
schema: normalizeOpenAIJsonSchema(responseFormat.schema),
|
|
426
427
|
}
|
|
427
428
|
: { type: 'json_object' },
|
|
428
429
|
}),
|
|
@@ -315,11 +315,12 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
|
315
315
|
* Set to 'flex' for 50% cheaper processing at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
316
316
|
* 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).
|
|
317
317
|
* Set to 'fast' for the same tier as 'priority' (OpenAI's newer name for it).
|
|
318
|
+
* Set to 'ultrafast' for access-controlled Ultrafast processing (available only for gpt-5.6-sol).
|
|
318
319
|
*
|
|
319
320
|
* Defaults to 'auto'.
|
|
320
321
|
*/
|
|
321
322
|
serviceTier: z
|
|
322
|
-
.enum(['auto', 'flex', 'priority', 'fast', 'default'])
|
|
323
|
+
.enum(['auto', 'flex', 'priority', 'fast', 'ultrafast', 'default'])
|
|
323
324
|
.nullish(),
|
|
324
325
|
|
|
325
326
|
/**
|