Modellix cover: two-line title Grok API Keys and Two Ways to Sign a Request over a glass auth header stack split between an amber console key and a cyan gateway key, MODELLIX wordmark

There are two legitimate ways to get a working set of Grok API keys, and only one of them requires an xAI account. The official route is the console: sign up, load the account with credits, and generate a key on the “API Keys” page (xAI quickstart). The other route is a gateway key — a credential issued by an aggregator that already holds vendor access and fronts the same model under its own authentication, so no xAI account is created at all. Both produce a string you paste into a header. Nothing about the model changes.

Every figure and endpoint below was read from a first-party page on September 16, 2026, and the model name is the one live that day: grok-4.6, the current flagship, priced at $2.00 per million input tokens and $6.00 per million output tokens (xAI models page, x.ai/api). One disclosure before the walkthrough: we run Modellix, a model gateway, so we have a commercial interest in the second route. It is not cheaper — on xai/grok-4.6 our catalogue price is identical to the vendor’s own rate — and we will say so again where it matters.

What a Grok API key is, and what it is not

A Grok API key is a bearer credential that authorises requests to xAI’s own API host. That is the whole definition, and it is worth stating plainly because the most common way to end up with the wrong key takes exactly one letter to do — and because the answer to how to get a Grok API key depends entirely on which of two consoles you want a relationship with.

Grok is not Groq. They are separate companies with separate consoles, separate hosts, and separate credentials. Groq is a separate company selling fast LLM inference, and it issues keys from console.groq.com for a service it calls GroqCloud (Groq docs), read into an environment variable named GROQ_API_KEY (Groq quickstart). xAI builds Grok, issues keys from the xAI console, and its quickstart exports XAI_API_KEY. This is not a pedantic distinction: on the day this article was written, a GroqCloud key page was ranking second in Google for “grok api keys”, above xAI’s own API landing page. The search result itself is part of the trap.

So the first question to ask about any key you are handed is not “is it valid” but “which console issued it”. Everything else — the host, the header, the billing account your request hits — follows from that answer.

The second thing a Grok API key is not: a licence. It authorises; it does not entitle. A key with a zero balance authenticates perfectly and still fails, which is why the console route starts with a top-up rather than a key.

If you want Grok for images and video rather than text, that is the same console and a different product line — our Grok Imagine API walkthrough covers the async image and video endpoints, which work on a submit-then-poll cycle rather than the synchronous text call described here.

Path A: create the key in the xAI console

This is the source-of-truth route and the one to take if you need xAI’s own account relationship — for billing, for team management, or because your procurement requires a direct vendor contract.

  1. Create the account, and note where you will log in later. Sign up at console.x.ai — that same host is the Grok API login for every return visit, with ?mode=sign-up selecting the registration form. The console describes itself as “your gateway to the Grok API and developer tools for building with AI”, and as of September 16, 2026 it brands itself SpaceXAI on both the sign-in page and the API landing page, so a name you do not recognise there is not a wrong turn.
  2. Load the account with credits first. The quickstart is explicit that this precedes your first call: sign up, “then load it with credits to start using the API” (xAI quickstart). Neither page publishes an API credit allowance, so read carefully when a tutorial promises you free Grok calls. There is a free element in this product, and it is Playground access rather than API calls: the landing page offers a playground “to test the latest models before you write any integration code”, then states that “API usage is billed per token” (x.ai/api).
  3. Open the API Keys page and create a key. The landing page condenses the flow to three steps — sign up, create a key on the “API Keys” page, set your base URL to https://api.x.ai/v1 (x.ai/api). The Grok API console’s own capability list for that page is “Create, rotate, and revoke keys” (console.x.ai), which is also where you rotate or revoke one later.
  4. Export it, do not paste it. The quickstart’s convention is export XAI_API_KEY="your_api_key", or a .env file next to your project. Both are better than a shell history entry.
xAI quickstart: Step 1 create an account and load credits, Step 2 generate an API key and export it as XAI_API_KEY, captured September 16, 2026

