SpyBara
Go Premium

advanced-api-usage/prompt-caching.md 2026-11-22 23:59 UTC to 2026-11-23 23:59 UTC

This page contains 4 additions and 2 deletions.

2026
Mon 23 23:59

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 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 prompt_cache_key (or the x-grok-conv-id HTTP header) to maximize your cache hit rate.

In this section