模型能力
推理
主要特性
- 思考后再回应:推理模型在提供答案前会逐步思考问题。
- 数学与量化优势:擅长数值挑战、逻辑谜题和复杂分析任务。
- 推理追踪:使用指标暴露
reasoning_tokens。某些模型还可以通过include: ["reasoning.encrypted_content"]返回加密推理(见下文)。
加密推理内容
推理内容由我们加密,如果您在调用 Responses API 时传递 include: ["reasoning.encrypted_content"],则可以返回该内容。您可以发送回加密内容,为之前的对话提供更多上下文。有关如何使用此内容的详细信息,请参阅添加加密思考内容。
TIP
使用 Vercel AI SDK 时,只要不指定 store: false,加密推理内容会自动在后台包含。无需额外配置。
reasoning_effort 参数
grok-4.5 支持 reasoning_effort 参数,控制模型在回应前投入多少思考精力。
如果未指定,reasoning_effort 默认为 "high"。推理功能不能禁用。
presencePenalty、frequencyPenalty 和 stop 不能与推理模型一起使用。包含这些参数的请求会返回错误。
努力级别
| 设置 | 描述 | 最适用场景 |
|---|---|---|
"low" | 使用一些推理令牌,但仍保持快速 | 对延迟敏感的代理使用和简单工具调用。 |
"medium" | 为对延迟不敏感的应用进行更多思考 | 复杂数据分析和长上下文推理。 |
"high" (默认) | 使用更多推理令牌进行深度思考 | 非常具挑战性的问题、复杂数学、多步骤逻辑、竞赛级任务 |
设置推理努力
以下示例将 reasoning_effort 设置为 "high",用于处理具有挑战性的数学证明。您可以根据需要替换为 "low" 或 "medium"。
python
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,
)
chat = client.chat.create(
model="grok-4.5",
reasoning_effort="high",
messages=[system("You are a highly intelligent AI assistant.")],
)
chat.append(user("Find all prime numbers p such that p^2 + 2 is also prime. Prove your answer."))
response = chat.sample()
print("Final Response:")
print(response.content)python
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),
)
response = client.responses.create(
model="grok-4.5",
reasoning={"effort": "high"},
input=[
{"role": "system", "content": "You are a highly intelligent AI assistant."},
{"role": "user", "content": "Find all prime numbers p such that p^2 + 2 is also prime. Prove your answer."},
],
)
message = next(item for item in response.output if item.type == "message")
text = next(c.text for c in message.content if c.type == "output_text")
print("Final Response:")
print(text)typescript
import { xai } from '@ai-sdk/xai';
import { generateText } from 'ai';
const result = await generateText({
model: xai.responses('grok-4.5'),
system: 'You are a highly intelligent AI assistant.',
prompt: 'Find all prime numbers p such that p^2 + 2 is also prime. Prove your answer.',
providerOptions: {
xai: { reasoningEffort: 'high' },
},
});
console.log('Final Response:', result.text);bash
curl https://api.x.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-m 3600 \
-d '{
"model": "grok-4.5",
"reasoning": {"effort": "high"},
"input": [
{
"role": "system",
"content": "You are a highly intelligent AI assistant."
},
{
"role": "user",
"content": "Find all prime numbers p such that p^2 + 2 is also prime. Prove your answer."
}
]
}'多代理模型
对于 grok-4.20-multi-agent,reasoning.effort 参数控制多少个代理协作处理请求,而非推理深度。有关详细信息,请参阅多代理文档。
总结表格
| 模型 | reasoning 参数 | 行为 |
|---|---|---|
grok-4.5 | reasoning.effort: "low" / "medium" / "high" (默认) | 控制推理深度(不能禁用) |
grok-4.20-multi-agent | reasoning.effort: "low" / "medium" / "high" / "xhigh" | 控制代理数量(4 或 16) |
摘要推理内容
对于 grok-4.5,我们公开了模型内部推理的摘要。以下是如何将推理摘要增量流式传输与最终响应一起输出的示例:
python
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.5",
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)python
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.5",
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)typescript
import { xai } from '@ai-sdk/xai';
import { streamText } from 'ai';
const result = streamText({
model: xai.responses('grok-4.5'),
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);
}
}bash
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.5",
"stream": true
}'示例输出
text
--------- Reasoning ---------
The problem is: 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²)
I need to find the speed when the projectile hits the ground. It's launched at 30 m/s at 37° from a 45 m cliff, with g=10 m/s².
Conservation of energy is a good approach. The initial kinetic energy is (1/2)mv² with v=30 m/s, and initial potential energy is mgh with h=45 m, taking ground as zero.
At impact, potential energy is zero, so initial KE + initial PE = final KE.
Thus, (1/2)m(30)² + mg(45) = (1/2)m v_f²
v_f² = 900 + 2*10*45 = 900 + 900 = 1800
v_f = sqrt(1800) = 30√2 m/s ≈ 42.4 m/s
The angle doesn't affect the final speed because the initial kinetic energy and potential energy change are the same regardless of direction, as long as the speed and height are the same.
Yes, that makes sense. The final speed is sqrt(v0² + 2gh), independent of the launch angle.当您使用推理模型时,推理令牌将作为您总消耗的一部分计费。