API balance
Your balance is a USD amount held by the gateway, credited from on-chain deposits and spent per token.
How balance is credited
The gateway runs an indexer that reads Deposited events from the Billing contract after a safe number of confirmations. Each event is applied exactly once, keyed by its deposit id, so restarts and reorg handling cannot double-credit.
How balance is spent
Every request follows the same three steps, so you are only ever charged for tokens that were actually used.
| Step | What happens |
|---|---|
| Reserve | The worst-case cost (prompt estimate plus max_tokens) is set aside from your balance. |
| Settle | When the provider reports usage, the exact cost is charged. |
| Refund | The unused part of the reservation returns to your balance immediately. |
If the reservation is larger than your balance or your max_cost, the gateway lowers max_tokens to fit rather than rejecting the request. A request is refused only when even a single output token cannot be afforded.
Spend caps
Send max_cost in the request body (or the x-max-cost header) to cap what a single call can cost in USD. This is useful for agents and untrusted prompts. See the reference.
Transparency
Every response includes usage.cost and the headers x-cerebra-cost and x-cerebra-balance. GET /v1/usage lists recent requests with token counts and exact cost, and the dashboard shows the same history.
Balances are not withdrawable