Skip to content

fix(agent): only auto-upgrade api.openai.com requests to codex_responses for Responses-API model families - #52115

Closed
Kewe63 wants to merge 1 commit into
NousResearch:mainfrom
Kewe63:fix/52023-openai-api-direct-chat-completions
Closed

fix(agent): only auto-upgrade api.openai.com requests to codex_responses for Responses-API model families#52115
Kewe63 wants to merge 1 commit into
NousResearch:mainfrom
Kewe63:fix/52023-openai-api-direct-chat-completions

Conversation

@Kewe63

@Kewe63 Kewe63 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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 caused gpt-4o-mini and gpt-4-turbo (non-Responses-API models on direct OpenAI) to be routed to the codex endpoint, which doesn't recognize them, producing 400: model not found errors (#52023).

The correct condition is the model family itself: only gpt-5.x and newer Responses-API models get the auto-upgrade. Non-Responses-API models like gpt-4o-mini, gpt-4-turbo, o1, and o3 must 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)

  • Dropped the _is_direct_openai_url(self.base_url) OR agent._provider_model_requires_responses_api(...) condition.
  • Simplified to a single _provider_model_requires_responses_api(...) check.
  • Added comment block documenting the regression and the model-family-only invariant.

File: tests/run_agent/test_run_agent.py (+49/-10)


How to Test

# Run the specific routing tests
.venv/bin/python -m pytest tests/run_agent/test_run_agent.py::TestGpt5ApiModeRouting -v
# ✅ 5 existing tests (re-aligned) + 2 new regression tests

# Or via the test suite wrapper
scripts/run_tests.sh tests/run_agent/test_run_agent.py -k "TestGpt5ApiModeRouting"

Checklist

  • Diff scoped — 2 files, +59/-21
  • URL-only OR removed — comment documents why
  • Tests added — 2 new regression tests + 3 existing tests re-aligned
  • No force-push, no destructive commands
  • Follows Conventional Commits
  • Cross-platform impact — pure routing condition in Python, no POSIX-only primitives

Risk & Impact

Low. The change is subtractive: it removes an OR-half the model-name check was already evaluating true for in every relevant case. The three pre-existing tests cover the routes that behavior has to preserve (Azure, gpt-5.x on api.openai.com, Nous gpt-5.x); the two new tests directly fail on the bug if it ever regresses.

Type: 🐛 Bug fix
Closes: #52023

…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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API P2 Medium — degraded but workaround exists labels Jun 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Competing fix cluster for the codex_responses URL-only auto-upgrade misroute (#52023): #23734 (earliest open, removes _is_direct_openai_url entirely) and #23895 (relaxes the custom-provider GPT-5.x guard, #23893). This PR keeps a single model-family check and adds regression tests. Same goal, different code paths — related, not duplicate; flagging the cluster so a maintainer can pick one.

@Morad37

Morad37 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

One thing I noticed: the _is_direct_openai_url() path was the only signal that made the upgrade apply for non-GPT-5 models served through api.openai.com. Dropping it entirely means those models stay on chat completions, which is correct. But the comment says the URL signal is still useful as a "model-family amplification" -- and the code still reads api.openai.com URLs in _is_direct_openai_url(), it just doesn't use it as an independent gate anymore. Might be worth cleaning up the comment to not imply the URL signal is still doing anything functional. It's just explanatory now.

@teknium1 teknium1 closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants