Getting Started
Welcome
Welcome to the xAI developer docs! Our API makes it easy to harness Grok's intelligence in your projects. Grok is our flagship AI model designed to deliver truthful, insightful answers.
Ready to start building? Head to the Hitchhiker's Guide to Grok for a step-by-step introduction.
Featured Models
Our flagship LLM that delivers unfiltered insights and raw intelligence.
Our latest image-understanding LLM that excels at processing diverse visual inputs like documents and photos.
Quick reference
Migrating from another LLM provider?
The xAI API is compatible with both the OpenAI and Anthropic SDKs. It takes just three lines of code to switch to using Grok.
Just change the base_url
, api_key
, and model
, and you're all set!
OpenAI SDK
from openai import OpenAI
client = OpenAI(
api_key=XAI_API_KEY,
base_url="https://api.x.ai/v1",
)
completion = client.chat.completions.create(
model="grok-2-latest",
...
)
Anthropic SDK
from anthropic import Anthropic
client = Anthropic(
api_key=XAI_API_KEY,
base_url="https://api.x.ai",
)
For more details, see Migration from Other Providers.
Questions and feedback
If you have any questions or feedback, feel free to email us at support@x.ai.
Happy Grokking! 😎