How to get a Grok (xAI) API key
Updated · 3 min read
A Grok API key lets apps use xAI's Grok models on your own xAI account, billed per token from credits you buy. It comes from the xAI console at console.x.ai. (xAI's developer docs now appear under the SpaceXSI name; the console and API addresses are unchanged.) Searching for a free Groq key instead? That's a different company with a free plan: see the Groq API key guide.
Step by step
- Create an account at console.x.ai. Keys and credits belong to a team; make sure you are in the team you want to pay from.
- Buy credits. Open Billing → API spend management and buy prepaid credits by card (bank transfers take 2-3 business days). The same page shows your balance and has a field for promo codes.
- Create a key on the API Keys page and copy it.
- Add it to your app. Pick xAI or Grok in the app's provider list. If there is none, add a custom OpenAI-compatible provider with base URL
https://api.x.ai/v1.
Is there a free Grok API?
Not today. On 2026-10-29 xAI's docs described two ways to pay, prepaid credits and monthly invoiced billing (on request through sales), and no free tier, free models or free monthly credits. Sites that promise "free Grok API keys" are sharing someone else's key or running a scam; a leaked key can be revoked at any moment, and it hands your prompts to a stranger's account.
If you want to try BYOK apps without paying, use a key that really is free, such as the Gemini free tier, Groq's free plan or OpenRouter's free models. See free AI API keys for the full list.
What it costs
Prices per million tokens on xAI's pricing page, 2026-10-29:
| Model | Context | Input | Cached input | Output |
|---|---|---|---|---|
| grok-4.7 (flagship) | 500K | $2.00 | $0.50 | $6.00 |
| grok-4.3 | 1M | $1.25 | $0.20 | $2.50 |
| grok-4.20 (reasoning and non-reasoning) | 1M | $1.25 | $0.20 | $2.50 |
| grok-build-0.1 (coding) | 256K | $1.00 | $0.20 | $2.00 |
Once a prompt reaches 200K tokens, the whole request is billed at double these rates. Requests to xAI's US regional endpoint cost 10% more.
For a chat turn of about 2,000 tokens in and 500 out, grok-4.3 costs around $0.004 (more than 1,000 turns for $5) and grok-4.7 about $0.007. Repeated context that hits the cache is billed at the cheaper cached rate.
Keep the bill under control
- Prepaid credits are a natural cap. With the default $0 invoiced billing limit, xAI rejects requests once your credits run out instead of charging your card.
- Auto top-up buys more credits when your balance drops below a threshold (minimum $5 per top-up). If you turn it on, also set the maximum total of top-ups per month.
- One key per app, so you can revoke a single key without breaking the others.
- Keep keys out of shared documents and public code, and delete keys you no longer use.
- Watch the Usage explorer in the console to see which app spends what.
Apps that work with your Grok (xAI) API key
Direct key or a gateway?
A direct xAI key gives you xAI's own prices, billing controls and xAI-only tools such as X Search. If you use Grok next to GPT, Claude and Gemini, an OpenRouter key covers all of them from one balance.
Questions
Is the Grok API free?
No. On 2026-10-29 xAI's docs described only paid use: prepaid credits (the usual way) or monthly invoicing. There is no free tier or free monthly allowance in the docs. If you have a promo code, you can redeem it on the console's Billing page.
Does a SuperGrok or X Premium subscription include API access?
xAI's API docs don't list app subscriptions as a way to pay for the API. API usage is paid from your console team's credits or invoice.
Is Grok the same as Groq?
No. Grok (with a k) is xAI's model family. Groq (with a q) is a different company that runs open models fast and has a free plan; see our Groq API key guide.
What base URL do apps need for Grok?
https://api.x.ai/v1. The API works with OpenAI's SDKs, so apps that accept a custom OpenAI-compatible endpoint can use Grok with that URL and your xAI key.
Which Grok model should I pick?
grok-4.7 is xAI's flagship for code and chat ($2 input / $6 output per million tokens). grok-4.3 costs less ($1.25 / $2.50) and has a 1M-token context window.
Sources
Checked against the providers' own documentation on 2026-10-29. Prices and limits change; the links below have the current figures.