curl --request POST \
--url https://direct.evolink.ai/v1/responses \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.7",
"input": "用一句话解释什么是 Prompt 缓存。",
"reasoning": {
"effort": "xhigh"
},
"max_output_tokens": 2048,
"prompt_cache_key": "grok-session-001"
}
'{
"id": "55d44212-8d5e-90cc-975f-36d341ce21f5",
"object": "response",
"status": "completed",
"model": "grok-4.7",
"created_at": 1786538000,
"output": [
{
"id": "<string>",
"type": "web_search_call",
"status": "completed",
"content": [
{}
],
"encrypted_content": "<string>"
}
],
"usage": {
"input_tokens": 10329,
"output_tokens": 299,
"total_tokens": 10628,
"input_tokens_details": {
"cached_tokens": 6016
},
"output_tokens_details": {
"reasoning_tokens": 128
},
"num_server_side_tools_used": 2,
"server_side_tool_usage_details": {
"web_search_calls": 2,
"x_search_calls": 0,
"code_interpreter_calls": 0,
"document_search_calls": 0,
"file_search_calls": 0,
"mcp_calls": 0,
"x_posts_fetched": 0,
"x_users_fetched": 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/billing"
}
}{
"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 全模型接口 - Responses 完整参数
- xAI Grok 系列文本模型的 OpenAI 兼容 Responses 接口,通过
model选择具体模型(全部可选值见model参数的对照表) - 50 万 token 上下文窗口;Prompt 达到 20 万 token 起,全部 token 按 2 倍价格计费
- Prompt 缓存自动生效:命中缓存的输入 token 按更低的缓存价计费
- 支持同步与流式(SSE)两种模式
- xAI 服务端工具在 xAI 基础设施上执行:
web_search、x_search、code_execution、attachment_search、collections_search;X 搜索按抓取的帖子数和用户资料数计费,其他工具按成功调用次数计费 - 同时支持普通
function工具(客户端函数调用,无按次费用) - 按 xAI 官方约定,
grok-4.7默认返回含encrypted_content的reasoning项;实际字段以当前线路响应为准
curl --request POST \
--url https://direct.evolink.ai/v1/responses \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.7",
"input": "用一句话解释什么是 Prompt 缓存。",
"reasoning": {
"effort": "xhigh"
},
"max_output_tokens": 2048,
"prompt_cache_key": "grok-session-001"
}
'{
"id": "55d44212-8d5e-90cc-975f-36d341ce21f5",
"object": "response",
"status": "completed",
"model": "grok-4.7",
"created_at": 1786538000,
"output": [
{
"id": "<string>",
"type": "web_search_call",
"status": "completed",
"content": [
{}
],
"encrypted_content": "<string>"
}
],
"usage": {
"input_tokens": 10329,
"output_tokens": 299,
"total_tokens": 10628,
"input_tokens_details": {
"cached_tokens": 6016
},
"output_tokens_details": {
"reasoning_tokens": 128
},
"num_server_side_tools_used": 2,
"server_side_tool_usage_details": {
"web_search_calls": 2,
"x_search_calls": 0,
"code_interpreter_calls": 0,
"document_search_calls": 0,
"file_search_calls": 0,
"mcp_calls": 0,
"x_posts_fetched": 0,
"x_users_fetched": 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/billing"
}
}{
"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 是多模态主力地址,对文本模型作为备用地址使用。Grok 4.7 接入说明
将model 设为 grok-4.7 即可调用。上下文窗口为 500,000 token,知识截止于 2026 年 5 月。推理深度通过 reasoning.effort 设置,支持 low、medium、high(默认)和 xhigh,推理无法关闭。
按 xAI 的加密思考约定,4.7 的 output 中默认返回带有 encrypted_content 的 reasoning 项,无需显式设置 include。自行维护多轮历史时,请将完整的 reasoning 项与其他历史输出一起原样传回下一轮 input;不要解码或修改密文。请以实际响应中的字段为准。
X Search 计费
X Search 新计费规则适用于 Grok 4.5、4.6 和 4.7:一次搜索可能抓取多条帖子及多个用户资料,父帖和引用帖也计数。例如抓取 30 条帖子和 3 个用户资料,工具费为30 × $0.005 + 3 × $0.01 = $0.18,另计 Token 费用。
查看 usage.server_side_tool_usage_details.x_posts_fetched 和 x_users_fetched 获取抓取量;两字段均缺失的响应按成功调用次数兼容计费。x_search_calls 是调用次数;max_tool_calls 是调用次数控制值,其实际限制效果取决于线路。两者都不能作为抓取量或费用上限。x_users_fetched 是用量字段,不需要额外声明工具。
image_generation 目前在 Grok 4.5、4.6 和 4.7 上均不可用:为兼容会接受该声明,但工具会在请求到达模型前被移除。未识别的 tools[].type 会返回 400。授权
##所有接口均需 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"
模型输入:纯字符串,或 OpenAI Responses 输入项数组(如 {"role":"user","content":[...]})。
"搜索最新的 SpaceX 发射并用一句话总结。"
是否流式返回(SSE)。默认 false。请读取终态响应的 status 和 usage:completed 表示生成完成;达到输出限制等情况可能为 incomplete,不应只等待 response.completed 事件。
false
生成的最大 token 数(含推理 token)。
2048
推理深度控制,对象形式:{"effort": "low" | "medium" | "high" | "xhigh"}。默认 high,推理无法关闭。xhigh 支持 grok-4.7 和 grok-4.6;grok-4.5 接受该值但会降级为 high。推理 token 按输出 token 计费,并计入 usage.output_tokens_details.reasoning_tokens。
Show child attributes
Show child attributes
工具声明。服务端工具费在 Token 费用之外计算,不受长上下文倍率影响:
| 工具类型 | 能力 | 计费单位与价格 |
|---|---|---|
web_search | 联网搜索并浏览网页 | 0.005 美元 / 次成功调用 |
x_search | 搜索 X 帖子、账号与话题 | 0.005 美元 / 条抓取的帖子 + 0.01 美元 / 个抓取的用户资料 |
code_execution | 在沙箱中运行 Python(别名 code_interpreter) | 0.005 美元 / 次成功调用 |
attachment_search | 搜索对话附件文件(输入含文件时可能自动启用) | 0.01 美元 / 次成功调用 |
collections_search | 检索已上传的文档集(别名 file_search) | 0.0025 美元 / 次成功调用 |
X Search 新口径适用于 grok-4.5、grok-4.6 和 grok-4.7。一次调用可能返回多条帖子;搜索或帖子串返回的父帖、引用帖也计数。实际计量见 usage.server_side_tool_usage_details;响应缺少两个抓取计数字段时,按成功调用次数兼容计费。
同时支持普通 function 工具(客户端函数调用,无服务端工具调用费)。
image_generation 目前不可用:为兼容会接受该声明,但会在请求到达模型前被移除。未识别的工具类型返回 400。
Show child attributes
Show child attributes
[{ "type": "web_search" }]
工具选择控制:"auto"(默认)/ "none" / "required",或用对象指定某个工具,如 {"type": "web_search"}。
auto, none, required 可选的缓存路由键。同一会话或共享相同 Prompt 前缀的请求使用稳定值,可提高 Prompt 缓存命中机会;不保证命中,也不改变缓存计费规则。实际命中量以 usage 中的 cached_tokens 为准。
"grok-session-001"
请求附加响应字段。例如 grok-4.6 可通过 ["reasoning.encrypted_content"] 请求加密思考内容;grok-4.7 按 xAI 接口约定默认返回,不需要显式设置。
["reasoning.encrypted_content"]
工具调用次数控制值。网关透传此值,并用于估算工具费用预留;具体线路是否严格限制调用次数需以实际行为为准。该值不限制 X 搜索抓取的帖子数或用户资料数,也不能作为费用上限。
1
响应
响应返回成功;请同时检查 status,生成完成为 completed,达到输出限制等情况可能为 incomplete,失败为 failed。stream=true 时为 SSE 事件流,应读取终态响应的 status 和 usage。
响应的唯一标识
"55d44212-8d5e-90cc-975f-36d341ce21f5"
响应类型
response "response"
响应状态
completed, incomplete, failed "completed"
实际使用的模型名称
"grok-4.7"
创建时间戳
1786538000
按生成顺序排列的输出项:reasoning 项(可含加密思考内容)、服务端工具调用项、function_call 项,以及含 output_text 内容的 message 项。工具用量以 usage 为准;一次 x_search 调用可能产生多条帖子和多个用户资料的费用。
Show child attributes
Show child attributes
Token 与工具用量统计。Prompt 达到 20 万 token 起,全部 token 按 2 倍价格计费;工具费不受倍率影响。
Show child attributes
Show child attributes