Can you set a hard spending limit on xAI?
Partly. A team starts on prepaid credits with a $0 invoiced billing limit, and xAI rejects API requests once the prepaid credits are depleted. Auto top-up buys more credits when the balance drops below a threshold you set, up to a monthly maximum. Teams on monthly invoiced billing stop getting responses once the month's invoice reaches their invoiced billing limit.
| Control | Applies to | What happens | Gap |
|---|---|---|---|
| Prepaid credits | The whole team | Requests are rejected once the credits run out | Every key draws on the same balance |
| Auto top-up | The whole team | Buys credits below a threshold, up to a monthly maximum | Keeps refilling what a runaway job drains |
| Invoiced billing limit | Teams on invoiced billing | No responses once the month's invoice reaches it | Off by default; you request it from xAI |
| Key rate limits | One API key | Caps queries per second or per minute | Limits speed, not dollars |
| Costbrake brake | One key, or the invoiced billing limit | Disables the key or sets the limit to $0.01 | An admin starts it |
The xAI Console shows a warning on its API spend management card at 80% of the monthly limit you set. Costbrake alerts by email, Slack, Discord, webhook or PagerDuty when an hour costs over 3 times its 7-day usual and at least $5 more. How do I limit spend on the xAI API? covers the Console settings.
What Costbrake reads from xAI
Costbrake calls xAI's management API for the team's usage, the same data as the Usage Explorer, in dollars per hour, model and API key as xAI reports them. xAI doesn't say how far its usage data trails, so every check re-reads the last 6 hours, and every 6 hours Costbrake re-reads the last 2 days.
Daily totals from the start of last month come from the same data, and a day counts as final 3 hours after it ends. Costbrake doesn't price tokens itself here; the dollars are xAI's. For model prices, see What does the xAI Grok API cost?.
Which xAI key does Costbrake need?
A management key, which xAI keeps separate from the API keys your apps call models with. Create one in the xAI Console under Settings, Management Keys, select only the AnalyzeBillingItems permission, and copy it while it is shown. Model API keys don't work here. An organization-wide key also needs the ID of the team to watch.
A key with only AnalyzeBillingItems can't call models or change API keys, limits or payment details. With agent setup, you still paste the xAI key yourself, on the connect page your agent sends.
The brakes need a second management key with ListApiKeys, UpdateApiKey, GetSpendingLimits and SetSoftSpendingLimit, added in the Costbrake dashboard. Create it as a team admin: xAI shows a member's management key only that member's own API keys.
How the xAI brakes work
- An admin turns on the killswitch for the connection and adds the second management key.
- Costbrake lists the team's invoiced billing limit and every API key.
- The admin picks a target and a brake, then types the connection's name to confirm.
- Costbrake disables the key, or sets the invoiced billing limit to $0.01.
- Undo enables the key again, or restores the earlier limit unless someone changed it after the brake.
On a team without invoiced billing the limit is already off, so Costbrake refuses that brake; disable the API keys instead.
What Costbrake can't do on xAI
- Stop spend on its own. Alerts are automatic; a brake always waits for an admin.
- Stop prepaid credit spend with the billing brake. Only disabling keys does that.
- Turn off auto top-up or change payment details.
- Delete an API key. Brakes only disable keys and lower a limit.
If a key has leaked, disable it first and rotate it after: What to do in the first hour after an API key leaks.
Questions and answers
Does xAI have a hard spending limit?
Prepaid credits work as one: with the default $0 invoiced billing limit, xAI rejects API requests once the prepaid credits are depleted. Auto top-up can refill them, and teams on invoiced billing stop once the month's invoice reaches their invoiced billing limit.
Why doesn't Freeze invoiced billing stop all xAI spend?
It only sets the team's invoiced billing limit to $0.01. Prepaid credits keep paying for requests until they run out, and auto top-up can buy more, so on prepaid credits the brake that stops a runaway key is Disable API key.
Can Costbrake use a normal xAI API key?
No. Costbrake reads usage through xAI's management API, which needs a management key; API keys for models don't work there. A management key with only the AnalyzeBillingItems permission is enough for alerts.
How often does Costbrake check xAI spend?
Every 5 minutes on Pro and Team, every 2 minutes for 2 hours after a spike alert, and every hour on Free. Each check re-reads the last 6 hours, because xAI doesn't say how far its usage data trails.
Does Costbrake stop xAI spend on its own?
No. Alerts go out automatically, but a brake only runs when an admin of your Costbrake workspace picks a target and types the connection name to confirm.
Sources
Updated