Retrieve encrypted reasoning with include
On this page
Access internal reasoning of xAI reasoning models
Recent xAI reasoning models (grok-4.5, grok-4.20 family) generate internal reasoning that you cannot read in plain text. However, xAI lets you retrieve this reasoning in encrypted form using the include parameter. This mechanism enables advanced uses, particularly reusing reasoning in subsequent requests.
The include parameter
To retrieve the encrypted reasoning content, add "reasoning.encrypted_content" to the include array in your Responses API request:
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://api.x.ai/v1"
)
response = client.responses.create(
model="grok-4.20-0309-reasoning",
input="Analyze the algorithmic complexity of merge sort.",
include=["reasoning.encrypted_content"]
)
Response structure
The response contains the encrypted reasoning in a specific format. This content is an encoded blob that you can store but not interpret. Its internal structure is opaque by design.
# Iterate through response elements
for item in response.output:
if item.type == "reasoning":
# Encrypted reasoning content
encrypted = item.encrypted_content
print(f"Encrypted reasoning size: {len(encrypted)} characters")
elif item.type == "message":
# Model's final response
print(f"Response: {item.content[0].text}")
Without include: no reasoning in the response
If you don’t include "reasoning.encrypted_content" in the include parameter, the response contains only the final result. Reasoning happens server-side, but no trace is returned:
# Without include - only the final response is returned
response = client.responses.create(
model="grok-4.20-0309-reasoning",
input="Analyze the algorithmic complexity of merge sort."
)
# response.output contains only the message, no reasoning
Reasoning tokens are still counted and billed, even without include. The difference is that you don’t receive the encrypted content for later reuse.
When to use include
Retrieving encrypted reasoning comes with a cost—larger responses, more bandwidth—so use include for a specific purpose, not by default. The primary use case is multi-turn conversation: if you plan to continue the exchange, reinjecting the reasoning from the previous turn preserves the continuity of the model’s thought. This distinguishes a progressing conversation from a series of independent questions. Thought cache is the enterprise extension: storing reasoning from a request to reuse it on similar requests avoids making the model recompute everything. Two governance use cases remain: audit, when compliance requires a complete trace of every response produced, and debugging with xAI support, which will request the full reasoning to analyze unexpected behavior.
Storing encrypted reasoning
You can store the encrypted content like any string. In a database, a TEXT or JSONB field is sufficient:
import json
# Extract and store encrypted reasoning
reasoning_data = None
for item in response.output:
if item.type == "reasoning":
reasoning_data = item.encrypted_content
# Save with the response
record = {
"question": "Analyze the complexity of merge sort.",
"response": response.output[-1].content[0].text,
"encrypted_reasoning": reasoning_data,
"model": "grok-4.20-0309-reasoning",
"timestamp": "2026-04-03T10:00:00Z"
}
Key takeaways
- The
include=["reasoning.encrypted_content"]parameter retrieves encrypted reasoning from xAI reasoning models - Without
include, reasoning occurs but is not returned (tokens are still billed) - Encrypted content is an opaque blob that you cannot read in plain text
- You can store and reuse this content in subsequent requests (in the next lesson)
- Use
includeonly if you have a specific use for the encrypted reasoning