Skip to content

[Bug]: Uncoded "exceeds the context window" errors from a Responses route reach Claude Code as a retryable 502 instead of "prompt is too long" #8127

Closed

Description

@gitrvc-hub

Client or integration

Claude Code

Area

Proxy and routing

Summary

A Claude Code session on a Messages → Responses translated route keeps running past the model's context window instead of compacting.

When the upstream rejects an oversized input, the error says Your input exceeds the context window of this model but has no context_length_exceeded code. opencodex only treats a refusal as an overflow when that code is present, so this one falls through to the generic upstream-failure mapping and reaches Claude Code as a 502. Claude Code sees a 502 as a temporary server error, so it retries instead of compacting. If the response were a 400 with prompt is too long, Claude Code would compact.

Reproduction

  1. Route Claude Code through opencodex to an openai-responses model with a window under 1M. In my setup that's gpt-6-astra (872K) behind an Anthropic-adapter provider with modelAdapters: openai-responses.
  2. Select the model with the [1m] suffix, so Claude Code's auto-compact threshold sits above the real window.
  3. Keep working until the request is larger than 872K tokens.
  4. Claude Code shows API Error: 502 Your input exceeds the context window of this model… and retries, several times over a few minutes. It never compacts on the overflow; compaction happened only once the client's own threshold was reached (preTokens about 925K in my transcripts).

Where it falls through (2.96.0 has the same code):

  • src/claude/outbound.ts: anthropicFailedStatus returns 400 only for code === "context_length_exceeded". An uncoded or server_error refusal goes to httpStatusFromTerminalError and gets 502.
  • src/server/claude-messages.ts: the non-stream !response.ok branch sets contextError from the code only. The status === "failed" JSON branch checks the code only too.

isContextOverflowText already recognises this message and is used on the native Messages lane (claudeOverflowSsePayload). The translated Responses lane doesn't use it.

Suggested fix (I'm running this as a local patch)

Add a helper that treats a refusal as context_length_exceeded when the message matches isContextOverflowText. Excluded: messages that match isThroughputLimitText, and errors whose type is rate_limit_error, authentication_error or permission_error. Use it in the stream response.failed handler, the non-stream error branch, and the failed-JSON branch.

Results with the patch:

  • Uncoded overflow: 400 invalid_request_error, message prompt is too long: …
  • server_error overflow: 400
  • Coded overflow: 400 (unchanged)
  • too many tokens per minute: 429 (unchanged)
  • Connection reset: 502 (unchanged)

Version

2.94.0 (2.96.0 code checked, same behaviour)

Operating system

macOS 26.6.2

Provider and model

Anthropic-compatible provider in front of CLIProxyAPI; gpt-6-astra / gpt-6.1-sol (872K) via openai-responses

Logs or error output

API Error: 502 Your input exceeds the context window of this model. Please adjust your input and try again.

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. github-actions commented on Nov 3, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  2. added
    bug
    proxy
    on Nov 3, 2026
  3. lidge-jun commented on Nov 3, 2026

    @lidge-jun
    Owner

    Fixed on dev by #8128 (60ac8ef): on the translated Claude Messages lane, a refusal that clearly says the request exceeds the context window now answers 400 "prompt is too long" (context_length_exceeded) instead of a retryable 502, so Claude Code compacts. It ships in the next release; please reopen if it still reproduces after updating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugproxy

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions