Skip to content

Commit 5e2df97

Browse files
authored
fix(provider): accept OpenAI ultrafast service tier (anomalyco#53875)
1 parent 663fbd7 commit 5e2df97

2 files changed

Lines changed: 204 additions & 4 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, test } from "bun:test"
2+
import { createOpenAI, type OpenAILanguageModelResponsesOptions } from "@ai-sdk/openai"
3+
4+
test("OpenAI Responses forwards the ultrafast service tier", async () => {
5+
const requests: unknown[] = []
6+
const stop = new Error("request captured")
7+
const provider = createOpenAI({
8+
apiKey: "test-key",
9+
fetch: Object.assign(
10+
async (url: RequestInfo | URL, init?: RequestInit) => {
11+
requests.push(await new Request(url, init).json())
12+
throw stop
13+
},
14+
{ preconnect: () => undefined },
15+
),
16+
})
17+
18+
expect(
19+
await provider
20+
.responses("gpt-6-astra")
21+
.doStream({
22+
prompt: [{ role: "user", content: [{ type: "text", text: "hello" }] }],
23+
providerOptions: {
24+
openai: { serviceTier: "ultrafast" } satisfies OpenAILanguageModelResponsesOptions,
25+
},
26+
})
27+
.then(undefined, (error: unknown) => error),
28+
).toBe(stop)
29+
30+
expect(requests).toHaveLength(1)
31+
expect(requests[0]).toMatchObject({ model: "gpt-6-astra", service_tier: "ultrafast" })
32+
})

‎patches/@ai-sdk%2Fopenai@3.0.88.patch‎

