xAI API cost tracking: three ways to see what Grok costs your team
xAI gives you three ways to see what the Grok API costs: a per-request cost field on every response, the Usage Explorer in the xAI Console, and a billing usage endpoint on the Management API. Each answers a different question. This guide covers when to use which, and where a shared dashboard still helps.
View Spend sits one layer up: connect read-only usage keys for xAI, OpenAI and Anthropic so engineering and finance look at the same spend view. More insight. Less waste.
1. Per-request cost: cost_in_usd_ticks
Per xAI's cost tracking docs, the usage object in chat completions, Responses API, image and video responses includes cost_in_usd_ticks: the amount billed for that request after discounts such as prompt caching. 1 USD is 1010 ticks.
cost_usd = usage.cost_in_usd_ticks / 1e10
Best for: logging cost next to a feature, user or job inside your own app. Limits: you only see traffic your code logs, so keys used by other teams, scripts or tools are invisible.
2. Usage Explorer in the xAI Console
Team admins can chart consumption by day, switch between USD, tokens and billing items, and group by API key or model. Filters cover API key, model, request IP, cluster and token type.
Best for: a quick look or spotting an anomaly. Limits: it is a console view for admins, not something finance gets in their inbox, and it only covers xAI.
3. Management API: historical usage
For automation, call POST /v1/billing/teams/{team_id}/usage on https://management-api.x.ai with a management key (not an inference key):
curl https://management-api.x.ai/v1/billing/teams/$XAI_TEAM_ID/usage \
-X POST \
-H "Authorization: Bearer $XAI_MANAGEMENT_KEY" \
-H "Content-Type: application/json" \
-d '{"analyticsRequest":{
"timeRange":{"startTime":"2026-10-01 00:00:00","endTime":"2026-10-27 23:59:59","timezone":"Etc/GMT"},
"timeUnit":"TIME_UNIT_DAY",
"values":[{"name":"usd","aggregation":"AGGREGATION_SUM"}],
"groupBy":["description"],
"filters":[]}}'
The response has one timeSeries per group with daily data points. If limitReached is true, the query hit a cardinality cap and the result is partial, so narrow the grouping or time range. Always check field names against the current xAI docs; they change.
Which one to use
| Path | Best when |
|---|---|
cost_in_usd_ticks | Attributing cost to features or users inside one app |
| Usage Explorer | Quick admin check, one provider |
| Management API usage | Daily syncs, custom grouping, your own pipeline |
| View Spend | xAI plus OpenAI and Anthropic, team attribution, budgets and alerts without owning the pipeline |
Gaps a DIY script usually hits
- OpenAI and Anthropic have different cost APIs and schemas (see OpenAI Costs API guide)
- Teams are not a native concept, so you map API keys to owners yourself
- Budgets, alerts and month-end chargeback are left to you
- Management keys are powerful, so storing and rotating them becomes production work
How View Spend fits
View Spend reads provider billing and usage APIs with read-only access, attributes spend to teams and projects, and adds budgets, alerts, forecasts and monthly chargeback. It does not proxy requests or read prompts. Related: LLM cost tracking, AI budget alerts, AI spend chargeback, monitor AI spend.
FAQ
How do I see what my team spends on the xAI API?
Use the Usage Explorer in the xAI Console for a quick view, or call the Management API usage endpoint (POST /v1/billing/teams/{team_id}/usage) with a management key to pull daily USD spend grouped by API key or model.
What is cost_in_usd_ticks?
A field in the usage object of xAI inference responses that gives the exact billed cost of that request. 1 USD equals 10,000,000,000 ticks, so divide by 1e10 to get dollars.
Can a normal xAI API key read billing data?
No. Billing routes live on https://management-api.x.ai and need a management key. An inference key against api.x.ai will not answer them.
Does View Spend proxy my xAI traffic?
No. View Spend reads usage and cost through provider billing and usage APIs with read-only access. Nothing sits in your request path.
Get started
View Spend helps teams track and cut spend on xAI, OpenAI and Anthropic with read-only usage keys. More insight. Less waste. Get started or see pricing.