#### Advanced API usage

# Prompt caching

We recommend the [Responses API](/developers/model-capabilities/text/generate-text) 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

> [!NOTE]
>
> 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](/developers/advanced-api-usage/prompt-caching/how-it-works) — Understand how caching works from the start of your messages array
* [Maximizing Cache Hits](/developers/advanced-api-usage/prompt-caching/maximizing-cache-hits) — Set up `prompt_cache_key` or `x-grok-conv-id` for optimal caching
* [What Breaks Caching](/developers/advanced-api-usage/prompt-caching/multi-turn) — Common mistakes that cause cache misses
* [Usage & Pricing](/developers/advanced-api-usage/prompt-caching/usage-and-pricing) — Read cached token counts and understand billing
* [Best Practices & FAQ](/developers/advanced-api-usage/prompt-caching/best-practices) — Tips, supported models, and common questions