The prerequisite order, from xAI’s own quickstart: the account comes first, the credits come before the first call, and the key is generated on the “API Keys” page and exported as XAI_API_KEY. Captured from docs.x.ai/developers/quickstart on September 16, 2026 — the console pages themselves sit behind a sign-in wall, so the documented flow is the verifiable version.

Path B: call Grok 4.6 without an xAI account

A gateway key is not a workaround and it is not a scraped token. It is a key issued by a company that has its own vendor agreement and resells access under a single credential. We operate one, which is the commercial interest disclosed above, and the honest version of the trade is this: you are not buying a cheaper token, you are buying one fewer account.

The mechanics are a base-URL swap. On the Modellix LLM gateway the host is https://llm.modellix.ai with a /v1 path prefix, and the credential is a key from the Modellix console — explicitly “not a vendor platform key” (LLM API guide). Models are addressed as provider/name, so Grok 4.6 is xai/grok-4.6, and the catalogue also carries a ~xai/grok-latest alias that follows the newest release in that series (Modellix LLM overview). On September 16, 2026 that catalogue held 30 text models across nine provider labels, and exactly two of them were xAI rows — xai/grok-4.5 and xai/grok-4.6. The previous generation has already left the list, which is worth knowing before you go looking for it here.

Modellix LLM catalogue filtered to xAI rows: Grok 4.6, 500k context, image input, 2.00 input and 6.00 output dollars per million tokens

The gateway’s own row for the vendor’s flagship. There is one figure per cell because the list price and the billed price are the same number, and the Discount column carries a dash to say so — on this model there is no discount to compare against. Captured from modellix.ai/llm on September 16, 2026.

Two limits worth knowing before you choose this path. First, the gateway returns text: the same key also reaches the image, video and speech endpoints on a second host, api.modellix.ai, and those run as asynchronous tasks (media API guide) — the boundary the LLM API guide states plainly: “Do not mix that host with the LLM gateway.” Second, a gateway is one more party in the request path — if your project needs a direct vendor contract or xAI-side team controls, Path A is the right answer regardless of convenience.

Grok 4.6 on the Modellix LLM gateway

Base URLs, supported protocols, the xai/grok-4.6 model ID, error codes and token billing for one-key access to Grok.

View Docs

Which key goes in which header

This is where “my key does not work” usually starts. Whichever credential you are holding — an xAI API key from the console, a gateway key, or a Groq key from a company you did not mean to sign up with — the failure is almost always that the header belongs to a different service than the key.

Route Base URL Header the request carries Env var convention
xAI, direct https://api.x.ai/v1 Authorization: Bearer <key> XAI_API_KEY
Modellix LLM gateway https://llm.modellix.ai/v1 Authorization: Bearer <key> or x-api-key: <key> OPENAI_API_KEY on OpenAI-compatible clients
Groq (a different company) GROQ_API_KEY

On the gateway, the two header styles are equivalent — “both headers are equivalent. If both are sent, they must be the same key” — and sending a Bearer value that disagrees with the x-api-key value is itself a 401 cause, not a tie-break. Base URL is the variable that decides which of these three tables your key lands in, which is the same mechanism behind our notes on switching the Anthropic base URL — change the host, and the credential, the billing account and the model namespace all change with it. Your first request on either route looks like this:

1
2
3
4
curl https://api.x.ai/v1/responses \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "grok-4.6", "input": "Explain what a bearer token is in one sentence."}'

That is the shape the quickstart itself uses, down to the /v1/responses path and the input field rather than messages. If you are switching to the gateway, change the host and the model string to xai/grok-4.6 and keep everything else.

Grok API pricing: what the key costs, and the 200k cliff

The key is free. The tokens are not, and the rate card has a step in it that catches people who scan only the first column.

Model Context Short-context input / cached / output (per 1M) Long-context (≥200k prompt) input / cached / output
grok-4.6 500k $2.00 / $0.50 / $6.00 $4.00 / $1.00 / $12.00
grok-4.5 500k $2.00 / $0.30 / $6.00 $4.00 / $0.60 / $12.00
grok-4.3 1M $1.25 / $0.20 / $2.50 $2.50 / $0.40 / $5.00

