Billing API reports a healthy account while every request 400s with insufficient credits

Aperta
#1,081 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cli
Ambito
api, backend

Direzione di ricerca

Start by reading the /alpha/billing/credits handler and the request path that returns the insufficient credits error; the payload names no source files or tests. Compare how each path derives credit availability, then check the usage limits documentation and related issue #904. Done when the billing response gives clients a reliable signal that matches whether requests can be served, with the documented behavior aligned.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

/alpha/billing/credits reports a healthy account (belowThreshold=false, both rolling windows at 0% used) while every completion request is rejected with insufficient credits. A client that automates fallback across providers therefore has no way to tell "this account can't serve requests" — it has to send a real request to find out.

Expected Behavior

If requests are refused, one of the documented fields should reflect it:

  • credits.belowThreshold = true, or
  • a new explicit flag (canRequest / insufficientCredits), or
  • windowLimits.exceeded / fiveHour.exceeded set.

Also, https://commandcode.ai/docs/resources/usage-limits ("What happens when I run out of credits?") says requests stop once your included credits reach zero, which suggests monthlyCredits would be 0 at that point. Here they stop at 0.084.

Actual Behavior

GET https://api.commandcode.ai/alpha/billing/credits → 200:

{
  "credits": { "belowThreshold": false, "creditThreshold": 0,
               "monthlyCredits": 0.0840296077, "purchasedCredits": 0, "freeCredits": 0 },
  "windowLimits": { "limited": true, "exceeded": null,
                    "fiveHour": { "used": 0, "cap": 14, "exceeded": false, "resetAt": 0 },
                    "weekly":   { "used": 0, "cap": 35, "exceeded": false, "resetAt": 0 } }
}

GET https://api.commandcode.ai/alpha/billing/subscriptions → 200: status: "active", planId: "individual-goat", currentPeriodEnd: "2026-11-04T14:00:31.000Z".

Any request fails, including a one-token one:

POST /provider/v1/chat/completions
{"model":"deepseek/deepseek-v4.1-flash","messages":[{"role":"user","content":"hi"}],"max_tokens":1}

HTTP 400
{"message":"You have insufficient credits to make this request. Please purchase more credits to continue using the service.",
 "type":"invalid_request_error","code":"BAD_REQUEST"}
x-trace-id: ab67b7089a5a839861c5a497f5d9fe96

So belowThreshold is unusable as a signal: with creditThreshold = 0 it can only trip exactly at zero. windowLimits.limited = true is not a signal either — it is true with both windows at 0% used, and windowLimits.exceeded is null, not false.

Steps to reproduce the issue
  1. Use an account whose included monthly credits are almost gone (0.084 here) with no purchased credits.
  2. curl -s -H "Authorization: Bearer $KEY" https://api.commandcode.ai/alpha/billing/credits → belowThreshold: false, monthlyCredits: 0.084, windows 0/14 and 0/35.
  3. curl -s -X POST https://api.commandcode.ai/provider/v1/chat/completions -H "Authorization: Bearer $KEY" -H "content-type: application/json" -d '{"model":"deepseek/deepseek-v4.1-flash","messages":[{"role":"user","content":"hi"}],"max_tokens":1}' → 400 insufficient credits.
Command Code Version

1.88.1 (provider-API behaviour; reproduced with plain curl, no CLI involved)

Operating System

Windows

Suggested fixes
  1. Add an explicit canRequest / insufficientCredits boolean to /alpha/billing/credits, or make belowThreshold honour a real minimum balance instead of creditThreshold = 0.
  2. Return the required amount / remaining balance in the 400 body, and a documented error code distinct from BAD_REQUEST.
  3. Document windowLimits.limited and windowLimits.exceeded (null vs false) — clients can only guess today.
  4. Align the "requests stop once your included credits reach zero" FAQ sentence with actual behaviour.

Related: #904 (non-interactive quota readout) is also helped by making these fields trustworthy.

Lingua principale
Nessun dato sulla lingua
Stelle
4.2k
Fork
377
Merge medio
1g 3h
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CommandCodeAI/command-code

Tutte le issue di CommandCodeAI/command-code

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.