Docs/Billing
Daily caps
How do I stop a script from spending my whole balance?
Checked against the code on
A daily cap is a number of credits one API key may spend in any rolling 24 hours. Set it when you make the key, or on an existing key in the wallet. It is optional, and it is the one setting every script key should have.
How it is enforced
- Before each request, the key's spend over the last 24 hours is added to the worst case this request could cost. If that would exceed the cap, the request is refused with
429 rate_limit_errorand does not run. - Because it checks the worst case, a capped key cannot go over the cap, even by one request.
- The window rolls: spend from 25 hours ago no longer counts.
{ "error": { "message": "This key's daily cap of 500 credits would be exceeded. It has spent 488.2 in the last 24 hours.", "type": "rate_limit_error", "param": null, "code": null } }What it does not cover
Caps are per key. The workspace has no cap; a person typing cannot run away the way a loop can. There is no account-level cap today.