Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions packages/proxy/src/providers/openai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,41 +431,47 @@ describe("request/response checking", () => {
]);
});

it("should convert minimal to low reasoning_effort for gpt-5.1 models", async () => {
it("should convert minimal to low reasoning_effort for gpt-5.x-codex models", async () => {
const calls: InterceptedCall[] = [];
server.use(
http.post(
"https://api.openai.com/v1/chat/completions",
"https://api.openai.com/v1/responses",
async ({ request: req }) => {
const request: InterceptedRequest = {
method: req.method,
url: req.url,
body: await req.json(),
};

// Mock a successful response
// Mock a successful responses API response
const response: InterceptedResponse = {
status: 200,
body: {
id: "chatcmpl-test",
object: "chat.completion",
created: 1234567890,
model: "gpt-5.1",
choices: [
id: "resp-test",
object: "response",
created_at: 1234567890,
model: "gpt-5.1-codex",
output: [
{
index: 0,
message: {
role: "assistant",
content: "Test response",
refusal: null,
},
finish_reason: "stop",
type: "message",
content: [
{
type: "output_text",
text: "Test response",
},
],
},
],
usage: {
prompt_tokens: 10,
completion_tokens: 5,
input_tokens: 10,
output_tokens: 5,
total_tokens: 15,
input_tokens_details: {
cached_tokens: 0,
},
output_tokens_details: {
reasoning_tokens: 0,
},
},
},
};
Expand All @@ -481,7 +487,7 @@ describe("request/response checking", () => {

await callProxyV1<OpenAIChatCompletionCreateParams, OpenAIChatCompletion>({
body: {
model: "gpt-5.1",
model: "gpt-5.1-codex",
reasoning_effort: "minimal",
stream: false,
messages: [
Expand All @@ -497,9 +503,12 @@ describe("request/response checking", () => {
});

expect(calls.length).toBe(1);
// gpt-5.x-codex models are routed to Responses API, which uses reasoning.effort instead of reasoning_effort
expect(calls[0].request.body).toMatchObject({
model: "gpt-5.1",
reasoning_effort: "low", // minimal should be converted to low for gpt-5.1
model: "gpt-5.1-codex",
reasoning: {
effort: "low", // minimal should be converted to low for gpt-5.x-codex
},
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/proxy/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,8 @@ async function fetchOpenAI(
bodyData?.model?.startsWith("o1-pro") ||
bodyData?.model?.startsWith("o3-pro") ||
bodyData?.model?.startsWith("gpt-5-pro") ||
bodyData?.model?.startsWith("gpt-5-codex")
(bodyData?.model?.startsWith("gpt-5") &&
bodyData?.model?.includes("-codex"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very tiny nit, i would probably test that it starts with "gpt" and ends with "codex" to be safe. but i dont think it matters.

) {
return fetchOpenAIResponsesTranslate({
headers,
Expand Down