curl --request POST \
--url https://direct.evolink.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-4.7",
"messages": [
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"reasoning_effort": "xhigh",
"max_tokens": 2048,
"prompt_cache_key": "grok-session-001"
}
'import requests
url = "https://direct.evolink.ai/v1/chat/completions"
payload = {
"model": "grok-4.7",
"messages": [
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"reasoning_effort": "xhigh",
"max_tokens": 2048,
"prompt_cache_key": "grok-session-001"
}
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.7',
messages: [{role: 'user', content: 'Explain prompt caching in one sentence.'}],
reasoning_effort: 'xhigh',
max_tokens: 2048,
prompt_cache_key: 'grok-session-001'
})
};
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.7',
'messages' => [
[
'role' => 'user',
'content' => 'Explain prompt caching in one sentence.'
]
],
'reasoning_effort' => 'xhigh',
'max_tokens' => 2048,
'prompt_cache_key' => 'grok-session-001'
]),
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.7\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"reasoning_effort\": \"xhigh\",\n \"max_tokens\": 2048,\n \"prompt_cache_key\": \"grok-session-001\"\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.7\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"reasoning_effort\": \"xhigh\",\n \"max_tokens\": 2048,\n \"prompt_cache_key\": \"grok-session-001\"\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.7\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"reasoning_effort\": \"xhigh\",\n \"max_tokens\": 2048,\n \"prompt_cache_key\": \"grok-session-001\"\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-20260812164515123456789AbCdEfGh",
"model": "grok-4.7",
"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 All-Model API - Chat Completions Reference
- OpenAI-compatible Chat Completions endpoint for xAI Grok text models; pick the model via the
modelparameter (see the table on themodelparameter for all values) - 500K-token context window; prompts of 200K tokens or more are billed at 2x for all token types
- Prompt caching is automatic: cached prompt tokens are billed at the lower cached-input rate
- Synchronous and streaming (SSE) modes
- Regular
functiontool calling is supported; for server-side tools such as web search and X search, use the 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.7",
"messages": [
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"reasoning_effort": "xhigh",
"max_tokens": 2048,
"prompt_cache_key": "grok-session-001"
}
'import requests
url = "https://direct.evolink.ai/v1/chat/completions"
payload = {
"model": "grok-4.7",
"messages": [
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
],
"reasoning_effort": "xhigh",
"max_tokens": 2048,
"prompt_cache_key": "grok-session-001"
}
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.7',
messages: [{role: 'user', content: 'Explain prompt caching in one sentence.'}],
reasoning_effort: 'xhigh',
max_tokens: 2048,
prompt_cache_key: 'grok-session-001'
})
};
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.7',
'messages' => [
[
'role' => 'user',
'content' => 'Explain prompt caching in one sentence.'
]
],
'reasoning_effort' => 'xhigh',
'max_tokens' => 2048,
'prompt_cache_key' => 'grok-session-001'
]),
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.7\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"reasoning_effort\": \"xhigh\",\n \"max_tokens\": 2048,\n \"prompt_cache_key\": \"grok-session-001\"\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.7\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"reasoning_effort\": \"xhigh\",\n \"max_tokens\": 2048,\n \"prompt_cache_key\": \"grok-session-001\"\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.7\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain prompt caching in one sentence.\"\n }\n ],\n \"reasoning_effort\": \"xhigh\",\n \"max_tokens\": 2048,\n \"prompt_cache_key\": \"grok-session-001\"\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-20260812164515123456789AbCdEfGh",
"model": "grok-4.7",
"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, which has better support for text models and long-lived connections. https://api.evolink.ai is the primary endpoint for multimodal services and serves as a fallback address for text models.function calls. For server-side tools (web search, X search, code execution, attachment search, and collections search), use the Responses API, which includes tool configuration and billing details.Using Grok 4.7
Setmodel to grok-4.7 and keep the existing messages request format. The context window is 500,000 tokens, and the knowledge cutoff is May 2026.
Use the top-level reasoning_effort parameter. Reasoning depth: low / medium / high (default) / xhigh. Reasoning cannot be disabled. grok-4.7 and grok-4.6 support xhigh; grok-4.5 accepts it but treats it as high. Reasoning tokens are billed as output tokens.
prompt_cache_key provides a stable cache routing hint for requests sharing a prompt prefix; it does not guarantee a cache hit. Check usage.prompt_tokens_details.cached_tokens for actual hits. To preserve encrypted reasoning across turns, use the Responses API.Authorizations
##All APIs require Bearer Token authentication##
Get API Key:
Visit API Key Management Page to get your API Key
Add to request header:
Authorization: Bearer YOUR_API_KEY
Body
Model to call:
| Model ID | Positioning |
|---|---|
grok-4.7 | xAI reasoning and tool-use model; 500K-token context window; supports xhigh; knowledge cutoff: 2026-05 |
grok-4.6 | xAI reasoning + tool-use model, 500K context window; adds the xhigh reasoning level; knowledge cutoff 2026-02-01 |
grok-4.5 | xAI reasoning + tool-use model, 500K context window; reasoning levels up to high (xhigh is accepted but downgraded to high) |
grok-4.7, grok-4.6, grok-4.5 "grok-4.7"
List of chat messages. Supports system, user, and assistant roles.
1Show child attributes
Show child attributes
[
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain prompt caching in one sentence."
}
]
Whether to return a streaming response (SSE, chat.completion.chunk events). Default false.
false
Maximum number of tokens to generate.
1024
Reasoning depth: low / medium / high (default) / xhigh. Reasoning cannot be disabled. grok-4.7 and grok-4.6 support xhigh; grok-4.5 accepts it but treats it as high. Reasoning tokens are billed as output tokens.
low, medium, high, xhigh Sampling temperature (0-2). Higher values produce more random output.
0.7
Nucleus sampling parameter (0-1).
0.95
This page documents regular OpenAI function tool definitions (client-side function calls with no server-side tool-call fee). See the Responses API for server-side tool configuration and usage, including web search and X search.
Show child attributes
Show child attributes
Controls function selection: "auto" / "none" / "required", or an object pinning a specific function.
auto, none, required Optional cache routing key. Use a stable value for requests in the same conversation or sharing the same prompt prefix to improve the chance of a cache hit. Hits are not guaranteed, and cache billing rules do not change. Check cached_tokens in usage for actual cache hits.
"grok-session-001"
Response
Chat completion generated successfully (JSON object, or an SSE stream of chat.completion.chunk events when stream=true)
Unique identifier for the chat completion
"chatcmpl-20260812164515123456789AbCdEfGh"
Model name actually used
"grok-4.7"
Response type
chat.completion "chat.completion"
Creation timestamp
1786538000
List of chat completion choices
Show child attributes
Show child attributes
Token usage statistics. Prompts of 200K tokens or more are billed at 2x for all token types (input, cached input, output).
Show child attributes
Show child attributes