GROK API 2026 — QUICK START
● Base URL: https://api.x.ai/v1
● Models: grok-4, grok-4-mini, grok-imagine-v2
● Authentication: Bearer token in headers
● Features: Streaming, tool calling, vision, DeepSearch integration
Getting Started
1. Get your API key from the xAI Console.
2. Install the official SDK or use HTTP requests.
3. Set the Authorization header with your Bearer token.
Python Example
from openai import OpenAI
client = OpenAI(
api_key="xai-your-key-here",
base_url="https://api.x.ai/v1"
)
response = client.chat.completions.create(
model="grok-4",
messages=[{"role": "user", "content": "Explain how Grok API works"}],
temperature=0.7,
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="")
Key Features in 2026
• Tool calling & function calling
• Vision capabilities (image understanding)
• Image generation via Grok Imagine endpoints
• DeepSearch integration for real-time web data
• Streaming responses for better UX
• Structured outputs (JSON mode)
Best Practices
• Use appropriate models for your use case (grok-4 for best quality, grok-4-mini for speed/cost)
• Implement proper error handling and retries
• Respect rate limits and implement exponential backoff
• Store API keys securely using environment variables
Updated July 2026 · Grok by xAI