Grok family
xAI’s Grok models, including the reasoning models Grok 4.7, 4.6, 4.5, and 4.3, and the non-reasoning models Grok 4.1 Fast and 4.20. Called through the OpenAI-compatible API.
Common tasks
Models
For the full model list and live prices, see the models page . Model IDs have the prefix x-ai/, which can be omitted.
x-ai/grok-4.7Reasoning model, 500K contextx-ai/grok-4.1-fastNon-reasoning, 2M context, image supportEndpoint support
Grok models are provided by xAI directly (grok), and some models also have Azure AI Foundry as a provider.
Examples
Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"])
resp = client.chat.completions.create(
model="x-ai/grok-4.7",
reasoning_effort="low",
messages=[{"role": "user", "content": "Explain idempotency in one sentence."}],
)
print(resp.choices[0].message.content)
print("Reasoning tokens:", resp.usage.completion_tokens_details.reasoning_tokens)Reasoning
Measured on the same math problem: by default Grok 4.7 used about 15,000 reasoning tokens and took about 4 minutes; with reasoning_effort: "low", it used about 4,200 tokens and took about 1 minute. Reasoning tokens are billed at the output rate, and their count is in usage.completion_tokens_details.reasoning_tokens; reasoning content is in delta.reasoning_content of the streaming response.
Other features
- Image input: supported by Grok 4.3, 4.20, and 4.1 Fast, using standard
image_urlcontent blocks; see Vision for the format. - Structured output and tool calling:
response_formatsupportsjson_schema; tool calling uses the standardtoolsparameter. - Caching: repeated request prefixes are cached automatically; the hit count is in
usage.prompt_tokens_details.cached_tokens.
Common errors
For other general errors, see Error handling.
Official docs
FAQ
How do I write Grok model IDs?
The standard form is x-ai/grok-4.7; you can also omit the prefix and write grok-4.7. Writing xai/grok-4.7 returns 404.
Why is Grok 4.7 so slow?
Grok 4.7, 4.6, and 4.5 always reason, and complex questions may use more than ten thousand reasoning tokens and take several minutes. Passing reasoning_effort: "low" shortens this significantly, or switch to the non-reasoning Grok 4.1 Fast.
Can reasoning be turned off for Grok?
Reasoning cannot be turned off for Grok 4.7, 4.6, 4.5, or 4.3; you can only reduce it with reasoning_effort. For fast responses, use Grok 4.1 Fast.
Can Claude Code use Grok?
Only Grok 4.3 supports the Anthropic API; calls to other Grok models return protocol_not_supported.
How long a context does Grok support?
Grok 4.1 Fast and 4.20 support 2M tokens, Grok 4.3 supports 1M, and Grok 4.7, 4.6, and 4.5 support 500K.