Advanced API usage
Prompt caching
We recommend the Responses API for Grok models, and the examples in this section use it. It carries the model's reasoning from one request to the next, either in the reasoning items you send back or through previous_response_id; Chat Completions has no field for encrypted reasoning. Prompt caching itself works the same way on both APIs.
When consecutive requests share the same starting messages, the Grok API automatically caches them. On the next request, messages at the beginning that match exactly are served from cache:
- Faster time-to-first-token — the model skips re-computing cached messages
- Lower cost — cached tokens are billed at a reduced rate
The Grok API performs prompt caching automatically. However, we recommend setting prompt_cache_key (or the x-grok-conv-id HTTP header) to maximize your cache hit rate.
In this section
- How It Works — Understand how caching works from the start of your messages array
- Maximizing Cache Hits — Set up
prompt_cache_keyorx-grok-conv-idfor optimal caching - What Breaks Caching — Common mistakes that cause cache misses
- Usage & Pricing — Read cached token counts and understand billing
- Best Practices & FAQ — Tips, supported models, and common questions
Last updated: November 24, 2026