Grok API Pricing Guide
How xAI meters the Grok API, which six factors actually move your bill, and the controls that keep it predictable.
TL;DR
- →Input and output are metered separately; output costs more on every model.
- →Rates change with model releases — read
docs.x.aiand the Console, not a blog table. - →Resent chat history is the most underestimated cost line in production.
- →Spend limits are enforced as 403s. Degrade gracefully instead of hard-failing.
Why This Page Has No Price Table
Deliberately. Per-million-token rates on the Grok family have moved with each model generation, and a stale number copied into an architecture decision is worse than no number at all — it gets trusted. The rate you need is on xAI's own pricing documentation and in the Console against your account.
What does not go stale is the structure of the bill and the levers that move it. That is what the rest of this page covers, and it is what actually determines whether your Grok spend is predictable.
Six Things That Move Your Bill
Output tokens dominate
Output is priced above input on every model. The cheapest optimisation available is asking for less: cap max_tokens, request terse formats, and stop asking models to restate the question before answering.
Resent conversation history
Every turn re-sends the whole thread as input. A fifty-turn chat pays for the early turns fifty times. Summarise or window the history rather than appending indefinitely.
Oversized retrieval context
RAG pipelines that stuff twenty chunks in when five would do multiply input cost with little quality gain. Rank, then truncate to what measurably improves the answer.
Reasoning-style intermediate output
Models that reason at length bill that reasoning as output tokens even when the user-visible answer is two lines. Match model choice to task difficulty instead of defaulting to the strongest one.
Retries and failovers
A retried request bills twice. A failover bills on both providers. Bounded retries with a circuit breaker are a cost control as much as a reliability control.
Cached input, when applicable
Repeated prefixes billed at a reduced rate reward stable system prompts. Randomising or reordering the front of your prompt for no reason forfeits that discount silently.
Attribute Spend to Features, Not Totals
A monthly total tells you that costs rose. It does not tell you which code path did it, which is the only thing you can act on. Emit prompt tokens, completion tokens and model ID as a metric tagged with the feature name on every call. Within a week you will have a per-feature cost graph, and the conversation shifts from "the LLM bill is up" to "the summarisation path doubled after Tuesday's deploy".
That same instrumentation feeds your rate limit work, since TPM and cost are driven by the exact same token counters — see the Grok API rate limits guide.
Spend Limits Fail as 403s
Worth stating plainly because it produces confusing incidents: when an account-level spend cap is reached, requests come back as 403 Forbidden — the same status as a missing model entitlement. Teams then rotate keys and audit permissions while the actual cause is a billing ceiling. Handle 403 as a distinct, alertable condition with its own runbook entry, and make sure your app degrades rather than throwing a stack trace at users. Full classification is in the error code reference.
Alert Pro
14-day free trialStop checking — get alerted instantly
Next time Grok goes down, you'll know in under 60 seconds — not when your users start complaining.
- Email alerts for Grok + 9 more APIs
- $0 charged today — card required to start
- Cancel anytime — $9/mo after trial
Related Guides
Frequently Asked Questions
How is the Grok API billed?
Per token, metered separately for input and output, with output priced higher than input on every model in the family. Additional line items can apply depending on what you use — cached input is billed at a reduced rate, and capabilities such as live information retrieval are metered on top of token usage. Because xAI revises rates as models ship, treat docs.x.ai and the Console as the authoritative source rather than any third-party table.
Why is my Grok API bill higher than my token count suggests?
Three usual culprits. First, output tokens cost more than input, so a chatty system prompt is cheap relative to verbose completions. Second, reasoning-oriented models can generate substantial intermediate output that bills as output tokens even when the visible answer is short. Third, resent context — every turn of a chat re-sends the full history, so long conversations grow input cost quadratically unless you truncate or summarise.
Does a smaller Grok model actually save money?
Usually yes, and often more than the headline rate difference suggests, because smaller models also finish faster and consume less of your rate limit. The caveat is retry cost: if a cheaper model fails your output schema often enough that you re-run on a larger one, the effective price is the sum of both calls. Measure cost per successful validated response, not cost per call.
How do I stop a runaway Grok API bill?
Set a spend limit in console.x.ai so the ceiling is enforced by the provider rather than by your own vigilance — note that hitting it surfaces as 403 responses, so your app should degrade gracefully rather than hard-fail. Then cap max_tokens on every call, truncate conversation history, and emit a per-request token counter tagged by feature so you can attribute spend to a code path instead of a total.
Do failed or timed-out requests still cost money?
A request that was rejected before generation — 400, 401, 403, 404, 422, 429 — does not produce billable output. A request that timed out on your side may well have been generated server-side and billed even though you never received the bytes. That asymmetry is why unbounded retry loops on timeouts are expensive as well as slow: cap retries and deduplicate on your own request ID.
📡 Monitor your APIs — know when they go down before your users do
Better Stack checks uptime every 30 seconds with instant Slack, email & SMS alerts. Free tier available.
Affiliate link — we may earn a commission at no extra cost to you