Figures read from xAI’s own pricing page on September 16, 2026 (docs.x.ai/developers/pricing). The step is not a surcharge on the tokens above the threshold. The page’s own note is worth quoting in full:

Models with long context pricing bill the long context rates for all tokens in a request once its prompt reaches the model’s long context threshold.

In plain numbers: a 199,000-token prompt on grok-4.6 bills at $2 per million input tokens, and a 201,000-token prompt bills the entire 201,000 at $4. The rate doubles at that boundary, so crossing it by a single token — 199,000 tokens at $0.398 against 201,000 at $0.804 — raises the cost of the whole request by about 102%.

xAI price table with the grok-4.6 row outlined: 2.00, 0.50 and 6.00 dollars short context against 4.00, 1.00 and 12.00 long context

The vendor’s own rate card with the grok-4.6 row outlined. The long-context columns are the ones to read before you ship a retrieval pipeline — a prompt that crosses 200,000 tokens reprices every token in the request, not just the excess. Captured from docs.x.ai/developers/pricing on September 16, 2026.

Two more lines from the same page that do not fit a table cell: requests to the US regional endpoint bill at 1.1× the global token rates, and cached input is a separate, cheaper lane — $0.50 per million on grok-4.6 short context, $1.00 long. If your workload reuses a long system prompt, the cache column is where the real comparison lives.

On the gateway that same row reads $2.00 / $0.50 / $6.00 short context and $4.00 / $1.00 / $12.00 long, with the vendor’s list price and the billed price identical — the discount column is empty, which is the specific sense in which this is not a pricing pitch. Across the rest of the catalogue, gateway rows do carry discounts against vendor list prices; on Grok 4.6 there is nothing to sell you, and pricing the whole catalogue in one place is a separate exercise covered in our cross-vendor LLM price comparison.

Turn on one Grok key

Create a key in the Modellix console and call xai/grok-4.6 alongside the rest of the text gateway with one credential.

Login

When the key stops working: 401 and its neighbours

Most “invalid key” reports are one of five things, and the status code narrows it immediately.

Status What it means on an API route What to check first
400 Malformed request — and on xAI’s own table, an incorrect API key The request body first, then the key
401 Missing or invalid key; on the gateway, also conflicting auth headers That the key came from the console you think it did, and that you did not send two disagreeing headers
402 Authenticated but unfunded — the account has no balance The billing page, before the key. Worth knowing that xAI’s own error table does not list 402 at all
403 Key accepted, action refused — the key or its team lacks permission, or is blocked Your team’s role and the key’s scope, not the key’s spelling
404 Key accepted, resource missing — unknown model string, or a misspelled endpoint URL The model ID, including the provider/ prefix on a gateway, then the path
429 Rate limit, or the model is temporarily unavailable Retry with backoff rather than rotating the key
5xx Upstream error Retry; it is not a credential problem

The gateway’s own error table maps these to the same causes — 401 for a missing or invalid key or conflicting auth headers, 402 with an insufficient_quota type for an empty balance — and it is the fastest way to tell a credential problem from a funding problem (LLM API guide). xAI draws the same line on the direct route, and its own error reference is the place to check the rest: 401 is a key problem, 403 is a permissions problem for your team to solve, and 404 is the model name.

Keeping it out of your repository

Three habits, in order of how much time they save.

Never inline the key. Both routes have an environment-variable convention — XAI_API_KEY on the direct route, OPENAI_API_KEY on the gateway when an OpenAI-compatible client is doing the reading — and both beat a literal in a source file. A key pasted into a notebook, a screenshot, or a support thread should be treated as compromised the same day.

Rotate on a schedule, not on an incident. The console supports rotation and revocation as first-class actions, which means a rotation is a two-minute task rather than a refactor. Newer keys in, older keys revoked, one deploy.

