Genace

NOT_ENOUGH_CREDITS: Not enough credits: balance is X, this request needs Y

HTTP 402 NOT_ENOUGH_CREDITS
{
  "error": {
    "type": "insufficient_credits",
    "code": "NOT_ENOUGH_CREDITS",
    "message": "Not enough credits: balance is 12, this request needs 100"
  }
}

The message carries both numbers, so you do not have to go looking: what you have, and what this specific request would have cost.

Nothing was spent

The balance check runs before the job is submitted upstream. A 402 means no job was created, nothing was charged, and there is nothing to reconcile or refund. Retrying after topping up is safe.

This is also why the error is worth treating as a normal branch rather than an exception: it is the designed behaviour of a prepaid ceiling, not a fault.

Working out the cost in advance

Cost is deterministic per model and per parameter set, so you can compute it before calling:

ModelCost
Nano Banana4 credits × n
Flux Pro v1.15 credits × n
Ideogram v36 credits × n
Seedance 2.0 Fast5 credits per second at 1080p, half at 720p
Kling 2.0 Standard35 credits (5s) or 70 (10s)
Veo 3100 credits at 1080p, 50 at 720p — always 8 seconds

The cheapest useful call on the platform is 4 credits; the most expensive single call is 100.

Two ways to stop hitting it

Cheaper iterations. Seedance and Veo 3 both halve their price at 720p. If you are iterating on prompts and only need full resolution for finals, that is a 50% cut on the expensive half of the loop.

Handle it as a branch. In an agent context, catching 402 and reporting “out of budget” is almost always better than retrying. The balance will not change on its own, so a retry loop just burns turns.

Failures do not cost credits

Credits are deducted at submit and refunded in full when a job ends failed or canceled. A run of upstream failures will not quietly drain the balance that produced this error.

Where these facts come from

  • codebase: src/ai/api/credits.ts — balance assertion before submit
  • codebase: src/ai/jobs/service.ts — deduct on submit, refund on failure/cancel
  • codebase: src/ai/providers/*.ts — per-model pricing()