xAI integration

xAI Grok API spend alerts and brakes

Costbrake reads the dollars xAI reports per hour, model and API key every 5 minutes on Pro and Team, and every 2 minutes for 2 hours after a spike alert. With a second management key, an admin can disable an API key or set the team's invoiced billing limit to $0.01, and Undo puts either back.

By default xAI runs on prepaid credits and rejects requests once they run out, but auto top-up can buy more. The Free plan checks hourly with email alerts; brakes come with Pro at $12 a month and Team at $39 a month (see pricing).

xAI at a glance

Reads
Dollars per hour, model and API key from xAI's management API
Key
A management key with only AnalyzeBillingItems; brakes need a second management key
Setup
Paste the key in the dashboard or on the connect page your coding agent sends
Free plan
Checks every hour, email alerts, no brakes
Pro and Team
Checks every 5 minutes, Slack, Discord and webhook alerts, brakes
Spike checks
Every 2 minutes for 2 hours after a spike alert
Brakes
Disable API key, Freeze invoiced billing

Brakes

2 brakes for xAI

An admin picks a brake, confirms it, and can undo it later. Brakes come with Pro and Team.

  • Admin confirms

    Disable API key

    Disables the API key, so xAI rejects its requests once the change reaches xAI's API servers; other keys keep working.

    UndoEnables the API key again.

    The team's other API keys keep spending the same prepaid credits.

  • Admin confirms

    Freeze invoiced billing

    Sets the team's invoiced billing limit to $0.01, so xAI rejects requests that would add to this month's invoice.

    UndoRestores the invoiced billing limit the team had before, unless someone changed it in the meantime.

    Prepaid credits keep being used until they run out and auto top-up can buy more, so on prepaid credits alone, disable keys instead.

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.

ControlApplies toWhat happensGap
Prepaid creditsThe whole teamRequests are rejected once the credits run outEvery key draws on the same balance
Auto top-upThe whole teamBuys credits below a threshold, up to a monthly maximumKeeps refilling what a runaway job drains
Invoiced billing limitTeams on invoiced billingNo responses once the month's invoice reaches itOff by default; you request it from xAI
Key rate limitsOne API keyCaps queries per second or per minuteLimits speed, not dollars
Costbrake brakeOne key, or the invoiced billing limitDisables the key or sets the limit to $0.01An 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

  1. An admin turns on the killswitch for the connection and adds the second management key.
  2. Costbrake lists the team's invoiced billing limit and every API key.
  3. The admin picks a target and a brake, then types the connection's name to confirm.
  4. Costbrake disables the key, or sets the invoiced billing limit to $0.01.
  5. 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

Start with 14 days of Pro, free

Catch the next xAI spike before the invoice.

14 days of Pro, then Free for 2 accounts. No card needed.