Skip to content

fix(gateway): reject unsupported responses subpaths for OAuth accounts#1373

Open
shichanglin5 wants to merge 1 commit intoWei-Shaw:mainfrom
shichanglin5:fix/oauth-unsupported-responses-subpath
Open

fix(gateway): reject unsupported responses subpaths for OAuth accounts#1373
shichanglin5 wants to merge 1 commit intoWei-Shaw:mainfrom
shichanglin5:fix/oauth-unsupported-responses-subpath

Conversation

@shichanglin5
Copy link
Copy Markdown

Problem

OAuth accounts route to chatgpt.com/backend-api/codex/responses. Sub-path requests like /v1/responses/input_tokens return 403 from Cloudflare, which the circuit breaker treats as auth failure and disables the entire account.

Triggered by LiteLLM's OpenAITokenCounter calling /v1/responses/input_tokens during Claude Code context compaction (/compact).

Fix

Validate responses API sub-path for OAuth accounts before forwarding:

  • /compact and /compact/* → allowed
  • Any other sub-path → reject immediately (fast 502, no upstream call)

Applied in both buildUpstreamRequestOpenAIPassthrough and buildUpstreamRequest.

Verification

5 consecutive /input_tokens calls → 502 each (~5ms, no upstream hit), account NOT disabled, /v1/responses continues returning 200.

ChatGPT Codex internal API (chatgpt.com/backend-api/codex/responses)
only supports /responses and /responses/compact. When a proxy like
LiteLLM forwards /v1/responses/input_tokens (OpenAI token counting
endpoint) through an OAuth account, the request hits Cloudflare which
returns 403 HTML. The rate limiter misinterprets this as an auth error
and disables the account, causing all subsequent OpenAI requests to
fail with 503 "no available OpenAI accounts".

This fix validates the responses subpath before forwarding: for OAuth
accounts, only /compact is allowed. Other subpaths (e.g. /input_tokens)
are rejected early with a clear error, preventing the Cloudflare 403
from triggering account circuit-breaking.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant