xAI API: Your First Call

Harry · 15 Oct 2026 · 4 views
Log in to track your progress and mark lessons complete.

API request flow

Why Developers Care

The xAI API speaks the OpenAI chat-completions format, so existing code migrates by changing the base URL and key. You also get Grok-only models with live search and reasoning.

First Call

curl https://api.x.ai/v1/chat/completions \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "grok-3-mini", "messages": [{"role": "user", "content": "Summarize recursion in one tweet"}]}'

Practical Rules

Keep keys server-side, never in shipped apps. Pin model versions in production. Log tokens per feature from day one so one runaway loop cannot surprise your bill.

Share this post:
AI caption:

Comments (0)

Please login or register to comment.
FREE FOREVER • NO CREDIT CARD

Learn faster with your free account

Join GroovyGrails and unlock everything a guest can't do.

🎓
Earn certificates
Pass quizzes and download verified PDF certificates.
📊
Track your progress
Resume tutorials where you left off, from your dashboard.
🔖
Bookmark & comment
Save tutorials for later and join the discussion.
🚀
Training & updates
Request live training and get new-lesson alerts.
📚 100+ tutorials📝 1000+ lessons💚 100% free
or continue with your account below

🙋 Register Free

Takes 30 seconds. You've enjoyed 3 free tutorials!

Already have an account?