API / understand-long-context-pricing

API

Understand long-context pricing on the Grok API

Understand long-context pricing on the Grok API

Several Grok text models bill at two tiers. When the prompt reaches a published token threshold (commonly 200k), the whole request is charged at the higher long-context rates for every token in that request — input, cached input, and output.

How the threshold works

  • Count the prompt tokens on the request (system + history + tools context the API counts as prompt).
  • If that prompt is below the threshold, use the lower row on Pricing.
  • If the prompt is at or above the threshold, use the higher row for all tokens on that call.

Example for grok-4.6 (500k context) from the pricing table:

Prompt size Input / 1M Cached input / 1M Output / 1M
< 200k $2.00 $0.50 $6.00
≥ 200k $4.00 $1.00 $12.00

grok-4.5 uses the same $2 / $6 base with different cached rates. grok-4.3, grok-4.20-*, grok-build-0.1, and grok-4.20-multi-agent-0309 also publish dual rows — always read the live table for the model you call.

Practical checks

  1. Log usage.prompt_tokens (or the Responses equivalent) on each call.
  2. Treat multi-turn agent loops carefully: prompt size grows as tool results accumulate, so a later turn can cross 200k even when the first turn did not.
  3. Prefer prompt cache sticky routing (prompt_cache_key on Responses, or x-grok-conv-id on Chat Completions) so repeated prefixes bill as cached input — see Maximize Grok API prompt cache hits and Avoid breaking the Grok API prompt cache.
  4. For bulk offline work, compare Batch discounts on the same pricing page; Batch token discounts vary by model and do not replace the long-context threshold rule on real-time calls.

Pitfalls

  • Assuming only tokens past 200k get the higher rate — the docs bill the entire request at the long-context row once the prompt hits the threshold.
  • Reading a stale screenshot of prices; Console model pages and docs.x.ai/developers/pricing are the source of truth.