Files
magpie/docs
yetone 322ec8b7ce gateway: a key out of credit rests longer each time it is refused so again, up to a week
PaulT on Discord #feedback: an OpenAI API-key provider answering 402 out
of credit showed "Resting · 402 out of credit · back at 04:10 PM" and was
asked again every 30 minutes, refused the same each time. 1534474c8 gave
ChatGPT accounts a rest until their credits are back; keys still had the
flat 30-minute creditRest.

An API key (Account == nil) whose vendor says it is out of money now
climbs creditLadder: 30m, 2h, 8h, 24h, 3d, then 7d each time after.
Refused again while it still rests (the lone key, asked all the same)
keeps its rung; a rest that ended and is refused again goes a rung up.
"Try now" (Unrest) and an answer (servedCandidate) start it over at 30m.
It covers what failure() already calls failCredit: a bare 402, OpenAI's
insufficient_quota (its billing errors are 429s with type
insufficient_quota and codes credit_balance_exhausted,
organization_/project_spend_limit_exceeded,
organization_usage_limit_exceeded, per
developers.openai.com/api/docs/guides/error-codes), DeepSeek's
"Insufficient Balance" 402, Anthropic's "credit balance is too low" 400,
Zhipu's 余额不足 and WorkBuddy's exhausted 429.

What stays as before: a refusal that names when it is back (resets_at,
a reset header) rests till then, capped at longestMonthly. A 402 that can
pass soon or for a smaller request rests creditRest flat and never climbs:
one with Retry-After (OpenRouter's openrouter_in_flight_budget, per
openrouter.ai/docs/api-reference/errors), OpenRouter's "can only afford" /
"fewer max_tokens", and "try again in N" / "N 分钟后" (creditSoon).
Subscription accounts other than ChatGPT's keep 30m flat, and another
computer's magpie rests the model only, flat (TestCreditLadderIsKeysOnly).

Run (mote-run; first at this change on origin/main d31710c71):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui: internal/gateway red only on TestAntigravityTurnsCodexsGPT5ThreadAwayOnce,
  TestAntigravityTurnedAwayIsForeseen, ...LastIsNoQuota, ...InsideTheReplyLast
  and TestCodexSpentGrokFailingIsTold, each red the same on origin/main
  d31710c71 (#4362), and TestBurstTellsNoSpeed under load (#2719);
  internal/gui red only on the real-window AppKit tests killed at their
  20-40s deadline under mote's load (TestDockJoinLeadsCommandTab,
  TestPanelCloseHidesIt, TestMainWindowCorners, TestCoveredWindowStaysUp,
  TestTrayCellClickReleasedPanel and others: #2645, #4125, #1936, #3178);
  the same five red at origin/main d31710c71 alone; TestBurstTellsNoSpeed
  passed alone on both; TestCoreScriptBudget passed
- earlier, -run 'Credit|Rest|Quota|...' ./internal/gateway: red only on
  TestAntigravityTurnedAwayLastIsNoQuota, red the same on origin/main
  d31710c71, filed as #4362.
- rebased on 764a032f6 (c37b8b659's remote-magpie quota change among
  it; the routing doc line conflicted and was merged by hand): go vet
  ./internal/gateway native, GOOS=linux, GOOS=windows ok; -run
  'Credit|Rest|Quota|Remote|Magpie|Unrest|Codex|Spent|Broke|Balance|Afford'
  ./internal/gateway red only on #4362's tests. Then rebased again on
  the 20 commits after it (46fb0c1b9) with no conflict; there go vet
  ./internal/gateway and the three new tests pass.
- gofmt -l clean; go vet ./internal/gateway native, GOOS=linux and
  GOOS=windows.
- The full go test ./... is still to come: mote was running other
  sessions' full suites. Any red it shows gets an issue.

Broken by hand, each red:
- the credit branch in restAfterMarked off: "refusal 2: rests 30m0s ...
  want 2h0m0s".
- the rung climb after an ended rest (else if had) off: red.
- creditSoon off: OpenRouter's "can only afford" climbs ("failures 1 ...
  want flat").

Not tried: PaulT's own 402 body (not known; the test holds OpenAI's
documented bodies and the vendors' bodies magpie's tests already had).
No real out-of-credit key was asked. A key's balance reading doesn't
lift its rest early; "Try now" does. The ladder is in memory, so a
restart of magpie starts it over at 30 minutes.
2026-10-30 15:30:55 +08:00
..