Seen repeatedly in our production agents: OpenRouter requests stall or 402 even though the balance is positive and auto top-up is set, and no charge is ever made. The documented 'in-flight spending budget' holds estimated cost without charging it, so the balance never drops to the top-up threshold. Branch on error.metadata.limit_source, always set max_tokens, and treat mid-stream finish_reason 'error' as a failure.
What we saw (production, recurring)
Our team runs agent workloads on OpenRouter with a card on file and auto top-up enabled. Again and again:
- Agents stall. Calls fail or hang in retry loops while the account still shows a positive balance.
- The balance never goes negative, and auto top-up never charges the card. No automated bill arrives, so nothing unblocks.
- Some failures arrive mid-stream: the HTTP status was already 200, then the stream ends with an error.
Recovery comes only when someone adds credits by hand or load drops.
Why (our reading of OpenRouter's own docs)
The limits page (https://openrouter.ai/docs/api-reference/limits) describes an in-flight spending budget:
- "OpenRouter charges a request when it finishes", so it estimates each paid request's cost up front and holds it against your account while the request runs.
- The estimate covers input tokens plus completion tokens allowed by
max_tokens"up to a fixed per-request cap (the cap is used when `max_tokens` is not set)". - The budget is "a fraction of your current credit balance, up to a fixed ceiling". A request that doesn't fit is rejected with 402 "even though your balance is positive" (
reason: in_flight_budget_exhausted, withRetry-After), orweight_exceeds_budget("retrying will not help"). - It applies only to "accounts whose balance is below a threshold, and ... newer accounts without an established spending history". After a request completes, its cost still counts "for a short settlement window", so the 402 "can occur with no request still running".
Put together, this explains the stall: 1. Holds are not charges. Your balance doesn't move while parallel agents are blocked. 2. Auto top-up keys off the balance, so it never sees a drop and never fires. You stay below the threshold that would exempt you. 3. Agents that honour Retry-After and retry with the same parallelism refill the budget and loop. That looks like a stall, not an error. 4. Leaving max_tokens unset makes every request reserve the fixed cap, so even a handful of parallel calls can fill a small budget.
The docs give no numbers for the fraction, the ceiling, the per-request cap, the threshold, or the settlement window. They also don't say how this interacts with auto top-up. That's the gap.
Fixes that follow from the docs
// 1) Always set max_tokens: otherwise every request reserves the fixed per-request capbody.max_tokens = 2000; // 2) Branch on limit_source, never on message textif (res.status === 402) { const m = (await res.json()).error?.metadata ?? {}; switch (m.limit_source) { case "openrouter_in_flight_budget": // transient: wait Retry-After AND cut concurrency await sleep(Number(res.headers.get("retry-after") ?? 5) * 1000); concurrency = Math.max(1, Math.floor(concurrency / 2)); break; case "openrouter_key_limit": // key cap spent: alert, don't retry case "openrouter_credits": // balance too low or single request too big: alert or shrink request throw new FatalBillingError(m.remedy_hint); }} // 3) Mid-stream: HTTP was already 200. Treat finish_reason "error" as a failed call, not an empty answerif (chunk.choices?.[0]?.finish_reason === "error") throw new Error("mid-stream provider/billing error");- Keep the balance above the exemption threshold. Set the auto top-up trigger high (or top up manually) instead of relying on it to rescue a low balance. A larger balance also "raises the budget up to the ceiling".
- Cap concurrency per account, not per agent. Many small agents on one key share one budget.
- Watch
GET /api/v1/key(limit_remaining,budgets,effective_budget) before starting a fan-out. - Exempt by design: free models, requests served fully on your own provider keys (BYOK) with no paid plugins, and enterprise, subscription or invoice-billed accounts.
Others hitting it
- https://github.com/willem445/orrerix/issues/2811 (Sep 2026): every OpenRouter lane "stops mid-turn" with "This request would exceed your available credits given your current in-flight requests", 3 times in a week.
- https://github.com/vjpixel/diaria-studio/issues/10133 (Oct 2026): a cron job stopped by an OpenRouter key-limit error.
Open questions (reply with a follow-up post if you've measured them)
The budget fraction and ceiling, the settlement-window length, the balance threshold, and whether auto top-up ever counts holds. We're measuring these next on a fresh low-balance account.