Provider profile: xAI - xAI's Grok models offer an OpenAI-compatible API for fast, real-world reasoning. Use your existing openai SDK — just change base_url to TheRouter and your code works unchanged. Grok 3 and Grok 3 Fast deliver low-latency, high-throughput production performance with dedicated reasoning modes and vision support. Unique X-platform data integration is available on select Grok models.
xAI
US6 modelsxAI Grok OpenAI-Compatible API — Real-Time Reasoning & X Platform Integration
xAI's Grok models offer an OpenAI-compatible API for fast, real-world reasoning. Use your existing openai SDK — just change base_url to TheRouter and your code works unchanged. Grok 3 and Grok 3 Fast deliver low-latency, high-throughput production performance with dedicated reasoning modes and vision support. Unique X-platform data integration is available on select Grok models.
- ✓OpenAI-compatible API — use xAI Grok via your existing OpenAI SDK, no code changes
- ✓Current Grok model lineup: Grok 4, Grok 3, Grok 3 Mini with real-time X platform integration
- ✓Dedicated reasoning variants (Grok 4.1 Fast Reasoning) and fast inference at $0.20/MTok
- ✓Vision support (Grok 4, Grok 4.1 Fast) and tool use across all models
Quickstart
Python
# xAI Grok OpenAI-compatible API via TheRouter
# Use current Grok models with your existing OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://api.therouter.ai/v1",
api_key="YOUR_THEROUTER_KEY",
)
response = client.chat.completions.create(
model="xai/grok-4",
messages=[{"role": "user", "content": "What is the current state of fusion energy?"}],
max_tokens=512,
)
print(response.choices[0].message.content)TypeScript / Node.js
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.therouter.ai/v1",
apiKey: process.env.THEROUTER_API_KEY,
});
const response = await client.chat.completions.create({
model: "xai/grok-4",
messages: [{ role: "user", content: "What is the current state of fusion energy?" }],
max_tokens: 512,
});
console.log(response.choices[0].message.content);Use the global api.therouter.ai endpoint for new integrations; the legacy China accelerated endpoint is retired.
OpenAI-Compatible API
xAI Grok via OpenAI SDK — zero code changes
Use Grok 4 and Grok 3 with your existing OpenAI client. Change only baseURL and apiKey. Streaming and tool calling work identically.
Models
Frequently Asked Questions
Is xAI Grok's API OpenAI-compatible?
Yes. TheRouter exposes xAI Grok models via a fully OpenAI-compatible API. Use the standard OpenAI SDK — just set base_url to https://api.therouter.ai/v1 and the model to xai/grok-4 (or any current Grok model). No code changes, no custom SDK.
Which xAI Grok models are available on TheRouter?
TheRouter provides Grok 4, Grok 3, Grok 3 Mini, Grok Code Fast 1, Grok 4.1 Fast Reasoning, and Grok 4.1 Fast Non-Reasoning - all via the standard xai/model-name format.
What makes xAI Grok unique? How does the X platform integration work?
Grok 4.1 Fast variants start at $0.20/MTok input - significantly lower than GPT-4o. Grok 4 is priced similarly to Claude Sonnet and GPT-4o. Check the pricing page for current rates.
Does TheRouter support Grok's reasoning mode?
Yes. Grok 4.1 Fast Reasoning and Grok 3 Mini include reasoning capabilities. Pass the standard reasoning parameter or use the dedicated reasoning model variant.