Lines changed: 172 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
1+
diff --git a/dist/index.d.mts b/dist/index.d.mts
2+
index 779b17d7d44b5ee58de033756d1156571b73eb70..4119876028932550c32ed0ed68db8f46bbdef74b 100644
3+
--- a/dist/index.d.mts
4+
+++ b/dist/index.d.mts
5+
@@ -14,7 +14,7 @@ declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<
6+
store?: boolean | undefined;
7+
metadata?: Record<string, string> | undefined;
8+
prediction?: Record<string, any> | undefined;
9+
- serviceTier?: "default" | "auto" | "flex" | "priority" | undefined;
10+
+ serviceTier?: "default" | "auto" | "flex" | "priority" | "ultrafast" | undefined;
11+
strictJsonSchema?: boolean | undefined;
12+
textVerbosity?: "low" | "medium" | "high" | undefined;
13+
promptCacheKey?: string | undefined;
14+
@@ -1089,7 +1089,7 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
15+
reasoningContext?: "auto" | "current_turn" | "all_turns" | undefined;
16+
reasoningSummary?: string | null | undefined;
17+
safetyIdentifier?: string | null | undefined;
18+
- serviceTier?: "default" | "auto" | "flex" | "priority" | null | undefined;
19+
+ serviceTier?: "default" | "auto" | "flex" | "priority" | "ultrafast" | null | undefined;
20+
store?: boolean | null | undefined;
21+
passThroughUnsupportedFiles?: boolean | undefined;
22+
strictJsonSchema?: boolean | null | undefined;
23+
diff --git a/dist/index.d.ts b/dist/index.d.ts
24+
index 779b17d7d44b5ee58de033756d1156571b73eb70..4119876028932550c32ed0ed68db8f46bbdef74b 100644
25+
--- a/dist/index.d.ts
26+
+++ b/dist/index.d.ts
27+
@@ -14,7 +14,7 @@ declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<
28+
store?: boolean | undefined;
29+
metadata?: Record<string, string> | undefined;
30+
prediction?: Record<string, any> | undefined;
31+
- serviceTier?: "default" | "auto" | "flex" | "priority" | undefined;
32+
+ serviceTier?: "default" | "auto" | "flex" | "priority" | "ultrafast" | undefined;
33+
strictJsonSchema?: boolean | undefined;
34+
textVerbosity?: "low" | "medium" | "high" | undefined;
35+
promptCacheKey?: string | undefined;
36+
@@ -1089,7 +1089,7 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
37+
reasoningContext?: "auto" | "current_turn" | "all_turns" | undefined;
38+
reasoningSummary?: string | null | undefined;
39+
safetyIdentifier?: string | null | undefined;
40+
- serviceTier?: "default" | "auto" | "flex" | "priority" | null | undefined;
41+
+ serviceTier?: "default" | "auto" | "flex" | "priority" | "ultrafast" | null | undefined;
42+
store?: boolean | null | undefined;
43+
passThroughUnsupportedFiles?: boolean | undefined;
44+
strictJsonSchema?: boolean | null | undefined;
145
diff --git a/dist/index.js b/dist/index.js
2-
index 5fc82d7ca0f5fba1da3b24c15bb714f51b5aa178..e1a3e2c97774af3a5688c7052bd9a07d692fcc8f 100644
46+
index 5fc82d7ca0f5fba1da3b24c15bb714f51b5aa178..16aa13f852706e88ae1e80617e6b22f1919584ef 100644
347
--- a/dist/index.js
448
+++ b/dist/index.js
49+
@@ -743,7 +743,7 @@ var openaiLanguageModelChatOptions = (0, import_provider_utils4.lazySchema)(
50+
*
51+
* @default 'auto'
52+
*/
53+
- serviceTier: import_v43.z.enum(["auto", "flex", "priority", "default"]).optional(),
54+
+ serviceTier: import_v43.z.enum(["auto", "flex", "priority", "ultrafast", "default"]).optional(),
55+
/**
56+
* Whether to use strict JSON schema validation.
57+
*
558
@@ -1035,22 +1035,6 @@ var OpenAIChatLanguageModel = class {
659
});
760
}
@@ -25,6 +78,15 @@ index 5fc82d7ca0f5fba1da3b24c15bb714f51b5aa178..e1a3e2c97774af3a5688c7052bd9a07d
2578
const {
2679
tools: openaiTools2,
2780
toolChoice: openaiToolChoice,
81+
@@ -4798,7 +4782,7 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils28.lazy
82+
*
83+
* Defaults to 'auto'.
84+
*/
85+
- serviceTier: import_v423.z.enum(["auto", "flex", "priority", "default"]).nullish(),
86+
+ serviceTier: import_v423.z.enum(["auto", "flex", "priority", "ultrafast", "default"]).nullish(),
87+
/**
88+
* Whether to store the generation. Defaults to `true`.
89+
*/
2890
@@ -5454,22 +5438,6 @@ var OpenAIResponsesLanguageModel = class {
2991
});
3092
}
@@ -49,9 +111,18 @@ index 5fc82d7ca0f5fba1da3b24c15bb714f51b5aa178..e1a3e2c97774af3a5688c7052bd9a07d
49111
(tool) => tool.type === "provider" && tool.id === "openai.shell"
50112
)) == null ? void 0 : _i.args) == null ? void 0 : _j.environment) == null ? void 0 : _k.type;
51113
diff --git a/dist/index.mjs b/dist/index.mjs
52-
index 589c4f76955bee692b8af36ea1d9a15121695d4a..6838ea0a362c8fe774527bb1126b8031ebfd3fab 100644
114+
index 589c4f76955bee692b8af36ea1d9a15121695d4a..7c471df4d4c01e0fd4a68b6a0774b07263443e37 100644
53115
--- a/dist/index.mjs
54116
+++ b/dist/index.mjs
117+
@@ -737,7 +737,7 @@ var openaiLanguageModelChatOptions = lazySchema2(
118+
*
119+
* @default 'auto'
120+
*/
121+
- serviceTier: z3.enum(["auto", "flex", "priority", "default"]).optional(),
122+
+ serviceTier: z3.enum(["auto", "flex", "priority", "ultrafast", "default"]).optional(),
123+
/**
124+
* Whether to use strict JSON schema validation.
125+
*
55126
@@ -1031,22 +1031,6 @@ var OpenAIChatLanguageModel = class {
56127
});
57128
}
@@ -75,6 +146,15 @@ index 589c4f76955bee692b8af36ea1d9a15121695d4a..6838ea0a362c8fe774527bb1126b8031
75146
const {
76147
tools: openaiTools2,
77148
toolChoice: openaiToolChoice,
149+
@@ -4899,7 +4883,7 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema21(
150+
*
151+
* Defaults to 'auto'.
152+
*/
153+
- serviceTier: z23.enum(["auto", "flex", "priority", "default"]).nullish(),
154+
+ serviceTier: z23.enum(["auto", "flex", "priority", "ultrafast", "default"]).nullish(),
155+
/**
156+
* Whether to store the generation. Defaults to `true`.
157+
*/
78158
@@ -5557,22 +5541,6 @@ var OpenAIResponsesLanguageModel = class {
79159
});
80160
}
@@ -98,10 +178,45 @@ index 589c4f76955bee692b8af36ea1d9a15121695d4a..6838ea0a362c8fe774527bb1126b8031
98178
const shellToolEnvType = (_k = (_j = (_i = tools == null ? void 0 : tools.find(
99179
(tool) => tool.type === "provider" && tool.id === "openai.shell"
100180
)) == null ? void 0 : _i.args) == null ? void 0 : _j.environment) == null ? void 0 : _k.type;
181+
diff --git a/dist/internal/index.d.mts b/dist/internal/index.d.mts
182+
index 07fcd092f1ffdbecc13557a05e851ab6756a19da..cdd551dd47a45e44694aa8eb8a18e99afa130979 100644
183+
--- a/dist/internal/index.d.mts
184+
+++ b/dist/internal/index.d.mts
185+
@@ -13,7 +13,7 @@ declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<
186+
store?: boolean | undefined;
187+
metadata?: Record<string, string> | undefined;
188+
prediction?: Record<string, any> | undefined;
189+
- serviceTier?: "default" | "auto" | "flex" | "priority" | undefined;
190+
+ serviceTier?: "default" | "auto" | "flex" | "priority" | "ultrafast" | undefined;
191+
strictJsonSchema?: boolean | undefined;
192+
textVerbosity?: "low" | "medium" | "high" | undefined;
193+
promptCacheKey?: string | undefined;
194+
diff --git a/dist/internal/index.d.ts b/dist/internal/index.d.ts
195+
index 07fcd092f1ffdbecc13557a05e851ab6756a19da..cdd551dd47a45e44694aa8eb8a18e99afa130979 100644
196+
--- a/dist/internal/index.d.ts
197+
+++ b/dist/internal/index.d.ts
198+
@@ -13,7 +13,7 @@ declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<
199+
store?: boolean | undefined;
200+
metadata?: Record<string, string> | undefined;
201+
prediction?: Record<string, any> | undefined;
202+
- serviceTier?: "default" | "auto" | "flex" | "priority" | undefined;
203+
+ serviceTier?: "default" | "auto" | "flex" | "priority" | "ultrafast" | undefined;
204+
strictJsonSchema?: boolean | undefined;
205+
textVerbosity?: "low" | "medium" | "high" | undefined;
206+
promptCacheKey?: string | undefined;
101207
diff --git a/dist/internal/index.js b/dist/internal/index.js
102-
index ad78b5df9359509091f4b8a1751dc34c03c74e32..ed92f56d8fe9c1442f741ef8d42d592ce9b28643 100644
208+
index ad78b5df9359509091f4b8a1751dc34c03c74e32..47fd0fd7be7200fa7683d24e6b2c806d6d07ed68 100644
103209
--- a/dist/internal/index.js
104210
+++ b/dist/internal/index.js
211+
@@ -778,7 +778,7 @@ var openaiLanguageModelChatOptions = (0, import_provider_utils4.lazySchema)(
212+
*
213+
* @default 'auto'
214+
*/
215+
- serviceTier: import_v43.z.enum(["auto", "flex", "priority", "default"]).optional(),
216+
+ serviceTier: import_v43.z.enum(["auto", "flex", "priority", "ultrafast", "default"]).optional(),
217+
/**
218+
* Whether to use strict JSON schema validation.
219+
*
105220
@@ -1070,22 +1070,6 @@ var OpenAIChatLanguageModel = class {
106221
});
107222
}
@@ -125,6 +240,15 @@ index ad78b5df9359509091f4b8a1751dc34c03c74e32..ed92f56d8fe9c1442f741ef8d42d592c
125240
const {
126241
tools: openaiTools,
127242
toolChoice: openaiToolChoice,
243+
@@ -4747,7 +4731,7 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils26.lazy
244+
*
245+
* Defaults to 'auto'.
246+
*/
247+
- serviceTier: import_v419.z.enum(["auto", "flex", "priority", "default"]).nullish(),
248+
+ serviceTier: import_v419.z.enum(["auto", "flex", "priority", "ultrafast", "default"]).nullish(),
249+
/**
250+
* Whether to store the generation. Defaults to `true`.
251+
*/
128252
@@ -5724,22 +5708,6 @@ var OpenAIResponsesLanguageModel = class {
129253
});
130254
}
@@ -149,9 +273,18 @@ index ad78b5df9359509091f4b8a1751dc34c03c74e32..ed92f56d8fe9c1442f741ef8d42d592c
149273
(tool) => tool.type === "provider" && tool.id === "openai.shell"
150274
)) == null ? void 0 : _i.args) == null ? void 0 : _j.environment) == null ? void 0 : _k.type;
151275
diff --git a/dist/internal/index.mjs b/dist/internal/index.mjs
152-
index db7d6741c9ea615d577ea07722b469c144066268..f6b41b2832d2c8392072e0ecc1612e9e18b1b48e 100644
276+
index db7d6741c9ea615d577ea07722b469c144066268..877f6e24381c0333e7b8575b834bb2c7de32c28f 100644
153277
--- a/dist/internal/index.mjs
154278
+++ b/dist/internal/index.mjs
279+
@@ -729,7 +729,7 @@ var openaiLanguageModelChatOptions = lazySchema2(
280+
*
281+
* @default 'auto'
282+
*/
283+
- serviceTier: z3.enum(["auto", "flex", "priority", "default"]).optional(),
284+
+ serviceTier: z3.enum(["auto", "flex", "priority", "ultrafast", "default"]).optional(),
285+
/**
286+
* Whether to use strict JSON schema validation.
287+
*
155288
@@ -1023,22 +1023,6 @@ var OpenAIChatLanguageModel = class {
156289
});
157290
}
@@ -175,6 +308,15 @@ index db7d6741c9ea615d577ea07722b469c144066268..f6b41b2832d2c8392072e0ecc1612e9e
175308
const {
176309
tools: openaiTools,
177310
toolChoice: openaiToolChoice,
311+
@@ -4795,7 +4779,7 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema17(
312+
*
313+
* Defaults to 'auto'.
314+
*/
315+
- serviceTier: z19.enum(["auto", "flex", "priority", "default"]).nullish(),
316+
+ serviceTier: z19.enum(["auto", "flex", "priority", "ultrafast", "default"]).nullish(),
317+
/**
318+
* Whether to store the generation. Defaults to `true`.
319+
*/
178320
@@ -5802,22 +5786,6 @@ var OpenAIResponsesLanguageModel = class {
179321
});
180322
}
@@ -237,6 +379,19 @@ index 009a58deea236c2be03adc5cd03f98ed9050fd7b..a606675d82fc72a0bab8d52ac9986610
237379
const {
238380
tools: openaiTools,
239381
toolChoice: openaiToolChoice,
382+
diff --git a/src/chat/openai-chat-options.ts b/src/chat/openai-chat-options.ts
383+
index 8203350fc89d3d26f055b1391665e4757e8d48ac..7027cf28d4841dfcc72f08bce1f70027378765f2 100644
384+
--- a/src/chat/openai-chat-options.ts
385+
+++ b/src/chat/openai-chat-options.ts
386+
@@ -142,7 +142,7 @@ export const openaiLanguageModelChatOptions = lazySchema(() =>
387+
*
388+
* @default 'auto'
389+
*/
390+
- serviceTier: z.enum(['auto', 'flex', 'priority', 'default']).optional(),
391+
+ serviceTier: z.enum(['auto', 'flex', 'priority', 'ultrafast', 'default']).optional(),
392+
393+
/**
394+
* Whether to use strict JSON schema validation.
240395
diff --git a/src/responses/openai-responses-language-model.ts b/src/responses/openai-responses-language-model.ts
241396
index 926e7ec713480353b969901f19c5d1d8cc883dab..ed457ce8f07a60ed48c47a3cbf11b2a7c6cf6415 100644
242397
--- a/src/responses/openai-responses-language-model.ts
@@ -278,3 +433,16 @@ index 926e7ec713480353b969901f19c5d1d8cc883dab..ed457ce8f07a60ed48c47a3cbf11b2a7
278433
const shellToolEnvType = (
279434
tools?.find(
280435
tool => tool.type === 'provider' && tool.id === 'openai.shell',
436+
diff --git a/src/responses/openai-responses-options.ts b/src/responses/openai-responses-options.ts
437+
index 2fec2c4cc8a2236daa8e3a9807c79a983c49d273..c895ea8d546cb7260c0ecfa62c8be94df0716786 100644
438+
--- a/src/responses/openai-responses-options.ts
439+
+++ b/src/responses/openai-responses-options.ts
440+
@@ -296,7 +296,7 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
441+
*
442+
* Defaults to 'auto'.
443+
*/
444+
- serviceTier: z.enum(['auto', 'flex', 'priority', 'default']).nullish(),
445+
+ serviceTier: z.enum(['auto', 'flex', 'priority', 'ultrafast', 'default']).nullish(),
446+
447+
/**
448+
* Whether to store the generation. Defaults to `true`.

0 commit comments

Comments
 (0)