curl --request POST \
--url https://direct.evolink.ai/v1/responses \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.6",
"input": "搜索最新的 SpaceX 发射并用一句话总结。",
"stream": false,
"max_output_tokens": 2048,
"reasoning": {
"effort": "high"
},
"tools": [
{
"type": "web_search"
}
]
}
'import requests
url = "https://direct.evolink.ai/v1/responses"
payload = {
"model": "grok-4.6",
"input": "搜索最新的 SpaceX 发射并用一句话总结。",
"stream": False,
"max_output_tokens": 2048,
"reasoning": { "effort": "high" },
"tools": [{ "type": "web_search" }]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'grok-4.6',
input: '搜索最新的 SpaceX 发射并用一句话总结。',
stream: false,
max_output_tokens: 2048,
reasoning: {effort: 'high'},
tools: [{type: 'web_search'}]
})
};
fetch('https://direct.evolink.ai/v1/responses', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://direct.evolink.ai/v1/responses",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'grok-4.6',
'input' => '搜索最新的 SpaceX 发射并用一句话总结。',
'stream' => false,
'max_output_tokens' => 2048,
'reasoning' => [
'effort' => 'high'
],
'tools' => [
[
'type' => 'web_search'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://direct.evolink.ai/v1/responses"
payload := strings.NewReader("{\n \"model\": \"grok-4.6\",\n \"input\": \"搜索最新的 SpaceX 发射并用一句话总结。\",\n \"stream\": false,\n \"max_output_tokens\": 2048,\n \"reasoning\": {\n \"effort\": \"high\"\n },\n \"tools\": [\n {\n \"type\": \"web_search\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://direct.evolink.ai/v1/responses")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"grok-4.6\",\n \"input\": \"搜索最新的 SpaceX 发射并用一句话总结。\",\n \"stream\": false,\n \"max_output_tokens\": 2048,\n \"reasoning\": {\n \"effort\": \"high\"\n },\n \"tools\": [\n {\n \"type\": \"web_search\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://direct.evolink.ai/v1/responses")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"grok-4.6\",\n \"input\": \"搜索最新的 SpaceX 发射并用一句话总结。\",\n \"stream\": false,\n \"max_output_tokens\": 2048,\n \"reasoning\": {\n \"effort\": \"high\"\n },\n \"tools\": [\n {\n \"type\": \"web_search\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "55d44212-8d5e-90cc-975f-36d341ce21f5",
"object": "response",
"status": "completed",
"model": "grok-4.6",
"created_at": 1786538000,
"output": [
{
"id": "<string>",
"type": "web_search_call",
"status": "completed",
"content": [
{}
]
}
],
"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
}
}
}{
"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 - 同时支持普通
function工具(客户端函数调用,无按次费用)
curl --request POST \
--url https://direct.evolink.ai/v1/responses \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.6",
"input": "搜索最新的 SpaceX 发射并用一句话总结。",
"stream": false,
"max_output_tokens": 2048,
"reasoning": {
"effort": "high"
},
"tools": [
{
"type": "web_search"
}
]
}
'import requests
url = "https://direct.evolink.ai/v1/responses"
payload = {
"model": "grok-4.6",
"input": "搜索最新的 SpaceX 发射并用一句话总结。",
"stream": False,
"max_output_tokens": 2048,
"reasoning": { "effort": "high" },
"tools": [{ "type": "web_search" }]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'grok-4.6',
input: '搜索最新的 SpaceX 发射并用一句话总结。',
stream: false,
max_output_tokens: 2048,
reasoning: {effort: 'high'},
tools: [{type: 'web_search'}]
})
};
fetch('https://direct.evolink.ai/v1/responses', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://direct.evolink.ai/v1/responses",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'grok-4.6',
'input' => '搜索最新的 SpaceX 发射并用一句话总结。',
'stream' => false,
'max_output_tokens' => 2048,
'reasoning' => [
'effort' => 'high'
],
'tools' => [
[
'type' => 'web_search'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://direct.evolink.ai/v1/responses"
payload := strings.NewReader("{\n \"model\": \"grok-4.6\",\n \"input\": \"搜索最新的 SpaceX 发射并用一句话总结。\",\n \"stream\": false,\n \"max_output_tokens\": 2048,\n \"reasoning\": {\n \"effort\": \"high\"\n },\n \"tools\": [\n {\n \"type\": \"web_search\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://direct.evolink.ai/v1/responses")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"grok-4.6\",\n \"input\": \"搜索最新的 SpaceX 发射并用一句话总结。\",\n \"stream\": false,\n \"max_output_tokens\": 2048,\n \"reasoning\": {\n \"effort\": \"high\"\n },\n \"tools\": [\n {\n \"type\": \"web_search\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://direct.evolink.ai/v1/responses")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"grok-4.6\",\n \"input\": \"搜索最新的 SpaceX 发射并用一句话总结。\",\n \"stream\": false,\n \"max_output_tokens\": 2048,\n \"reasoning\": {\n \"effort\": \"high\"\n },\n \"tools\": [\n {\n \"type\": \"web_search\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "55d44212-8d5e-90cc-975f-36d341ce21f5",
"object": "response",
"status": "completed",
"model": "grok-4.6",
"created_at": 1786538000,
"output": [
{
"id": "<string>",
"type": "web_search_call",
"status": "completed",
"content": [
{}
]
}
],
"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
}
}
}{
"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 是多模态主力地址,对文本模型作为备用地址使用。image_generation 目前在 Grok 4.5 与 Grok 4.6 上均不可用:为兼容会接受该声明,但工具会在请求到达模型前被移除。未识别的 tools[].type 会返回 400。授权
##所有接口均需 Bearer Token 认证##
获取 API Key:
访问 API Key 管理页面 获取你的 API Key
添加到请求头:
Authorization: Bearer YOUR_API_KEY
请求体
要调用的模型:
| 模型 ID | 定位 |
|---|---|
grok-4.6 | xAI 推理 + 工具调用模型,50 万 token 上下文窗口;额外支持 xhigh 推理档;知识截止 2026-02-01 |
grok-4.5 | xAI 推理 + 工具调用模型,50 万 token 上下文窗口;推理档最高到 high(传 xhigh 会被降级为 high) |
grok-4.6, grok-4.5 "grok-4.6"
模型输入:纯字符串,或 OpenAI Responses 输入项数组(如 {"role":"user","content":[...]})。
"搜索最新的 SpaceX 发射并用一句话总结。"
是否流式返回(SSE 事件流,以 response.completed 结束)。默认 false。
false
生成的最大 token 数(含推理 token)。
2048
推理深度控制,对象形式:{"effort": "low" | "medium" | "high" | "xhigh"}。默认 high,推理无法关闭。xhigh 仅 grok-4.6 支持——grok-4.5 接受该值但会降级为 high。推理 token 按输出 token 计费,并计入 usage.output_tokens_details.reasoning_tokens。
Show child attributes
Show child attributes
工具声明。xAI 服务端工具(按成功调用次数计费,工具费不受长上下文倍率影响):
| 工具类型 | 能力 | 单次价格 |
|---|---|---|
web_search | 联网搜索并浏览网页 | $0.005 |
x_search | 搜索 X 帖子、账号与话题 | $0.005 |
code_execution | 在沙箱中运行 Python(别名 code_interpreter) | $0.005 |
attachment_search | 搜索对话附件文件(输入含文件时可能自动启用) | $0.01 |
collections_search | 检索已上传的文档集(别名 file_search) | $0.0025 |
同时支持普通 function 工具(客户端函数调用,无按次费用)。
image_generation 目前不可用:为兼容会接受该声明,但会在请求到达模型前被移除。未识别的工具类型返回 400。
Show child attributes
Show child attributes
[{ "type": "web_search" }]
工具选择控制:"auto"(默认)/ "none" / "required",或用对象指定某个工具,如 {"type": "web_search"}。
auto, none, required 响应
响应生成成功(JSON 对象;stream=true 时为 SSE 事件流,以 response.completed 结束)
响应的唯一标识
"55d44212-8d5e-90cc-975f-36d341ce21f5"
响应类型
response "response"
响应状态
completed, incomplete, failed "completed"
实际使用的模型名称
"grok-4.6"
创建时间戳
1786538000
按生成顺序排列的输出项:reasoning 项(思考摘要)、服务端工具调用项(如 web_search_call / code_interpreter_call,状态 completed 表示成功且计费的调用),以及最后含 output_text 内容的 message 项。
Show child attributes
Show child attributes
Token 与工具用量统计。Prompt 达到 20 万 token 起,全部 token 按 2 倍价格计费;工具费不受倍率影响。
Show child attributes
Show child attributes