Grok 快速对话(全模型)
curl --request POST \
--url https://direct.evolink.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.5",
"messages": [
{
"role": "user",
"content": "你好,介绍一下你自己"
}
]
}
'import requests
url = "https://direct.evolink.ai/v1/chat/completions"
payload = {
"model": "grok-4.5",
"messages": [
{
"role": "user",
"content": "你好,介绍一下你自己"
}
]
}
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.5', messages: [{role: 'user', content: '你好,介绍一下你自己'}]})
};
fetch('https://direct.evolink.ai/v1/chat/completions', 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/chat/completions",
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.5',
'messages' => [
[
'role' => 'user',
'content' => '你好,介绍一下你自己'
]
]
]),
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/chat/completions"
payload := strings.NewReader("{\n \"model\": \"grok-4.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好,介绍一下你自己\"\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/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"grok-4.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好,介绍一下你自己\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://direct.evolink.ai/v1/chat/completions")
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.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好,介绍一下你自己\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-20260812164515123456789AbCdEfGh",
"model": "grok-4.5",
"object": "chat.completion",
"created": 1786538000,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是 Grok 4.5,由 xAI 打造的推理模型……"
},
"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/billing"
}
}{
"error": {
"code": 403,
"message": "Access denied for this model",
"type": "permission_error",
"param": "model"
}
}{
"error": {
"code": 404,
"message": "Specified model not found",
"type": "not_found_error",
"param": "model",
"fallback_suggestion": "grok-4.5"
}
}{
"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": 502,
"message": "Upstream AI service unavailable",
"type": "upstream_error",
"fallback_suggestion": "try again later"
}
}{
"error": {
"code": 503,
"message": "Service temporarily unavailable",
"type": "service_unavailable_error",
"fallback_suggestion": "retry after 30 seconds"
}
}Chat Completions 接口
Grok 全模型接口 - Chat Completions 快速开始
- 使用 OpenAI SDK 格式调用 xAI Grok 文本模型(通过
model参数选择具体模型) - 推理 + 工具调用模型;
grok-4.5上下文窗口 50 万 token - 同步处理模式,参数极简,快速上手
- 💡 需要更多功能?查看完整参数文档
- 💡 服务端工具(联网搜索、X 搜索、代码执行等)请使用 Responses 接口
POST
/
v1
/
chat
/
completions
Grok 快速对话(全模型)
curl --request POST \
--url https://direct.evolink.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.5",
"messages": [
{
"role": "user",
"content": "你好,介绍一下你自己"
}
]
}
'import requests
url = "https://direct.evolink.ai/v1/chat/completions"
payload = {
"model": "grok-4.5",
"messages": [
{
"role": "user",
"content": "你好,介绍一下你自己"
}
]
}
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.5', messages: [{role: 'user', content: '你好,介绍一下你自己'}]})
};
fetch('https://direct.evolink.ai/v1/chat/completions', 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/chat/completions",
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.5',
'messages' => [
[
'role' => 'user',
'content' => '你好,介绍一下你自己'
]
]
]),
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/chat/completions"
payload := strings.NewReader("{\n \"model\": \"grok-4.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好,介绍一下你自己\"\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/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"grok-4.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好,介绍一下你自己\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://direct.evolink.ai/v1/chat/completions")
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.5\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好,介绍一下你自己\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-20260812164515123456789AbCdEfGh",
"model": "grok-4.5",
"object": "chat.completion",
"created": 1786538000,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是 Grok 4.5,由 xAI 打造的推理模型……"
},
"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/billing"
}
}{
"error": {
"code": 403,
"message": "Access denied for this model",
"type": "permission_error",
"param": "model"
}
}{
"error": {
"code": 404,
"message": "Specified model not found",
"type": "not_found_error",
"param": "model",
"fallback_suggestion": "grok-4.5"
}
}{
"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": 502,
"message": "Upstream AI service unavailable",
"type": "upstream_error",
"fallback_suggestion": "try again later"
}
}{
"error": {
"code": 503,
"message": "Service temporarily unavailable",
"type": "service_unavailable_error",
"fallback_suggestion": "retry after 30 seconds"
}
}BaseURL 说明:默认 BaseURL 为
https://direct.evolink.ai,对文本模型支持更好,支持长连接;https://api.evolink.ai 是多模态主力地址,对文本模型作为备用地址使用。授权
##所有接口均需 Bearer Token 认证##
获取 API Key:
访问 API Key 管理页面 获取你的 API Key
添加到请求头:
Authorization: Bearer YOUR_API_KEY
请求体
application/json
响应
对话生成成功
对话补全的唯一标识
示例:
"chatcmpl-20260812164515123456789AbCdEfGh"
实际使用的模型名称
示例:
"grok-4.5"
响应类型
可用选项:
chat.completion 示例:
"chat.completion"
创建时间戳
示例:
1786538000
对话补全选项列表
Show child attributes
Show child attributes
Token 用量统计。Prompt 达到 20 万 token 起,全部 token 按 2 倍价格计费。
Show child attributes
Show child attributes
⌘I