Getting programmatic access to Grok models means stepping outside the familiar grok.com chat window and into xAI’s dedicated developer infrastructure. A Grok API key is issued exclusively through the xAI Console at console.x.ai, a portal built for engineers and completely separate from the consumer-facing app millions of people use on their phones every day.
The path from zero to a working key is short but has a few non-obvious gotchas: you need an active xAI account, a properly funded team workspace, and a moment of discipline to save the key the instant it appears, because xAI never shows it to you again. Below is exactly how the process works as of late 2026, based on the current console workflow.
What You Need Before Creating a Grok API Key
Before you even open the console, a few prerequisites determine whether key creation will go smoothly or throw you into a wall of confusing errors.
You need an active xAI account, which you can register with a plain email address or, more commonly, by signing in with an existing X (formerly Twitter) account. Most developers already have an X login handy, so this is usually the faster route.
Your account also needs to sit inside an active xAI team workspace. This is the part that trips people up most. In xAI’s infrastructure, every API key, every usage log, every permission setting, and the entire payment balance belong to the team, not to your personal profile. If you’re added to someone else’s team, the keys you generate and the credits you burn belong to that team’s ledger, not your own.
You’ll also need billing credits loaded onto that workspace. xAI’s platform will not process live inference calls against an account with a zero balance, so funding needs to happen before you write a single line of integration code.
Have a secure place to store secrets open and ready before you start. A .env file, a password manager, or a secrets vault. This matters because of a hard rule in the xAI Console: once you close the key-creation modal, the full string is gone for good.
Finally, you simply need a browser pointed at console.x.ai, the correct address for all key management, billing, and usage dashboards.
How to Get a Grok API Key from xAI
Here’s the exact sequence inside the console, step by step.
1. Open the xAI Console and Sign In
Go to console.x.ai. This is a completely different product from grok.com or the Grok tab inside the X app, and it’s easy to land on the wrong one if you’re searching casually. The console is where developer-facing tools, billing, and API key management all live.
Sign in using either your linked X account or your registered email and password.
2. Set Up API Billing and Credits
Once inside, click into the Billing section in the left-hand navigation.
To actually execute requests against production endpoints, you’ll need to add a payment method and purchase a starting credit balance. New accounts sometimes see a promotional credit appear automatically in this dashboard, though the size and availability of any signup bonus changes over time and shouldn’t be assumed until you actually see it listed.
Before you write your first line of integration code, glance at your active balance. An account sitting at $0 will reject every request with a payment error, and that’s one of the most common why isn’t this working moments for first-time users.
3. Open the API Keys Page
Click the API Keys tab in the console’s main navigation.
Check the workspace selector at the top of the screen before doing anything else. Every key you generate inherits the billing status, rate limits, and permissions of whichever team is currently active. Generate a key under the wrong workspace, and you’ll end up with a token that either can’t bill correctly or can’t reach the models you expected.
4. Create and Name Your API Key
Click Create Key.
Give it a name that actually tells you something later, like production-backend-service or dev-testing-app, rather than something generic like key1. This matters more than it sounds like it should. Once you have five or six keys scattered across different projects, a clear naming convention is the only thing standing between you and a revocation mistake.
If your console view shows scope or permission toggles, set them to match what that specific key actually needs. A key meant only for read-only testing shouldn’t carry full production write access.
5. Copy and Store the Key Immediately
The console will display your full secret token, always starting with the xai- prefix.
Copy it right away using the copy button next to the field.
This is the step people regret skipping: xAI permanently masks the key the moment you close that dialog. There is no reveal button hiding somewhere in settings. If you close the modal without saving it, your only option is generating a fresh key and deleting the orphaned one.
How to Use Your Grok API Key
Once you have your key saved, using it is a matter of standard Bearer token authentication, the same pattern used across most modern AI APIs.
All requests go to the base endpoint at https://api.x.ai/v1. Every authenticated call needs this header structure:
Authorization: Bearer <YOUR_XAI_API_KEY>
To sanity-check your connection without writing a full application, run this from a terminal:
Bash
curl https://api.x.ai/v1/models \
-H “Authorization: Bearer YOUR_XAI_API_KEY”
For anything beyond a quick test, xAI maintains official SDKs that handle header formatting, retries, and streaming for you: the Python SDK (pip install xai-sdk) and the JavaScript SDK (npm install xai-sdk). Because xAI’s API surface closely mirrors the OpenAI-style chat completions format, many existing integrations built for other providers can be pointed at api.x.ai/v1 with only a base URL and key swap, which has made migration relatively painless for teams already building on similar APIs.
How to Check Whether Your Grok API Key Works
The cleanest way to validate a key is hitting the /v1/models endpoint, since listing available models costs nothing in tokens essentially while still confirming that both your authentication header and your billing status are in good standing.
Bash
curl -i https://api.x.ai/v1/models \
-H “Authorization: Bearer YOUR_XAI_API_KEY”
A working key returns an HTTP 200 OK along with a JSON payload listing the models your team currently has access to, which as of this writing includes the flagship grok-4.7, along with grok-4.6, grok-4.5, grok-4.3, and the coding-focused grok-build-0.1.
If you get back an HTTP 401 Unauthorized, the most common culprits are a missing Bearer prefix, a stray space, or a key that was copied incompletely. An HTTP 402 Payment Required response means the key itself is fine, but the team workspace behind it has run out of funded credits.
Do You Need X Premium or SuperGrok for the API?
No. An X Premium subscription or a SuperGrok plan is not required to register for or use the xAI API, and the two systems don’t share billing at all.
Consumer plans like X Premium (currently $8/month) and SuperGrok ($30/month) unlock features inside the end-user chat apps: longer conversations, DeepSearch, voice mode, and access to Grok inside the X platform itself. SuperGrok Heavy, xAI’s top consumer tier at $300/month, adds a multi-agent Heavy reasoning mode for the most demanding individual users.
None of that overlaps with developer access. The API operates on a completely separate, metered pay-per-token model managed entirely through console.x.ai, and you can build and ship a production application without ever touching a consumer subscription.
Is the Grok API Free?
Creating an API key itself costs nothing. What isn’t free is sending requests to the models, which is billed per token, input and output counted separately.
As of xAI’s current published pricing, the flagship grok-4.7 costs $2.00 per million input tokens and $6.00 per million output tokens for prompts under 200,000 tokens, with cached input priced at just $0.50 per million. Cross that 200K-token threshold in a single request, and xAI’s long-context pricing kicks in, roughly doubling the rate to $4.00 input and $12.00 output per million tokens. The coding-focused grok-build-0.1 model is cheaper, priced at $1.00 input and $2.00 output per million tokens under the same short-context tier. Mid-tier models like grok-4.3 sit at $1.25 input and $2.50 output per million tokens, making them a reasonable middle ground for teams that don’t need flagship-level reasoning on every call.
Beyond raw token costs, xAI’s server-side tools (web search, X search, code execution) each carry their own per-call fees, generally around $5 per 1,000 calls, with X Search specifically now billed by the number of posts and profiles actually fetched rather than a flat per-call rate.
New signups have historically received small promotional credits to test the waters before committing a card to real usage, though the exact size of that credit isn’t guaranteed and shouldn’t be the basis of a budget plan. It’s also worth being clear that consumer subscription spend never transfers to API usage. Paying for SuperGrok Heavy doesn’t shave a cent off your developer bill; the two ledgers are entirely separate. Anyone building at real scale should check xAI’s live Pricing page under docs.x.ai before finalizing a budget, since per-model rates have shifted more than once this year as new model versions have shipped.
Common Problems When Creating or Using a Grok API Key
Most setup friction traces back to one of a small handful of causes: wrong workspace, missing funds, or a malformed header.
If the API Keys option isn’t visible at all in your dashboard, check which team is active in the top workspace selector. You generally need an Admin or Developer role on that specific team to generate credentials; a viewer-level account won’t see the option.
When requests get rejected outright, open Billing and confirm your credit balance is actually above zero. An unfunded team will block every inbound request even when the key itself is completely valid, which is a frustrating thing to debug if you’re staring only at your code.
For persistent authentication failures, look closely at how your script builds the header. It’s surprisingly common to accidentally save a trailing space or a stray quotation mark inside an environment variable, and that alone is enough to break the Bearer token match.
If you’ve lost a key, there’s no recovery path. xAI’s masking is permanent by design, so the only fix is generating a new key and deleting the old one from the management page so it can no longer be used if it leaked somewhere.
And if errors point to wrong team specifically, it usually means the key you’re using belongs to a workspace that doesn’t have the billing or model permissions your request needs. Double-check that the key you generated actually lives under the team tied to the account you funded.
Keep Your xAI API Key Secure
A leaked API key is a direct path to unexpected charges landing on your card, so a bit of hygiene goes a long way.
Never hardcode a secret key inside a public source file, and definitely never push one to a public GitHub repository. This sounds obvious, but it remains one of the most common ways developer credentials end up exploited within hours of exposure.
Load your key through environment variables like XAI_API_KEY, or route it through a proper secrets manager if you’re working inside a larger organization.
Avoid calling xAI’s endpoints directly from client-side browser code or from inside a public mobile app bundle. Anyone who inspects network traffic or decompiles the app can pull the key straight out. Route all model calls through a backend server you control, and let that server hold the credential.
It’s also good practice to keep separate keys for development and production. That way, a compromised dev key doesn’t put your live application at risk, and you can revoke one environment’s access without disrupting the other.
If a key does get compromised, don’t wait. Go straight to console.x.ai, find the token under API Keys, and hit Revoke or Delete immediately, then generate its replacement.
Managing your Grok account and API access also means knowing how to control your subscription, protect your data, and make the most of xAI’s features. These related articles cover the key details:
- How to Cancel a Grok Subscription on Any Device
- How to Delete Your Grok xAI Account
- Grok Context Window 2026: Token Limits for Every Model
- Does Grok xAI Have Video Generation? Features and Limits
Frequently Asked Questions About Grok API Keys
Where do I get a Grok API key?
You generate one through the official developer console at console.x.ai, under the API Keys management page, after setting up an account and a funded team workspace.
Is a Grok API key the same as an X API key?
No. A Grok API key authenticates requests to xAI’s language models via api.x.ai, while an X API key authenticates requests to the social media platform’s own endpoints, like posting and reading user profiles, via api.x.com. They’re issued by different systems and aren’t interchangeable.
Do I need X Premium to use the Grok API?
No. Developer access runs entirely through the xAI Console on a pay-as-you-go basis and has no dependency on an X Premium subscription.
Does the Grok API have a free tier?
xAI doesn’t maintain a permanent free usage tier for the API, though new developer accounts have periodically received small promotional starting credits to test endpoints before adding a card. Availability of any such credit can change, so check your console dashboard directly rather than assuming one will appear.
What should I do if I lose my xAI API key?
Since xAI masks key strings permanently after the first display, a lost token cannot be recovered. Revoke it inside the console and generate a fresh replacement right away.
Where should I store my xAI API key?
Keep it inside a secure local .env file, a server-side environment variable, or an encrypted secrets management service, never in plain text inside a repository or client-facing code.