fix(agent): only auto-upgrade api.openai.com requests to codex_responses for Responses-API model families - #52115
Conversation
…ses for Responses-API model families (NousResearch#52023) A fresh Hermes install on Windows 11 with only the OpenAI API key configured fails with HTTP 400 "Encrypted content is not supported with this model" for any non-GPT-5 model — gpt-4o-mini, gpt-4.1, gpt-4-turbo. GPT-5.x models keep working. Root cause: `init_agent` upgrades any chat-completions request whose `base_url` is `api.openai.com` to the `codex_responses` api_mode. The Codex/Responses transport unconditionally attaches `include` (and, when reasoning is enabled, `reasoning.encrypted_content`) to the request payload. OpenAI's responses endpoint only accepts that payload for GPT-5.x — older models reject with the 400 above. The url-only heuristic can't tell GPT-5 from GPT-4 / GPT-4o, because older and newer families share the same `/v1/chat/completions` endpoint. The model-name check (`_provider_model_requires_responses_api`) already returns the right answer (true for `gpt-5*`, false otherwise); this commit drops the redundant URL OR-branch and lets the model-name check be authoritative. gpt-4o-mini / gpt-4.1 / gpt-4-turbo on direct OpenAI URLs stay on chat completions; gpt-5.x still upgrades; Azure's existing carve-out is unchanged. Refs: NousResearch#52023 This is a pure routing / parametrization fix. No state, no env-reading, no transport-layer edits.
Competing fix cluster for the codex_responses URL-only auto-upgrade misroute (#52023): #23734 (earliest open, removes |
|
One thing I noticed: the |
Summary
The chat-completions → codex-responses auto-upgrade for direct OpenAI API calls (
api.openai.com) was incorrectly triggered by_is_direct_openai_url(base_url)— a URL-only check. This causedgpt-4o-miniandgpt-4-turbo(non-Responses-API models on direct OpenAI) to be routed to the codex endpoint, which doesn't recognize them, producing400: model not founderrors (#52023).The correct condition is the model family itself: only
gpt-5.xand newer Responses-API models get the auto-upgrade. Non-Responses-API models likegpt-4o-mini,gpt-4-turbo,o1, ando3must stay on the standard chat-completions endpoint regardless of the base URL.This PR removes the URL-only OR-branch and replaces it with the model-family check that was already executing for the Azure and Nous paths.
Changes
File:
agent/agent_init.py(+20/-11)_is_direct_openai_url(self.base_url) OR agent._provider_model_requires_responses_api(...)condition._provider_model_requires_responses_api(...)check.File:
tests/run_agent/test_run_agent.py(+49/-10)TestGpt5ApiModeRoutingre-aligned to the simplified decision.test_gpt4o_mini_on_openai_direct_stays_on_chat_completions— gpt-4o-mini must not auto-upgrade to codex on api.openai.comtest_gpt4_1_on_openai_direct_stays_on_chat_completions— gpt-4-turbo must not auto-upgradeHow to Test
Checklist
Risk & Impact
Low. The change is subtractive: it removes an OR-half the model-name check was already evaluating
truefor in every relevant case. The three pre-existing tests cover the routes that behavior has to preserve (Azure,gpt-5.xonapi.openai.com, Nousgpt-5.x); the two new tests directly fail on the bug if it ever regresses.Type: 🐛 Bug fix
Closes: #52023