Reuse Reasoning in Subsequent Requests
On this page
Thought Cache
One of the most powerful features of xAI’s encrypted reasoning system is the ability to reinject reasoning from a previous request into a new one. This mechanism, similar to a “thought cache”, lets the model pick up its reasoning where it left off.
How It Works
The process consists of three steps:
- Initial request: you send a question with
include=["reasoning.encrypted_content"] - Storage: you keep the encrypted content returned in the response
- Subsequent request: you reinject this encrypted content into the new request
The model recognizes the encrypted reasoning and uses it as context for its new reflection. It doesn’t start from scratch: it has “memory” of its previous thought process.
Step-by-Step Implementation
Step 1: Initial Request with Reasoning Retrieval
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://api.x.ai/v1"
)
# First request
response_1 = client.responses.create(
model="grok-4.20-0309-reasoning",
input="Explain Bayes' theorem and give a medical example.",
include=["reasoning.encrypted_content"]
)
# Extract encrypted reasoning
encrypted_reasoning = None
for item in response_1.output:
if item.type == "reasoning":
encrypted_reasoning = item.encrypted_content
Step 2: Subsequent Request with Reinjection
# Second request that benefits from the previous reasoning
response_2 = client.responses.create(
model="grok-4.20-0309-reasoning",
input=[
# Reinject encrypted reasoning from the previous request
{
"type": "reasoning",
"encrypted_content": encrypted_reasoning
},
# New message
{
"type": "message",
"role": "user",
"content": "Now, apply this theorem to a COVID test with 95% sensitivity and 99% specificity."
}
],
include=["reasoning.encrypted_content"]
)
Benefits of the Thought Cache
Reasoning Continuity
The model doesn’t need to reconstruct the entire thought context. If it has already reasoned about Bayes’ theorem, it can apply it directly to the new problem without rehashing the demonstration.
Token Savings
By reusing encrypted reasoning, you prevent the model from regenerating reasoning tokens for the part already covered. In long conversations, the savings can be significant.
Consistency
The model maintains consistency across its successive responses. It won’t contradict itself since it has the trace of its own reasoning.
Constraints and Limitations
- Same model: encrypted reasoning from one model cannot be reused by another model. Reasoning produced by grok-4.5 won’t work with grok-4.20-0309-reasoning.
- Size: encrypted content can be large. Monitor your request sizes.
- Expiration: encrypted content may have a limited validity period. Don’t store it indefinitely without checking.
- No modification: you cannot alter the encrypted content. Any modification makes it invalid.
Production Use Cases
Complex Multi-Turn Conversations
For a chatbot solving math problems over several exchanges, the thought cache maintains the thread of reasoning without having to resend everything in context.
Validation Pipeline
A pipeline that analyzes code in multiple passes can reuse reasoning from the first pass (identifying issues) for the second pass (proposing fixes).
Interactive Tutor
A tutoring system can store the model’s reasoning on explaining a concept, then reuse it when the student asks follow-up questions.
Key Takeaways
- Encrypted reasoning can be reinjected into subsequent requests via the
inputfield - This mechanism maintains reasoning continuity without regenerating tokens
- Encrypted reasoning is tied to the model that produced it
- Never modify the encrypted content: it becomes invalid
- Useful for multi-turn conversations, pipelines, and interactive systems