{
"id": "chatcmpl-20260812164515123456789AbCdEfGh",
"model": "grok-4.7",
"object": "chat.completion",
"created": 1786538000,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Prompt 缓存会复用已处理过的输入前缀,重复上下文按更低价格计费。",
"tool_calls": [
{}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 504,
"completion_tokens": 2,
"total_tokens": 526,
"prompt_tokens_details": {
"cached_tokens": 0
}
}
}{
"error": {
"code": 400,
"message": "Invalid request parameters",
"type": "invalid_request_error"
}
}{
"error": {
"code": 401,
"message": "Invalid or expired token",
"type": "authentication_error"
}
}{
"error": {
"code": 402,
"message": "Insufficient quota",
"type": "insufficient_quota_error",
"fallback_suggestion": "https://evolink.ai/dashboard/credits"
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded",
"type": "rate_limit_error",
"fallback_suggestion": "retry after 60 seconds"
}
}{
"error": {
"code": 500,
"message": "Internal server error",
"type": "internal_server_error",
"fallback_suggestion": "try again later"
}
}{
"error": {
"code": 503,
"message": "Service temporarily unavailable",
"type": "service_unavailable_error",
"fallback_suggestion": "retry after 30 seconds"
}
}Grok 全模型接口 - Chat Completions 完整参数
- xAI Grok 系列文本模型的 OpenAI 兼容 Chat Completions 接口,通过
model选择具体模型(全部可选值见model参数的对照表) - 50 万 token 上下文窗口;Prompt 达到 20 万 token 起,全部 token 按 2 倍价格计费
- Prompt 缓存自动生效:命中缓存的输入 token 按更低的缓存价计费
- 支持同步与流式(SSE)两种模式
- 支持普通
function工具调用;联网搜索、X 搜索等服务端工具建议使用 Responses 接口 - 支持图片输入(jpg / png,单张 ≤ 20MiB):
content传内容块数组,image_url块传公网 URL 或 base64 data URL;Grok 4.5 / 4.6 / 4.7 均支持
{
"id": "chatcmpl-20260812164515123456789AbCdEfGh",
"model": "grok-4.7",
"object": "chat.completion",
"created": 1786538000,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Prompt 缓存会复用已处理过的输入前缀,重复上下文按更低价格计费。",
"tool_calls": [
{}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 504,
"completion_tokens": 2,
"total_tokens": 526,
"prompt_tokens_details": {
"cached_tokens": 0
}
}
}{
"error": {
"code": 400,
"message": "Invalid request parameters",
"type": "invalid_request_error"
}
}{
"error": {
"code": 401,
"message": "Invalid or expired token",
"type": "authentication_error"
}
}{
"error": {
"code": 402,
"message": "Insufficient quota",
"type": "insufficient_quota_error",
"fallback_suggestion": "https://evolink.ai/dashboard/credits"
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded",
"type": "rate_limit_error",
"fallback_suggestion": "retry after 60 seconds"
}
}{
"error": {
"code": 500,
"message": "Internal server error",
"type": "internal_server_error",
"fallback_suggestion": "try again later"
}
}{
"error": {
"code": 503,
"message": "Service temporarily unavailable",
"type": "service_unavailable_error",
"fallback_suggestion": "retry after 30 seconds"
}
}https://direct.evolink.ai,对文本模型支持更好,支持长连接;https://api.evolink.ai 是多模态主力地址,对文本模型作为备用地址使用。function 工具调用。服务端工具(联网搜索、X 搜索、代码执行、附件搜索、文档集搜索)建议使用 Responses 接口,其中包含工具配置和计费说明。Grok 4.7 接入说明
将model 设为 grok-4.7 即可调用,保留现有的 messages 请求格式。上下文窗口为 500,000 token,知识截止于 2026 年 5 月。
推理深度使用顶层 reasoning_effort,支持 low、medium、high(默认)和 xhigh;推理无法关闭。grok-4.6 同样支持 xhigh,grok-4.5 会将其按 high 处理。
prompt_cache_key 可为共享相同 Prompt 前缀的请求提供稳定的缓存路由提示,不保证缓存命中。实际命中量请查看 usage.prompt_tokens_details.cached_tokens。如需在多轮对话中保留加密思考内容,请使用 Responses 接口。授权
##所有接口均需 Bearer Token 认证##
获取 API Key:
访问 API Key 管理页面 获取你的 API Key
添加到请求头:
Authorization: Bearer YOUR_API_KEY
请求体
要调用的模型:
| 模型 ID | 定位 |
|---|---|
grok-4.7 | xAI 推理 + 工具调用模型,50 万 token 上下文窗口;支持 xhigh 推理档;知识截止 2026-05 |
grok-4.6 | xAI 推理 + 工具调用模型,50 万 token 上下文窗口;额外支持 xhigh 推理档;知识截止 2026-02-01 |
grok-4.5 | xAI 推理 + 工具调用模型,50 万 token 上下文窗口;推理档最高到 high(传 xhigh 会被降级为 high) |
grok-4.7, grok-4.6, grok-4.5 "grok-4.7"
对话消息列表,支持 system、user、assistant 角色。content 可以是字符串,也可以是内容块数组(text / image_url),用于图片理解。
1Show child attributes
Show child attributes
[ { "role": "system", "content": "你是一个简洁的助手。" }, { "role": "user", "content": "用一句话解释什么是 Prompt 缓存。" } ]
是否流式返回(SSE,chat.completion.chunk 事件)。默认 false。
false
生成的最大 token 数。
1024
推理深度:low / medium / high(默认)/ xhigh。推理无法关闭。xhigh 支持 grok-4.7 和 grok-4.6;grok-4.5 接受该值但会降级为 high。推理 token 按输出 token 计费。
low, medium, high, xhigh 采样温度(0-2),越大输出越随机。
0.7
核采样参数(0-1)。
0.95
本页展示普通 OpenAI function 工具定义(客户端函数调用,无服务端工具调用费)。联网搜索、X 搜索等服务端工具的配置与用量说明请参阅 Responses 接口。
Show child attributes
Show child attributes
函数选择控制:"auto" / "none" / "required",或用对象指定某个函数。
auto, none, required 可选的缓存路由键。同一会话或共享相同 Prompt 前缀的请求使用稳定值,可提高 Prompt 缓存命中机会;不保证命中,也不改变缓存计费规则。实际命中量以 usage 中的 cached_tokens 为准。
"grok-session-001"
响应
对话生成成功(JSON 对象;stream=true 时为 chat.completion.chunk 的 SSE 事件流)
对话补全的唯一标识
"chatcmpl-20260812164515123456789AbCdEfGh"
实际使用的模型名称
"grok-4.7"
响应类型
chat.completion "chat.completion"
创建时间戳
1786538000
对话补全选项列表
Show child attributes
Show child attributes
Token 用量统计。Prompt 达到 20 万 token 起,全部 token(输入、缓存输入、输出)按 2 倍价格计费。
Show child attributes
Show child attributes