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": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"stream": false,
"max_tokens": 1024,
"temperature": 0.7,
"top_p": 0.95,
"tools": [
{
"type": "function",
"function": {}
}
]
}
'import requests
url = "https://direct.evolink.ai/v1/chat/completions"
payload = {
"model": "grok-4.5",
"messages": [
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"stream": False,
"max_tokens": 1024,
"temperature": 0.7,
"top_p": 0.95,
"tools": [
{
"type": "function",
"function": {}
}
]
}
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: 'system', content: 'You are a concise assistant.'},
{role: 'user', content: 'Explain prompt caching in one sentence.'}
],
stream: false,
max_tokens: 1024,
temperature: 0.7,
top_p: 0.95,
tools: [{type: 'function', function: {}}]
})
};
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' => 'system',
'content' => 'You are a concise assistant.'
],
[
'role' => 'user',
'content' => 'Explain prompt caching in one sentence.'
]
],
'stream' => false,
'max_tokens' => 1024,
'temperature' => 0.7,
'top_p' => 0.95,
'tools' => [
[
'type' => 'function',
'function' => [
]
]
]
]),
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\": \"system\",\n \"content\": \"You are a concise assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 1024,\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {}\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\": \"system\",\n \"content\": \"You are a concise assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 1024,\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {}\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\": \"system\",\n \"content\": \"You are a concise assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 1024,\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {}\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": "Prompt caching reuses previously processed prompt prefixes so repeated context is billed at a lower rate.",
"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/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 全モデルインターフェース - Chat Completions 完全なパラメータ
- xAI Grok テキストモデル向けの OpenAI 互換 Chat Completions エンドポイント。モデルは
modelパラメータで選択(全指定値はmodelパラメータの対照表を参照) grok-4.5:コンテキストウィンドウ 500K トークン。プロンプトが 200K トークン以上になると、すべてのトークン種別が 2 倍の料金で課金されます- プロンプトキャッシュは自動的に有効:キャッシュにヒットした入力トークンはより安いキャッシュ料金で課金されます
- 同期モードとストリーミング(SSE)モードに対応
- 通常の
functionツール呼び出しに対応。xAI のサーバーサイドツールは Responses API のみで利用できます
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": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"stream": false,
"max_tokens": 1024,
"temperature": 0.7,
"top_p": 0.95,
"tools": [
{
"type": "function",
"function": {}
}
]
}
'import requests
url = "https://direct.evolink.ai/v1/chat/completions"
payload = {
"model": "grok-4.5",
"messages": [
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"stream": False,
"max_tokens": 1024,
"temperature": 0.7,
"top_p": 0.95,
"tools": [
{
"type": "function",
"function": {}
}
]
}
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: 'system', content: 'You are a concise assistant.'},
{role: 'user', content: 'Explain prompt caching in one sentence.'}
],
stream: false,
max_tokens: 1024,
temperature: 0.7,
top_p: 0.95,
tools: [{type: 'function', function: {}}]
})
};
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' => 'system',
'content' => 'You are a concise assistant.'
],
[
'role' => 'user',
'content' => 'Explain prompt caching in one sentence.'
]
],
'stream' => false,
'max_tokens' => 1024,
'temperature' => 0.7,
'top_p' => 0.95,
'tools' => [
[
'type' => 'function',
'function' => [
]
]
]
]),
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\": \"system\",\n \"content\": \"You are a concise assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 1024,\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {}\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\": \"system\",\n \"content\": \"You are a concise assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 1024,\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {}\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\": \"system\",\n \"content\": \"You are a concise assistant.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 1024,\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {}\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": "Prompt caching reuses previously processed prompt prefixes so repeated context is billed at a lower rate.",
"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/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 はマルチモーダルの主力エンドポイントで、テキストモデルに対しては代替アドレスとして使用されます。function ツール呼び出しのみに対応します。承認
##すべてのAPIにBearer Token認証が必要です##
APIキーの取得:
APIキー管理ページにアクセスしてAPIキーを取得してください
リクエストヘッダーに追加:
Authorization: Bearer YOUR_API_KEY
ボディ
呼び出すモデル:
| モデル ID | 位置づけ |
|---|---|
grok-4.5 | xAI の推論 + ツール呼び出しモデル、コンテキストウィンドウ 500K |
grok-4.5 "grok-4.5"
チャットメッセージのリスト。system、user、assistant のロールに対応します。
1Show child attributes
Show child attributes
[
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
]
ストリーミングでレスポンスを返すかどうか(SSE、chat.completion.chunk イベント)。デフォルトは false。
false
生成するトークンの最大数。そのままモデルに渡されます。
1024
サンプリング温度(0-2)。値を大きくすると出力がよりランダムになります。
0.7
Nucleus サンプリングのパラメータ(0-1)。
0.95
通常の OpenAI function ツール定義(クライアント側の関数呼び出し。呼び出しごとの追加料金なし)。xAI のサーバーサイドツールは Responses API のみで利用できます。
Show child attributes
Show child attributes
関数の選択を制御します:"auto" / "none" / "required"、または特定の関数を指定するオブジェクト。
auto, none, required レスポンス
チャット補完が正常に生成されました(JSON オブジェクト、または stream=true の場合は chat.completion.chunk イベントの SSE ストリーム)
チャット補完の一意の識別子
"chatcmpl-20260812164515123456789AbCdEfGh"
実際に使用されたモデル名
"grok-4.5"
レスポンスタイプ
chat.completion "chat.completion"
作成タイムスタンプ
1786538000
チャット補完選択肢のリスト
Show child attributes
Show child attributes
トークン使用統計。プロンプトが 200K トークン以上の場合、すべてのトークン種別(入力、キャッシュ入力、出力)が 2 倍で課金されます。
Show child attributes
Show child attributes