Repository navigation
fix(backend): answer a credit-exhausted BYOK OpenRouter account as a typed 429, not the generic 500 - #22630
Merged
Git-on-my-level merged 1 commit intoOct 21, 2026
Conversation
…typed 429
The direct OpenRouter BYOK notes lane answers a spent account with HTTP 402
('requires more credits' / limit_source openrouter_credits) before generation;
the composition boundary had no classifier for that spelling, so retries never
succeeded while clients re-polled the generic 500 at process_conversation.py:633
(same group family as the Anthropic credit fix in #21779). Classify 402 with
either OpenRouter credit marker as byok_quota so the boundary answers the
existing typed 429; every other 402 keeps the privacy-safe generic response.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
Autonomous repair exhausted (review failed 3x (timeout)); 0 fixup rounds, attempt 3/3. PR left OPEN for human triage.\n\nLast findings excerpt:\nreview failed 3x (timeout) |
Git-on-my-level
deleted the
fix/errfix-1019-gcp-process-conversation-py-633-fastapi
branch
October 21, 2026 08:24
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.
fix(backend): answer a credit-exhausted BYOK OpenRouter account as a typed 429, not the generic 500
Error group
Same fingerprint family as the py-632 predecessor fixed by #21779 (direct Anthropic credit exhaustion). That fix deployed; the group reopened on the new image (first line-633 event 2026-10-19T14:52Z, 68 events by 19:07Z).
Root cause
_get_structured's composition boundary maps every unmapped failure to the generic 500. The recurrence is driven by the direct OpenRouter BYOK notes lane: BYOK users whose key is OpenRouter's are routed tohttps://openrouter.ai/api/v1(_get_or_create_openrouter_llm), and when that account's credits cannot cover the request, OpenRouter answers HTTP 402 and the openai SDK raisesAPIStatusErrorbefore generation. Retries can never succeed, so clients re-poll into the same 500. Prod evidence (projectbased-hardware, 2026-10-19):/app/utils/conversations/process_conversation.py:633):This is the same account state the platform already answers as "throttled BYOK, not a server bug": the gateway classifies it
byok_quotaand answers 429, and the composition boundary already types the gateway envelope (#21779) and direct Anthropic's 400 "credit balance is too low" (#21779). The direct OpenRouter 402 spelling had no detection, so it fell into the generic 500 bucket — the user gets an unhelpful "try again later" for a state only they can fix, and this error group keeps reopening.Fix
backend/utils/llm/gateway_error_contract.py:_OPENROUTER_CREDIT_EXHAUSTED_MARKERS(requires more credits,openrouter_credits): OpenRouter's stable spellings of the credit-exhaustion account state, in the message and as thelimit_sourcemetadata value. Marker text is used only for classification — never logged or echoed.is_byok_quota_error()now also classifies HTTP 402 carrying either marker as BYOK quota, mirroring the existing direct-Anthropic 400 branch. All other 402s and every other exception keep the privacy-safe generic 500.conversation_processing_http_exception()is unchanged: the newly classified errors now map to the existing typed 429{'code': 'byok_quota', ...}detail, matching the contract the gateway lane already enforces.No fallback to the managed lane is introduced; the response only stops misreporting a fixable account state as a server error.
Verification
py_compileon both touched files: OK.openai.APIStatusErrorinstances (backend/tests/unit/test_conversation_structure_byok_quota.py):black --line-length 120 --skip-string-normalization --check: both files clean.Failure-Class: none