Skip to main content
Watch: I Built an AI App Without Leaving Databricks

Cost levers - verified

How to cut your xAI API bill

Prompt caching: automatic. Cache lifetime: not fixed: evicted under load. A cache hit typically saves 84% on input across 8 current models. Batch: 20% off select models, 24 hours, best effort. Batch and caching stack: yes. Service tiers: Priority (2x).

Read from docs.x.ai. Compare every provider's cost levers

Caching
Automatic
Cache hit saves
84%
Batch
20% off select models
Service tiers
1

Prompt caching

Mode

Automatic: repeated prefixes are cached with no code change

Automatic prefix caching on all grok language models; x-grok-conv-id header (or prompt_cache_key on Responses API) routes to the same server to raise hit rates.

Cache lifetime

Not fixed: entries can be evicted at any time due to server load or restarts

Minimum prompt
Not stated
Cache write cost
Not stated
Cache read cost

Reduced per-model cached prompt token price

Storage cost
Not stated
How to enable

Automatic; set the x-grok-conv-id HTTP header to a stable conversation ID.

Request fragment
x-grok-conv-id: <stable conversation id>
From the docs
“The xAI API performs prompt caching automatically. However, we recommend setting the `x-grok-conv-id` HTTP header to maximize your cache hit rate.”
“Cache entries can be evicted at any time due to server load or restarts. Use `x-grok-conv-id` to maximize retention by routing to the same server.”
“Cached tokens are billed at the cached prompt token price, which is substantially lower than the regular prompt token price. The exact rates vary by model”
“Prompt caching is available on all `grok` language models.”

Sources: docs.x.ai/developers/advanced-api-usage/prompt-caching, docs.x.ai/developers/advanced-api-usage/prompt-caching/usage-and-pricing, docs.x.ai/developers/advanced-api-usage/prompt-caching/best-practices

Batch API

Discount

20% off select models

20% on grok-4.3, grok-4.20-0309-reasoning, grok-4.20-0309-non-reasoning and grok-4.20-multi-agent-0309; models not listed get no batch discount. Applies to input, output, cached and reasoning tokens (text models only; image/video at standard rates)

Window

Typically within 24 hours, best effort, not guaranteed

Limits

File upload: max 200 MB and 50,000 requests; inline batches unlimited in theory (>100,000 may be throttled); 25MB per request; 2 batch creations per second per team; requests don't count toward rate limits

Endpoint

Batch API (create batch, then add requests or upload JSONL; lines target /v1/chat/completions, /v1/responses, image and video endpoints)

Stacks with caching

Yes: the batch discount and the cache discount combine

“The batch discount applies to all token types”

Sources: docs.x.ai/developers/advanced-api-usage/batch-api, docs.x.ai/developers/pricing

From the docs
“The Batch API lets you process large volumes of requests asynchronously at a discount to standard pricing. The size of the discount varies by model.”
“The batch discount applies to all token types”
“The batch discount applies to text and language models only. Image and video generation are supported in the Batch API but are billed at standard rates.”
“Most batch requests complete within 24 hours, though processing time may vary depending on system load and batch size. Completion time is best effort and not guaranteed.”
“Maximum file size is 200 MB with up to 50,000 requests.”
“A batch can contain an unlimited number of requests in theory, but extremely large batches (>100,000 requests) may be throttled for processing stability.”
“| grok-4.3 grok-4.20-0309-reasoning grok-4.20-0309-non-reasoning grok-4.20-multi-agent-0309 | 20% |”
“Models not listed above have no batch discount.”
“Each individual request that can be added to a batch has a maximum payload size of 25MB.”
“Maximum batch creation rate: 2 batch creations per second per team.”

Sources: docs.x.ai/developers/advanced-api-usage/batch-api, docs.x.ai/developers/pricing

Service tiers

Flex trades speed or availability for a lower price; Priority and Fast cost more for lower latency or reserved capacity.

Priority

Priority Processing

Set with service_tier: priority

Price effect

2x premium over standard on all token types (cache discount applied first); billed at priority only when the response confirms priority

Trade-off

Lower TTFT and inter-token latency, especially at high demand; Chat Completions and Responses only; not for Batch

From the docs
“Priority requests are billed at a 2x premium over standard rates.”
“The 2x multiplier applies to all token types”
“You are only billed at the priority rate when the response confirms "service_tier": "priority".”
“Priority Processing gives your xAI API requests higher scheduling priority, which typically results in lower time-to-first-token (TTFT) and faster inter-token latency (ITL), especially during periods of high demand.”

Sources: docs.x.ai/developers/advanced-api-usage/priority-processing, docs.x.ai/developers/pricing

Other discounts and surcharges

Other discounts on the pages checked: Not stated

xAI per-model prices

USD per 1M tokens from the provider's own pricing page, newest release first. A dash means the model has no such rate. Muted rows are scheduled for shutdown or deprecated.

xAI models with input, cache, batch, output and fast mode prices per 1M tokens
ModelInputCached inputBatch inputOutputBatch output
Grok 4.7$2$0.5075% off-$6-
Grok 4.6$2$0.5075% off-$6-
Grok 4.5$2$0.3085% off-$6-
Grok Build 0.1$1$0.2080% off-$2-
Grok 4.20$1.25$0.2084% off$1$2.50$2
Grok 4.20 (Non-Reasoning)$1.25$0.2084% off$1$2.50$2
Grok 4.20 Multi-Agent Beta$1.25$0.2084% off$1$2.50$2
Grok 4.3$1.25$0.2084% off$1$2.50$2

Research notes

Docs now branded 'SpaceXSI Docs' at docs.x.ai/developers. Batch discount is per model (20% on the listed models only).

FAQ

Does xAI cache prompts automatically?

Automatic: repeated prefixes are cached with no code change. Automatic prefix caching on all grok language models; x-grok-conv-id header (or prompt_cache_key on Responses API) routes to the same server to raise hit rates. How to enable: Automatic; set the x-grok-conv-id HTTP header to a stable conversation ID.

How much does a cache hit cost on xAI?

Across 8 current models with a cache read price, a hit saves 84% (75% to 85%) off the input price. The docs say: Reduced per-model cached prompt token price.

Does xAI have a batch API discount?

20% on grok-4.3, grok-4.20-0309-reasoning, grok-4.20-0309-non-reasoning and grok-4.20-multi-agent-0309; models not listed get no batch discount. Applies to input, output, cached and reasoning tokens (text models only; image/video at standard rates). Window: Typically within 24 hours, best effort, not guaranteed. Stacks with caching: yes: the batch discount and the cache discount combine.

What service tiers does xAI offer?

Priority: 2x premium over standard on all token types (cache discount applied first); billed at priority only when the response confirms priority.

Sources

Last verified from xAI's own pages below. Quotes are verbatim; each was matched against the live page.

Newsletter

Know when a provider changes its prices

One email per week. New model releases, pricing changes and what they mean for what you build.