Skip to content

Grok (xAI) Text Generation ​

Grok is xAI's large language model series, fully OpenAI-compatible, so you can migrate existing OpenAI apps with zero code changes. It supports up to 500k token context and image understanding.

Endpoint ​

POST $URL/v1/chat/completions

Supported Models ​

ModelDescriptionContext
grok-4.6Flagship, strongest overall capability and speed500k
grok-4.5Previous flagship500k

Parameters ​

ParamTypeRequiredDescription
modelstringyesModel name above
messagesarrayyesConversation messages; system/user/assistant can be mixed in any order
streambooleannoStream the response, default false
temperaturenumbernoSampling temperature 0–2
max_tokensintegernoMax tokens to generate
tools / tool_choicearray / stringnoFunction calling
response_formatobjectnoStructured outputs (e.g. {"type":"json_object"})
imagestring / objectnoImage input (passed in message content as image), jpg/png, ≤ 20MiB each

Request Example ​

bash
curl $URL/v1/chat/completions \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.6",
    "messages": [
      {"role": "user", "content": "Introduce yourself in one sentence"}
    ]
  }'
python
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="$URL/v1")
resp = client.chat.completions.create(
    model="grok-4.6",
    messages=[{"role": "user", "content": "Introduce yourself in one sentence"}],
)
print(resp.choices[0].message.content)

Billing Notes ​

  • Billed by actual usage (input / output / cached input priced separately); see the Console "Model Market" for unit prices;
  • Long-context tiers: once a request's prompt reaches 200k tokens, all tokens of that request are billed at the long-context rate (even if the completion itself is short);
  • Cached input tokens are billed at a discounted rate; there is no separate cache-write fee;
  • Reasoning tokens are billed as output usage.

Notes ​

  • logprobs / top_logprobs are not supported and are silently ignored;
  • Grok's knowledge is cut off at training time; enable search tools in the request for real-time information (billed per upstream usage).

© 2026 Euno AI. All rights reserved.