Skip to content

Commit e46929b

Browse files
committed
fix: map gpt-5-codex model to gpt-5-2025-08-07 for API compatibility
- Added model ID mapping in getModel() method to convert gpt-5-codex to gpt-5-2025-08-07 - Added test cases to verify gpt-5-codex model mapping works correctly - Ensures tool invocation and code editing work properly with gpt-5-codex model Fixes #8273
1 parent 8dbd8c4 commit e46929b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

src/api/providers/__tests__/openai-native.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,72 @@ describe("OpenAiNativeHandler", () => {
208208
})
209209

210210
describe("GPT-5 models", () => {
211+
it("should map gpt-5-codex to gpt-5-2025-08-07", () => {
212+
const handler = new OpenAiNativeHandler({
213+
...mockOptions,
214+
apiModelId: "gpt-5-codex",
215+
})
216+
217+
const model = handler.getModel()
218+
// Verify that gpt-5-codex is mapped to gpt-5-2025-08-07
219+
expect(model.id).toBe("gpt-5-2025-08-07")
220+
// Verify it has the correct model info from gpt-5-codex
221+
expect(model.info.description).toBe("GPT-5-Codex: A version of GPT-5 optimized for agentic coding in Codex")
222+
expect(model.info.supportsVerbosity).toBe(true)
223+
expect(model.info.supportsTemperature).toBe(false)
224+
})
225+
226+
it("should handle gpt-5-codex streaming with Responses API", async () => {
227+
// Mock fetch for Responses API
228+
const mockFetch = vitest.fn().mockResolvedValue({
229+
ok: true,
230+
body: new ReadableStream({
231+
start(controller) {
232+
controller.enqueue(
233+
new TextEncoder().encode(
234+
'data: {"type":"response.output_item.added","item":{"type":"text","text":"Codex response"}}\n\n',
235+
),
236+
)
237+
controller.enqueue(
238+
new TextEncoder().encode(
239+
'data: {"type":"response.done","response":{"usage":{"prompt_tokens":10,"completion_tokens":2}}}\n\n',
240+
),
241+
)
242+
controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"))
243+
controller.close()
244+
},
245+
}),
246+
})
247+
global.fetch = mockFetch as any
248+
249+
// Mock SDK to fail so it uses fetch
250+
mockResponsesCreate.mockRejectedValue(new Error("SDK not available"))
251+
252+
handler = new OpenAiNativeHandler({
253+
...mockOptions,
254+
apiModelId: "gpt-5-codex",
255+
})
256+
257+
const stream = handler.createMessage(systemPrompt, messages)
258+
const chunks: any[] = []
259+
for await (const chunk of stream) {
260+
chunks.push(chunk)
261+
}
262+
263+
// Verify the request uses the mapped model ID
264+
expect(mockFetch).toHaveBeenCalledWith(
265+
"https://api.openai.com/v1/responses",
266+
expect.objectContaining({
267+
body: expect.stringContaining('"model":"gpt-5-2025-08-07"'),
268+
}),
269+
)
270+
271+
// Verify the response content
272+
const textChunks = chunks.filter((c) => c.type === "text")
273+
expect(textChunks).toHaveLength(1)
274+
expect(textChunks[0].text).toBe("Codex response")
275+
})
276+
211277
it("should handle GPT-5 model with Responses API", async () => {
212278
// Mock fetch for Responses API
213279
const mockFetch = vitest.fn().mockResolvedValue({

src/api/providers/openai-native.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,16 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
12471247

12481248
// The o3 models are named like "o3-mini-[reasoning-effort]", which are
12491249
// not valid model ids, so we need to strip the suffix.
1250-
return { id: id.startsWith("o3-mini") ? "o3-mini" : id, info, ...params, verbosity: params.verbosity }
1250+
// Similarly, gpt-5-codex needs to be mapped to the base gpt-5 model
1251+
let mappedModelId = id
1252+
if (id.startsWith("o3-mini")) {
1253+
mappedModelId = "o3-mini"
1254+
} else if (id === "gpt-5-codex") {
1255+
// Map gpt-5-codex to the base GPT-5 model for API compatibility
1256+
mappedModelId = "gpt-5-2025-08-07"
1257+
}
1258+
1259+
return { id: mappedModelId, info, ...params, verbosity: params.verbosity }
12511260
}
12521261

12531262
/**

0 commit comments

Comments
 (0)