Know what an alias buys you. On the xAI side, <modelname> follows the latest stable release, <modelname>-latest follows the newest version including anything not yet settled, and <modelname>-<date> pins one release and never moves (models page). The gateway carries the same idea as ~provider/series-latest. Pinning is for reproducibility; following is for defaults. Pick per environment, not per preference — and if you are building the habit of holding one key for several vendors, a sibling walkthrough like our Nano Banana API key guide runs the same sequence against a different model family.

Modellix LLM latest model ID routing table with the tilde xai grok latest row outlined, routing it to xai slash grok-4.6

A version-following alias is only as safe as its routing table. ~xai/grok-latest resolves to xai/grok-4.6, and that is the line to re-read after any model release. Captured from modellix.ai/llm on September 16, 2026.

How to choose

If your main reason is Start with Because
A direct vendor relationship, xAI-side team management, or invoice-based billing Path A, the xAI console The account is the deliverable, and the credits prerequisite is part of it
Calling Grok next to other vendors’ models from one credential Path B, a gateway key One key and one bill across model families; the per-token rate on Grok 4.6 is unchanged
Cheapest possible Grok tokens Neither, yet Both routes bill the same rate card for grok-4.6; the lever is prompt shape — stay under the 200k threshold and use the cached lane

Whichever you pick, do one thing before you build on it: send a single request with the model string you intend to ship, and log the model field that comes back. That one line tells you which route answered and which version actually served you, and it is the difference between debugging a key and debugging an assumption.

Frequently Asked Questions About Grok API Keys

Are Grok API keys free?

The key itself costs nothing on either route — you are never billed for the credential, only for the tokens a request consumes. So “free grok api key” is true about the key and false about the usage. What differs is the prerequisite: xAI’s quickstart tells you to load credits before your first call and publishes no API credit allowance, while a gateway key needs a funded gateway balance instead. Treat any claim of free unlimited Grok calls as a claim about someone else’s quota, not about your key.

How do I get a Grok API key?

Two documented routes. Create an xAI account at console.x.ai, load it with credits, and generate a key on the API Keys page; or create one key in a gateway console and call xai/grok-4.6 on https://llm.modellix.ai/v1 without ever registering with xAI.

What do Grok API keys cost to use?

Nothing per key, and $2.00 per million input tokens and $6.00 per million output tokens for grok-4.6 while the prompt stays under 200,000 tokens. Over that line the long-context rates apply to every token in the request: $4.00 in and $12.00 out.

Why does my xAI key work in one tool and fail in another?

Because the tool is pointed at a different service. A 401 on a valid key most often means the base URL belongs to another host, or the client is sending x-api-key where a Bearer token is expected — and on a gateway, two disagreeing auth headers are their own 401 cause. Check the host first, then the header, then the key.

Is a Grok API key the same as a Groq API key?

No. Groq and xAI are separate companies with separate consoles and separate credentials — GROQ_API_KEY against XAI_API_KEY — and a key from one will not authenticate against the other. The names differ by one letter, which is why this is the most common wrong-key report in the first place.

Will my key keep working when xAI ships the next Grok version?

Only if you asked it to. A dated model string pins one release; on xAI’s side <modelname> tracks the latest stable release while <modelname>-latest tracks the newest version even before it settles, and ~provider/series-latest does the same job on a gateway. Version-following behaviour is a configuration decision, so check which form is in your code before an upgrade surprises you.


Endpoints, model names and per-token rates change without notice, and every figure in this guide was read from first-party pages on September 16, 2026 — xAI’s quickstart, models, pricing and error-reference pages, the API landing page at x.ai/api, the xAI console, Groq’s documentation, and the Modellix LLM docs. Re-check the xAI rate card and the xAI model list before committing spend. Modellix is an API gateway with a commercial interest in the gateway route described above; on xai/grok-4.6 its billed price equals xAI’s own published rate, so the argument for it is one credential across many models rather than a lower bill, and it is not affiliated with xAI. Route text models through one key at modellix.ai.