Stream reasoning summaries on grok-4.6
Stream reasoning summaries on grok-4.6
On grok-4.6, set stream: true and read summarized reasoning as it arrives. The xAI SDK exposes chunk.reasoning_content. OpenAI-compatible Responses streams emit response.reasoning_text.delta and response.reasoning_summary_text.delta (print event.delta). Vercel AI SDK surfaces part.type === 'reasoning-delta' with part.text. Those streams are summarizations of internal reasoning. Reasoning tokens bill as part of total consumption (reasoning_tokens in usage).
xAI SDK
import os
from xai_sdk import Client
from xai_sdk.chat import system, user
client = Client(
api_key=os.getenv("XAI_API_KEY"),
timeout=3600, # Override default timeout with longer timeout for reasoning models
)
chat = client.chat.create(
model="grok-4.6",
messages=[system("You are a highly intelligent AI assistant.")],
)
chat.append(user("A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)"))
content_started = False
print("\n\n--------- Reasoning ---------", flush=True)
latest_response = None
for response, chunk in chat.stream():
if chunk.reasoning_content:
print(chunk.reasoning_content, end="", flush=True)
OpenAI SDK (Responses)
import os
import httpx
from openai import OpenAI
client = OpenAI(
base_url="https://api.x.ai/v1",
api_key=os.getenv("XAI_API_KEY"),
timeout=httpx.Timeout(3600.0),
)
stream = client.responses.create(
model="grok-4.6",
input=[
{"role": "system", "content": "You are a highly intelligent AI assistant."},
{"role": "user", "content": "A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)"},
],
stream=True,
)
print("\n\n--------- Reasoning ---------", flush=True)
for event in stream:
if event.type in ("response.reasoning_text.delta", "response.reasoning_summary_text.delta"):
print(event.delta, end="", flush=True)
curl
curl https://api.x.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-m 3600 \
-d '{
"input": [
{
"role": "system",
"content": "You are a highly intelligent AI assistant."
},
{
"role": "user",
"content": "A ball is thrown upward at 25 m/s from the top of a 60 m building. Find the maximum height above the ground. (g=10 m/s²)"
}
],
"model": "grok-4.6",
"stream": true
}'
Vercel AI SDK
import { xai } from '@ai-sdk/xai';
import { streamText } from 'ai';
const result = streamText({
model: xai.responses('grok-4.6'),
system: 'You are a highly intelligent AI assistant.',
prompt: 'A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)'
});
console.log("\n\n--------- Reasoning ---------" )
for await (const part of result.fullStream) {
if (part.type === 'reasoning-delta') {
process.stdout.write(part.text);
}
}
For opaque multi-turn continuity with encrypted thinking traces, see the separate how-to on include: ["reasoning.encrypted_content"] / use_encrypted_content=True.
Pitfalls
- Override client timeouts for reasoning streams. Docs examples use 3600 seconds so the connection does not close early.
- Summarized reasoning streams are documented for
grok-4.6on the Reasoning page. Check that page before assuming other models emit the same fields. - Reasoning tokens are billed. Watch
reasoning_tokensin usage. presencePenalty,frequencyPenalty, andstoperror on reasoning models. Drop them.- Console API credits are separate from SuperGrok's weekly pool on grok.com.