SpyBara
Go Premium

advanced-api-usage/prompt-caching.md 2026-10-29 23:01 UTC to 2026-10-30 23:58 UTC

No changes for this document in this history range.

2026

Advanced API Usage

Prompt Caching

When consecutive requests share the same starting messages, the xAI 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 xAI API performs prompt caching automatically. However, we recommend setting the x-grok-conv-id HTTP header to maximize your cache hit rate.

In this section