Skip to content

fix(routing): fall back past HTTP 402 payment-required providers - #16

Merged
aliihsaad merged 1 commit into
mainfrom
fix/payment-required-fallback
Sep 22, 2026
Merged

aliihsaad merged 1 commit into
mainfrom
fix/payment-required-fallback

Conversation

@aliihsaad

Copy link
Copy Markdown
Owner

Problem

In the production Playground, Auto (chat route) returned a 502 on every message:

Provider error (GPT-OSS 120B (Cerebras)): Cerebras API error 402: Payment required to access this resource. Visit your billing tab.

Cerebras now blocks chat completions for all models until the account has a payment method, while GET /v1/models still lists them.

Root cause

classifyProviderError had no rule for HTTP 402, so the error fell to other (retryable: false):

  • the proxy returned 502 immediately instead of trying the next model in the chain;
  • recordTerminalProviderFailure records nothing for other, so the next request picked Cerebras again, forever.

Same bug class as the 410 fix in #8: an unclassified status code ends the fallback chain.

Fix

402 / "payment required" joins the existing account-denial branch in server/src/services/provider-errors.ts:

  • retryable: true, so auto-route falls through to the next model;
  • skipModel: false, so the model is not quarantined (the account is the problem);
  • 24h key-scoped cooldown, so that credential is skipped for every model on the platform.

It is matched with /\b402\b/ (no false positives on numbers like 4020) and placed before the rate-limit branch, because some 402 bodies (Chutes) also say "quota".

Tests

  • 4 classifier tests in account-denial-cooldown.test.ts
  • End-to-end proxy test in proxy-model-hardening.test.ts: Cerebras 402 → Groq serves; the second request does not call Cerebras again; the model is not blocked. Returns 502 without the fix (verified by stashing the change).
  • Server suite 345/345; tsc clean; server/dist rebuilt (provider-errors outputs only).

After merge

  • Deploy to the VPS (git fetch origin && git reset --hard origin/main && systemctl restart llm-hub).
  • The Cerebras account still needs a payment method, or its rows should be disabled. The key cooldown is in memory, so after a restart each Cerebras key fails once more before it is benched again.

🤖 Generated with Claude Code

Cerebras now answers 402 "Payment required to access this resource" on
chat completions for every model until the account adds a payment
method, while GET /models still lists them. classifyProviderError had no
402 rule, so it fell to 'other' (retryable: false): model:auto returned a
502 instead of trying the next model, and nothing was recorded, so the
next request picked Cerebras again.

402 is a billing state of the account, so it joins the account-denial
branch: retryable, model not quarantined, credential benched for 24h
across the platform. Matched before the rate-limit branch because some
402 bodies (Chutes) also say "quota". Includes the rebuilt server/dist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: cc715c97-7ca7-4412-a43c-4b57557bb3ea


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aliihsaad
aliihsaad merged commit d164376 into main Sep 22, 2026
2 checks passed
@aliihsaad
aliihsaad deleted the fix/payment-required-fallback branch September 22, 2026 20:19
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