Skip to content

Commit 21e137d

Browse files
committed
refactor: simplify OpenAI service tier implementation
- Extend existing 'tiers' property with optional 'name' field instead of separate allowedServiceTiers and serviceTierPricing - Remove redundant boolean logic (|| false) - Update UI components to use unified tier structure - Maintain backward compatibility and all tests pass - Note: Service tier error handling removal completed in separate task
1 parent 31f5205 commit 21e137d

File tree

5 files changed

+150
-181
lines changed

5 files changed

+150
-181
lines changed

packages/types/src/model.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ export const modelInfoSchema = z.object({
7777
maxCachePoints: z.number().optional(),
7878
cachableFields: z.array(z.string()).optional(),
7979
/**
80-
* Deprecated generic tiers (kept for backward compatibility).
81-
* Prefer serviceTierPricing which is keyed by the OpenAI service tier names.
80+
* Service tiers with pricing information.
81+
* Each tier can have a name (for OpenAI service tiers) and pricing overrides.
82+
* The top-level input/output/cache* fields represent the default/standard tier.
8283
*/
8384
tiers: z
8485
.array(
8586
z.object({
87+
name: serviceTierSchema.optional(), // Service tier name (flex, priority, etc.)
8688
contextWindow: z.number(),
8789
inputPrice: z.number().optional(),
8890
outputPrice: z.number().optional(),
@@ -91,36 +93,6 @@ export const modelInfoSchema = z.object({
9193
}),
9294
)
9395
.optional(),
94-
/**
95-
* Which OpenAI service tiers this model supports beyond the Default tier.
96-
* If undefined or empty, assume only 'default' is available.
97-
*/
98-
allowedServiceTiers: z.array(serviceTierSchema).optional(),
99-
/**
100-
* Pricing overrides per OpenAI service tier. The top-level input/output/cache*
101-
* fields represent the Default (standard) tier. When a tier is selected, use
102-
* these overrides if present.
103-
*/
104-
serviceTierPricing: z
105-
.object({
106-
flex: z
107-
.object({
108-
inputPrice: z.number().optional(),
109-
outputPrice: z.number().optional(),
110-
cacheWritesPrice: z.number().optional(),
111-
cacheReadsPrice: z.number().optional(),
112-
})
113-
.optional(),
114-
priority: z
115-
.object({
116-
inputPrice: z.number().optional(),
117-
outputPrice: z.number().optional(),
118-
cacheWritesPrice: z.number().optional(),
119-
cacheReadsPrice: z.number().optional(),
120-
})
121-
.optional(),
122-
})
123-
.optional(),
12496
})
12597

12698
export type ModelInfo = z.infer<typeof modelInfoSchema>

packages/types/src/provider-settings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ const openAiNativeSchema = apiModelIdProviderModelSchema.extend({
225225
openAiNativeApiKey: z.string().optional(),
226226
openAiNativeBaseUrl: z.string().optional(),
227227
// OpenAI Responses API service tier for openai-native provider only.
228-
// UI should only expose this when the selected model supports flex/priority.
229228
openAiNativeServiceTier: serviceTierSchema.optional(),
230229
})
231230

packages/types/src/providers/openai.ts

Lines changed: 118 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,22 @@ export const openAiNativeModels = {
3232
// supportsVerbosity is a new capability; ensure ModelInfo includes it
3333
supportsVerbosity: true,
3434
supportsTemperature: false,
35-
allowedServiceTiers: ["flex", "priority"],
36-
serviceTierPricing: {
37-
flex: { inputPrice: 0.625, outputPrice: 5.0, cacheReadsPrice: 0.0625 },
38-
priority: { inputPrice: 2.5, outputPrice: 20.0, cacheReadsPrice: 0.25 },
39-
},
35+
tiers: [
36+
{
37+
name: "flex",
38+
contextWindow: 400000,
39+
inputPrice: 0.625,
40+
outputPrice: 5.0,
41+
cacheReadsPrice: 0.0625,
42+
},
43+
{
44+
name: "priority",
45+
contextWindow: 400000,
46+
inputPrice: 2.5,
47+
outputPrice: 20.0,
48+
cacheReadsPrice: 0.25,
49+
},
50+
],
4051
},
4152
"gpt-5-mini-2025-08-07": {
4253
maxTokens: 128000,
@@ -51,11 +62,22 @@ export const openAiNativeModels = {
5162
description: "GPT-5 Mini: A faster, more cost-efficient version of GPT-5 for well-defined tasks",
5263
supportsVerbosity: true,
5364
supportsTemperature: false,
54-
allowedServiceTiers: ["flex", "priority"],
55-
serviceTierPricing: {
56-
flex: { inputPrice: 0.125, outputPrice: 1.0, cacheReadsPrice: 0.0125 },
57-
priority: { inputPrice: 0.45, outputPrice: 3.6, cacheReadsPrice: 0.045 },
58-
},
65+
tiers: [
66+
{
67+
name: "flex",
68+
contextWindow: 400000,
69+
inputPrice: 0.125,
70+
outputPrice: 1.0,
71+
cacheReadsPrice: 0.0125,
72+
},
73+
{
74+
name: "priority",
75+
contextWindow: 400000,
76+
inputPrice: 0.45,
77+
outputPrice: 3.6,
78+
cacheReadsPrice: 0.045,
79+
},
80+
],
5981
},
6082
"gpt-5-nano-2025-08-07": {
6183
maxTokens: 128000,
@@ -70,10 +92,15 @@ export const openAiNativeModels = {
7092
description: "GPT-5 Nano: Fastest, most cost-efficient version of GPT-5",
7193
supportsVerbosity: true,
7294
supportsTemperature: false,
73-
allowedServiceTiers: ["flex"],
74-
serviceTierPricing: {
75-
flex: { inputPrice: 0.025, outputPrice: 0.2, cacheReadsPrice: 0.0025 },
76-
},
95+
tiers: [
96+
{
97+
name: "flex",
98+
contextWindow: 400000,
99+
inputPrice: 0.025,
100+
outputPrice: 0.2,
101+
cacheReadsPrice: 0.0025,
102+
},
103+
],
77104
},
78105
"gpt-4.1": {
79106
maxTokens: 32_768,
@@ -84,10 +111,15 @@ export const openAiNativeModels = {
84111
outputPrice: 8,
85112
cacheReadsPrice: 0.5,
86113
supportsTemperature: true,
87-
allowedServiceTiers: ["priority"],
88-
serviceTierPricing: {
89-
priority: { inputPrice: 3.5, outputPrice: 14.0, cacheReadsPrice: 0.875 },
90-
},
114+
tiers: [
115+
{
116+
name: "priority",
117+
contextWindow: 1_047_576,
118+
inputPrice: 3.5,
119+
outputPrice: 14.0,
120+
cacheReadsPrice: 0.875,
121+
},
122+
],
91123
},
92124
"gpt-4.1-mini": {
93125
maxTokens: 32_768,
@@ -98,10 +130,15 @@ export const openAiNativeModels = {
98130
outputPrice: 1.6,
99131
cacheReadsPrice: 0.1,
100132
supportsTemperature: true,
101-
allowedServiceTiers: ["priority"],
102-
serviceTierPricing: {
103-
priority: { inputPrice: 0.7, outputPrice: 2.8, cacheReadsPrice: 0.175 },
104-
},
133+
tiers: [
134+
{
135+
name: "priority",
136+
contextWindow: 1_047_576,
137+
inputPrice: 0.7,
138+
outputPrice: 2.8,
139+
cacheReadsPrice: 0.175,
140+
},
141+
],
105142
},
106143
"gpt-4.1-nano": {
107144
maxTokens: 32_768,
@@ -112,10 +149,15 @@ export const openAiNativeModels = {
112149
outputPrice: 0.4,
113150
cacheReadsPrice: 0.025,
114151
supportsTemperature: true,
115-
allowedServiceTiers: ["priority"],
116-
serviceTierPricing: {
117-
priority: { inputPrice: 0.2, outputPrice: 0.8, cacheReadsPrice: 0.05 },
118-
},
152+
tiers: [
153+
{
154+
name: "priority",
155+
contextWindow: 1_047_576,
156+
inputPrice: 0.2,
157+
outputPrice: 0.8,
158+
cacheReadsPrice: 0.05,
159+
},
160+
],
119161
},
120162
o3: {
121163
maxTokens: 100_000,
@@ -128,11 +170,22 @@ export const openAiNativeModels = {
128170
supportsReasoningEffort: true,
129171
reasoningEffort: "medium",
130172
supportsTemperature: false,
131-
allowedServiceTiers: ["flex", "priority"],
132-
serviceTierPricing: {
133-
flex: { inputPrice: 1.0, outputPrice: 4.0, cacheReadsPrice: 0.25 },
134-
priority: { inputPrice: 3.5, outputPrice: 14.0, cacheReadsPrice: 0.875 },
135-
},
173+
tiers: [
174+
{
175+
name: "flex",
176+
contextWindow: 200_000,
177+
inputPrice: 1.0,
178+
outputPrice: 4.0,
179+
cacheReadsPrice: 0.25,
180+
},
181+
{
182+
name: "priority",
183+
contextWindow: 200_000,
184+
inputPrice: 3.5,
185+
outputPrice: 14.0,
186+
cacheReadsPrice: 0.875,
187+
},
188+
],
136189
},
137190
"o3-high": {
138191
maxTokens: 100_000,
@@ -167,11 +220,22 @@ export const openAiNativeModels = {
167220
supportsReasoningEffort: true,
168221
reasoningEffort: "medium",
169222
supportsTemperature: false,
170-
allowedServiceTiers: ["flex", "priority"],
171-
serviceTierPricing: {
172-
flex: { inputPrice: 0.55, outputPrice: 2.2, cacheReadsPrice: 0.138 },
173-
priority: { inputPrice: 2.0, outputPrice: 8.0, cacheReadsPrice: 0.5 },
174-
},
223+
tiers: [
224+
{
225+
name: "flex",
226+
contextWindow: 200_000,
227+
inputPrice: 0.55,
228+
outputPrice: 2.2,
229+
cacheReadsPrice: 0.138,
230+
},
231+
{
232+
name: "priority",
233+
contextWindow: 200_000,
234+
inputPrice: 2.0,
235+
outputPrice: 8.0,
236+
cacheReadsPrice: 0.5,
237+
},
238+
],
175239
},
176240
"o4-mini-high": {
177241
maxTokens: 100_000,
@@ -268,10 +332,15 @@ export const openAiNativeModels = {
268332
outputPrice: 10,
269333
cacheReadsPrice: 1.25,
270334
supportsTemperature: true,
271-
allowedServiceTiers: ["priority"],
272-
serviceTierPricing: {
273-
priority: { inputPrice: 4.25, outputPrice: 17.0, cacheReadsPrice: 2.125 },
274-
},
335+
tiers: [
336+
{
337+
name: "priority",
338+
contextWindow: 128_000,
339+
inputPrice: 4.25,
340+
outputPrice: 17.0,
341+
cacheReadsPrice: 2.125,
342+
},
343+
],
275344
},
276345
"gpt-4o-mini": {
277346
maxTokens: 16_384,
@@ -282,10 +351,15 @@ export const openAiNativeModels = {
282351
outputPrice: 0.6,
283352
cacheReadsPrice: 0.075,
284353
supportsTemperature: true,
285-
allowedServiceTiers: ["priority"],
286-
serviceTierPricing: {
287-
priority: { inputPrice: 0.25, outputPrice: 1.0, cacheReadsPrice: 0.125 },
288-
},
354+
tiers: [
355+
{
356+
name: "priority",
357+
contextWindow: 128_000,
358+
inputPrice: 0.25,
359+
outputPrice: 1.0,
360+
cacheReadsPrice: 0.125,
361+
},
362+
],
289363
},
290364
"codex-mini-latest": {
291365
maxTokens: 16_384,

0 commit comments

Comments
 (0)