Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: normalize Codex Responses request body for compat with LiteLLM/Anthropic clients #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
srizzo wants to merge 1 commit into EvanZhouDev:main
base: main
Choose a base branch
Loading
from srizzo:fix/codex-responses-request-normalization
Open
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
21 changes: 21 additions & 0 deletions packages/openai-oauth-core/src/transport.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,27 @@ export const normalizeCodexResponsesBody = (
}

delete normalized.max_output_tokens
// Codex backend rejects these params; strip for compatibility with LiteLLM/Anthropic-format clients.
delete normalized.user
delete normalized.temperature
delete normalized.top_p

// LiteLLM translates Anthropic's web_search server tool to OpenAI's public name
// (web_search_preview). The Codex backend uses the internal name (web_search) and
// requires external_web_access:true to perform live searches (default is cached mode).
let renamedWebSearch = false
if (Array.isArray(normalized.tools)) {
normalized.tools = (normalized.tools as unknown[]).map((t) => {
if (t && typeof t === "object" && (t as Record<string, unknown>).type === "web_search_preview") {
renamedWebSearch = true
return { ...(t as Record<string, unknown>), type: "web_search", external_web_access: true }
}
return t
})
}
if (renamedWebSearch && normalized.tool_choice && normalized.tool_choice !== "none") {
normalized.tool_choice = "auto"
}

return normalized
}
Expand Down
79 changes: 79 additions & 0 deletions packages/openai-oauth-core/test/transport.test.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,85 @@ describe("normalizeCodexResponsesBody", () => {

expect(normalized.store).toBe(false)
})

test("strips params the Codex backend rejects", () => {
const normalized = normalizeCodexResponsesBody({
model: "gpt-5.3-codex-spark",
user: "user-123",
temperature: 0.2,
top_p: 0.9,
})

expect(normalized).not.toHaveProperty("user")
expect(normalized).not.toHaveProperty("temperature")
expect(normalized).not.toHaveProperty("top_p")
})

test("renames web_search_preview to web_search with external_web_access", () => {
const normalized = normalizeCodexResponsesBody({
model: "gpt-5.4",
tools: [
{ type: "web_search_preview" },
{ type: "function", name: "other", parameters: {} },
],
})

expect(normalized.tools).toEqual([
{ type: "web_search", external_web_access: true },
{ type: "function", name: "other", parameters: {} },
])
})

test("resets tool_choice to auto when renaming web_search_preview", () => {
const normalized = normalizeCodexResponsesBody({
model: "gpt-5.4",
tools: [{ type: "web_search_preview" }],
tool_choice: { type: "function", name: "ignored" },
})

expect(normalized.tool_choice).toBe("auto")
})

test("leaves tool_choice 'none' intact even when renaming", () => {
const normalized = normalizeCodexResponsesBody({
model: "gpt-5.4",
tools: [{ type: "web_search_preview" }],
tool_choice: "none",
})

expect(normalized.tool_choice).toBe("none")
})

test("does not touch tool_choice when no web_search_preview tool is present", () => {
const toolChoice = { type: "function", name: "my_tool" }
const normalized = normalizeCodexResponsesBody({
model: "gpt-5.4",
tools: [{ type: "function", name: "my_tool", parameters: {} }],
tool_choice: toolChoice,
})

expect(normalized.tool_choice).toEqual(toolChoice)
})

test("preserves other web search config keys when renaming", () => {
const normalized = normalizeCodexResponsesBody({
model: "gpt-5.4",
tools: [
{
type: "web_search_preview",
search_context_size: "medium",
},
],
})

expect(normalized.tools).toEqual([
{
type: "web_search",
search_context_size: "medium",
external_web_access: true,
},
])
})
})

describe("createCodexOAuthFetch", () => {
Expand Down

AltStyle によって変換されたページ (->オリジナル) /