入门指南
Grok 4.5
Grok 4.5 是 SpaceXAI 的前沿模型,专为编程、智能体任务和知识工作而构建。它使用涵盖科学、工程和数学的新数据集,在 SpaceXAI 位于孟菲斯的数据中心进行训练。
使用 API
如果您已有 API 密钥,请将模型名称设置为 grok-4.5:
python
import os
from xai_sdk import Client
from xai_sdk.chat import user
client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(model="grok-4.5")
chat.append(user("Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}"))
response = chat.sample()
print(response.content)javascript
import { xai } from '@ai-sdk/xai';
import { generateText } from 'ai';
const { text } = await generateText({
model: xai.responses('grok-4.5'),
prompt:
'Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}',
});
console.log(text);javascript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.XAI_API_KEY,
baseURL: 'https://api.x.ai/v1',
});
const response = await client.responses.create({
model: 'grok-4.5',
input: [
{
role: 'user',
content:
'Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}',
},
],
});
console.log(response.output_text);bash
curl https://api.x.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-d '{
"model": "grok-4.5",
"input": "Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}"
}'刚接触 xAI API?请按照 快速入门 创建账户并发出您的第一个请求。
概览
| 属性 | 值 |
|---|---|
| 模型名称 | grok-4.5 |
| 知识截止日期 | 2026年2月1日 |
| 输入价格 | $2.00 / 100万 tokens |
| 输出价格 | $6.00 / 100万 tokens |
| 推理能力 | 低、中或高(默认高) |
| API | 响应 API, 聊天补全 |
| 工具 | 函数调用, 网络搜索, X 搜索, 代码执行 |
完整上下文窗口、速率限制和团队的实时定价可在 模型详情页 和 定价页面 查看。
有关基准测试结果和成本与分数对比,请参阅 公告。
重要细节
- 我们强烈建议设置一个
prompt_cache_key(响应 API;聊天补全中的x-grok-conv-id头部)。它将对话的请求路由到同一服务器,使缓存命中变得可靠;没有它,您通常需要在缓存未命中的服务器上支付全额输入价格。请参阅 哪些情况会破坏缓存 了解常见错误。 - 长智能体循环 还受益于 上下文压缩;对于工具密集型工作负载,请参阅 函数调用。
运行环境
- xAI API:从 控制台 获取密钥
- Grok Build:编码智能体 的默认模型,在 API 和 CLI 上可用
- Cursor:所有计划均可使用
- Office 加载项:Word、PowerPoint 和 Excel 加载项中的默认模型
- 模型网关:OpenRouter、Vercel、Cloudflare、Snowflake 和 Databricks Mosaic