-
Notifications
You must be signed in to change notification settings - Fork 72
fix: normalize Codex Responses request body for compat with LiteLLM/Anthropic clients#7
Open
srizzo wants to merge 1 commit into
Open
Conversation
...nthropic clients The Codex `/v1/responses` backend differs from the public OpenAI Responses API in two ways that matter for clients forwarding through openai-oauth: 1. Codex reasoning models reject `user`, `temperature`, and `top_p`. LiteLLM's Anthropic-Messages adapter forwards `temperature` by default (Claude Code sets it on every request), so every call errors out with "The feature 'temperature' is not supported. temperature is not supported for reasoning models" before the backend even starts generating. Strip these three params in `normalizeCodexResponsesBody`. 2. Codex uses the internal name `web_search` for the OpenAI WebSearch server tool (the public name is `web_search_preview`). It also defaults to cached-only mode and requires `external_web_access: true` to perform live searches; without it the tool accepts the call but returns cached results, causing models to hallucinate plausible but wrong results. When a `web_search_preview` tool is present in the request, rename it to `web_search`, inject `external_web_access: true`, and reset any function-pointing `tool_choice` to `"auto"` so it does not become stale after the rename (Codex returns "Tool choice 'function' not found in 'tools' parameter" otherwise). `tool_choice: "none"` is preserved intact. Neither change affects requests that do not carry the offending params or tools. Tests cover stripping, renaming, tool_choice handling in both the rename and no-rename paths, and preservation of sibling keys on the web_search tool config.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Codex
/v1/responsesbackend differs from the public OpenAI Responses API in two ways that matter for clients forwarding through openai-oauth (LiteLLM → Anthropic-format, Cursor, etc.):Codex reasoning models reject
user/temperature/top_p. LiteLLM's Anthropic-Messages adapter forwardstemperatureby default (Claude Code sets it on every request), so every call errors out with:before the backend even starts generating.
Codex uses the internal tool name
web_searchfor what OpenAI publicly callsweb_search_preview. It also defaults to cached-only mode and requiresexternal_web_access: truefor live searches. Without those two adjustments the tool is accepted but runs in cached mode, so the model returns plausible-looking but hallucinated results.Additionally, when
web_search_previewis renamed, a caller-suppliedtool_choicethat points at a specific function becomes stale (Codex returnsTool choice 'function' not found in 'tools' parameter). Reset it to\"auto\"in that case;\"none\"is preserved intact.What changes
normalizeCodexResponsesBodyinpackages/openai-oauth-core/src/transport.ts:delete normalized.userdelete normalized.temperaturedelete normalized.top_ptools[*].type === \"web_search_preview\"→{ type: \"web_search\", external_web_access: true, ...rest }tool_choice !== \"none\", set it to\"auto\"packages/openai-oauth-core/test/transport.test.tscovering stripping, renaming, tool_choice handling in both the rename and no-rename paths, and preservation of sibling keys (e.g.search_context_size) on the web_search tool config.None of these changes affect requests that don't carry the offending params or tools.
Related
function_call_argumentsevents for codex-spark). Together they make the Responses API round-trip via LiteLLM usable for Anthropic-format clients with tool calls and WebSearch.Test plan
bun run test— all tests pass (+6 new)bun run test