Skip to content

Commit f5ea46a

Browse files
committed
fix: properly parse models for openai
1 parent 80c32be commit f5ea46a

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎src/domain/models/models-dev.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const PROXY_API_KEY_ENV = "KLEIS_API_KEY";
3030
const MODELS_DEV_URL = "https://models.dev/api.json";
3131
const MODELS_DEV_CACHE_TTL_MS = 5 * 60 * 1000;
3232
// Match OpenCode's ChatGPT OAuth model gate.
33-
// https://github.com/anomalyco/opencode/blob/4a57013cf8cb163f58638273fd9da8538cd33cb7/packages/opencode/src/plugin/openai/codex.ts#L276-L315
33+
// https://github.com/anomalyco/opencode/blob/337fd144d2ba144743368f78d9579a99cce175bd/packages/opencode/src/plugin/openai/codex.ts#L286-L310
3434
const CODEX_ALLOWED_OPENAI_MODEL_IDS = new Set([
3535
"gpt-5.3-codex-spark",
3636
"gpt-5.4",
3737
"gpt-5.4-mini",
3838
"gpt-5.5",
3939
]);
4040
const CODEX_DISALLOWED_OPENAI_MODEL_IDS = new Set(["gpt-5.5-pro", "gpt-5.6"]);
41-
const CODEX_DYNAMIC_GPT_VERSION_THRESHOLD = 5.4;
41+
const CODEX_DYNAMIC_GPT_VERSION_THRESHOLD = { major: 5, minor: 4 };
4242

4343
// ChatGPT Codex limits are smaller than the public API limits. Match OpenCode
4444
// OAuth metadata so clients compact before the backend runs out of output room:
@@ -182,11 +182,21 @@ const isModelSupportedByProxyProvider = (
182182
return false;
183183
}
184184

185-
const gptVersion = normalizedModelId.match(/^gpt-(\d+\.\d+)/u)?.[1];
185+
if (CODEX_ALLOWED_OPENAI_MODEL_IDS.has(normalizedModelId)) {
186+
return true;
187+
}
188+
189+
const gptVersion = normalizedModelId.match(/^gpt-(\d+)(?:\.(\d+))?/u);
190+
if (!gptVersion) {
191+
return false;
192+
}
193+
194+
const major = Number(gptVersion[1]);
195+
const minor = Number(gptVersion[2] ?? 0);
186196
return (
187-
CODEX_ALLOWED_OPENAI_MODEL_IDS.has(normalizedModelId) ||
188-
(gptVersion !== undefined &&
189-
Number.parseFloat(gptVersion) > CODEX_DYNAMIC_GPT_VERSION_THRESHOLD)
197+
major > CODEX_DYNAMIC_GPT_VERSION_THRESHOLD.major ||
198+
(major === CODEX_DYNAMIC_GPT_VERSION_THRESHOLD.major &&
199+
minor > CODEX_DYNAMIC_GPT_VERSION_THRESHOLD.minor)
190200
);
191201
};
192202

‎tests/domain/models-dev-contract.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ const upstreamRegistry = {
6161
npm: "@ai-sdk/openai",
6262
},
6363
},
64+
"gpt-6-astra": {
65+
id: "gpt-6-astra",
66+
name: "GPT-6 Astra",
67+
provider: {
68+
api: "https://api.openai.com/v1",
69+
npm: "@ai-sdk/openai",
70+
},
71+
},
6472
"gpt-5": {
6573
id: "gpt-5",
6674
name: "GPT-5",
@@ -181,6 +189,7 @@ describe("models registry contract", () => {
181189
expect(kleis.models?.["gpt-5.5-pro"]).toBeUndefined();
182190
expect(kleis.models?.["gpt-5.6"]).toBeUndefined();
183191
expect(kleis.models?.["gpt-5.6-luna"]?.id).toBe("gpt-5.6-luna");
192+
expect(kleis.models?.["gpt-6-astra"]?.id).toBe("gpt-6-astra");
184193
expect(kleis.models?.["openai/gpt-5.3-codex"]).toBeUndefined();
185194
expect(kleis.models?.["github-copilot/gpt-5"]?.id).toBe(
186195
"github-copilot/gpt-5"
@@ -297,7 +306,7 @@ describe("models registry contract", () => {
297306
models?: Record<string, { id?: string }>;
298307
};
299308
expect(openai.env).toEqual(["OPENAI_API_KEY"]);
300-
expect(Object.keys(openai.models ?? {})).toHaveLength(8);
309+
expect(Object.keys(openai.models ?? {})).toHaveLength(9);
301310

302311
const kleis = registry.kleis as {
303312
models?: Record<string, { id?: string }>;
@@ -322,7 +331,7 @@ describe("models registry contract", () => {
322331
models?: Record<string, unknown>;
323332
};
324333
expect(openai.env).toEqual(["OPENAI_API_KEY"]);
325-
expect(Object.keys(openai.models ?? {})).toHaveLength(8);
334+
expect(Object.keys(openai.models ?? {})).toHaveLength(9);
326335

327336
expect(registry.anthropic).toBeDefined();
328337
expect(registry["github-copilot"]).toBeDefined();
@@ -366,6 +375,7 @@ describe("models registry contract", () => {
366375
"gpt-5.5-pro",
367376
"gpt-5.6",
368377
"gpt-5.6-luna",
378+
"gpt-6-astra",
369379
"gpt-5",
370380
"text-embedding-3-large",
371381
]);
@@ -422,6 +432,7 @@ describe("models registry contract", () => {
422432
"gpt-5.3-codex-spark",
423433
"gpt-5.5",
424434
"gpt-5.6-luna",
435+
"gpt-6-astra",
425436
]);
426437
});
427438

0 commit comments

Comments
 (0)