The cost formula (memorize this one)
Every Grok API call follows the same math. There is no per-call fee, no platform fee, no minimum spend. You pay for what you send and what you get back, at the model's per-1M-token rate:
``` cost = (input_tokens / 1,000,000) × input_price_per_M + (output_tokens / 1,000,000) × output_price_per_M ```
Two adjustments stack on top, but only on Grok-4.20. First, **cache-hit pricing** drops the cached input portion to $0.20/1M — a 90% discount versus the $2.00 standard rate. The cache is opportunistic and prefix-based: put your stable system prompt, tool definitions, and any reusable few-shot examples at the start of the message array; put user-specific content last. Second, the **data-sharing program** returns up to $150/month in free credits if you opt your traffic into xAI's training set (see the dedicated section below). These two stack: a data-sharing-eligible workload running on cached Grok-4.20 prefixes can net out at zero marginal cost for the first ~75M cached input tokens per month.
Real-time X-search results that the model retrieves are billed as input tokens once they enter context — there is no separate search fee like Perplexity charges. This is one of Grok's cleanest pricing wins: live web/X grounding is built into the standard token rate.