中文

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.grok.cadn.net.cn

Ready to start building? Head to the Hitchhiker's Guide to Grok for a step-by-step introduction.grok.cadn.net.cn



Unlock the Universe's Secrets

To access Grok models via API, you must create an xAI account and an API key. grok.cadn.net.cn

The xAI API is compatible with both the OpenAI and Anthropic SDKs. It takes just three lines of code to switch to using Grok.grok.cadn.net.cn

Just change the base_url, api_key, and model, and you're all set!grok.cadn.net.cn

OpenAI SDKgrok.cadn.net.cn

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 SDKgrok.cadn.net.cn

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.grok.cadn.net.cn


If you have any questions or feedback, feel free to email us at support@x.ai.grok.cadn.net.cn

Happy Grokking! 😎grok.cadn.net.cn