Grok API key: getting an xAI key and calling Grok 4.7 through a gateway
Two routes to Grok: an xAI console key, or a gateway key paid by SBP, MasterCard or crypto. Steps, a request example and what it costs.
5 min · · API keys · models
You need a grok api key and you are not sure where to get it or how much you will pay. There are two routes: create an account in the xAI console and use the official API, or take a single gateway key and call Grok the same way as Claude or GPT. Below, both routes step by step, an answer to the free-access question, working code and a cost calculation.
For the xAI console we relied on its documentation (docs.x.ai, Quickstart section) as of October 18, 2026. Account terms, regions and payment methods are set by xAI itself, so verify them at sign-up.
How to get a Grok API key in the xAI console
Following the quickstart in the docs, the order is:
- Sign up in the console at console.x.ai.
- Top up the account with credits. The docs say it directly: first "load it with credits", then start working with the API.
- On the API Keys page create a key and save it, for example in an
XAI_API_KEYenvironment variable. - Send a first request.
The official API address is https://api.x.ai/v1. It is compatible with the OpenAI format, and the docs examples for Grok 4.7 use the Responses endpoint. The model is called grok-4.7. There is also a dedicated xai_sdk, but you can get by with the plain OpenAI client by substituting a different base_url.
If the xAI console is not available to you, sign-up fails, or there is no suitable payment method, there is the second route.
Is there free access: grok api free
Short answer: do not count on it. In the xAI quickstart the first step is topping up credits, and any promotions or free allowances, if they appear, are shown in the console itself and may vanish. Check them there.
Do not look for "free keys" on forums and in chats: other people's keys either do not work or belong to someone who will later see your requests. For our part, we do not promise free access. Zukko has a single one-time reward: $0.50 for subscribing to the @zukkopro channel, once per Telegram account (link Telegram in the dashboard, subscribe, press "Check"). There is no sign-up bonus.
Grok through a gateway: one key instead of a separate account
Zukko is a gateway to models from several vendors with one balance in dollars. Access from Russia goes through the gateway, paid by SBP, MasterCard or crypto. The Grok models in the list as of October 18, 2026, prices in $ per 1M tokens:
| Model | Input / output | Cache: read / write | Context | Images | Strength index |
|---|---|---|---|---|---|
grok-4.7 | 0.175 / 0.513 | 0.025 / 0.175 | 256K | yes | 47 |
grok-4.6 | 0.138 / 0.4 | 0.013 / 0.138 | 256K | yes | 44 |
grok-4.5 | 0.113 / 0.338 | 0.013 / 0.113 | 256K | yes | 40 |
The strength index is the Artificial Analysis Intelligence Index; we give no other quality numbers. The context in the table comes from the Zukko model list. The xAI documentation may state a different limit for Grok 4.7, so for calls through the gateway rely on the response of GET https://api.zukko.pro/v1/models.
The key is created on the API keys page, and the full key is shown once. Authorization is the Authorization: Bearer fetch_... header; details in the authentication section.
A curl request
curl https://api.zukko.pro/v1/chat/completions \
-H "Authorization: Bearer $ZUKKO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.7",
"messages": [
{"role": "user", "content": "Find the bug: def median(a): a.sort(); return a[len(a)/2]"}
]
}'Python and the official OpenAI client
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.zukko.pro/v1",
api_key=os.environ["ZUKKO_API_KEY"],
)
resp = client.chat.completions.create(
model="grok-4.7",
messages=[{"role": "user", "content": "Explain the difference between list and tuple."}],
)
print(resp.choices[0].message.content)
print(resp.usage)For streaming add stream=True. The server sends a final chunk with usage and an empty choices, so check in the loop:
stream = client.chat.completions.create(
model="grok-4.7",
messages=[{"role": "user", "content": "Write a short README outline."}],
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="")If you prefer the Responses API as in xAI's examples, the gateway has POST /v1/responses too. Only the endpoint and the input field instead of messages change. Any model in the list can be called in either format, including the Anthropic-compatible POST /v1/messages. More in the quick start.
What a Grok request costs
Formula: cost = fresh input × input price + cache read × read price + output × output price. Prices as of October 18, 2026.
A request with 100,000 input tokens and 10,000 output tokens, no cache:
grok-4.7: 0.1 × 0.175 + 0.01 × 0.513 = 0.0175 + 0.00513 = $0.02263.grok-4.6: 0.1 × 0.138 + 0.01 × 0.4 = 0.0138 + 0.004 = $0.0178.- For comparison
claude-sonnet-5: 0.1 × 0.4 + 0.01 × 2 = 0.04 + 0.02 = $0.06.
If 80,000 of those input tokens came from cache and the vendor reported it in the response, grok-4.7 comes to: 0.02 × 0.175 + 0.08 × 0.025 + 0.01 × 0.513 = 0.0035 + 0.002 + 0.00513 = $0.01063. Cache reads are counted when the model vendor returns them in the response; cache writes are not billed separately.
Top-up by SBP: the payment page adds 8.5% on top. To credit $5 you pay, in rubles at the rate at the time of payment, the equivalent of $5 × 1.085 = $5.425. The minimum top-up is $1. Vendor prices change; current values are always in GET /v1/models and on the dashboard's "Models" page. Test the choice between models on your own tasks: price and index tell you where to start but do not replace a comparison.
Errors you will meet
- 401: the key is wrong or copied incompletely.
- 402: not enough balance.
- 403
model_not_allowed_for_key: the key has an allowed-models list andgrok-4.7is not in it. - 404
model_not_found: a typo in the model name; check againstGET /v1/models. - 429: the key's daily or monthly limit is exhausted, or the model provider is limiting.
A separate key with a daily limit per project removes unpleasant surprises on the bill. If you want to try it, create a key in the dashboard.
FAQ
Where is the console for the Grok API (grok api console)?
At xAI it is at console.x.ai: sign-up, credit top-ups and key creation. Through the gateway you do not need the xAI console, the Zukko dashboard is enough.
Do I need an xAI key if I use Zukko?
No. The fetch_... key works with Grok models the same as with Claude or GPT, and the gateway handles the relationship with xAI.
Which base URL should I set in the client?
For the OpenAI format: https://api.zukko.pro/v1. Clients that add /v1 themselves (Claude Code, the Anthropic SDK) use the address without /v1, but that concerns Claude tools.
Does Grok 4.7 see images?
Yes, the Zukko list marks image input for grok-4.7. The format is the same as for other image-capable models in an OpenAI-compatible request.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- xAI Grok API: Connecting Grok 4.7, Price and the 256K ContextHow to call grok-4.7 through an OpenAI-compatible API, what to do about the 256K context limit and what typical requests cost. Plus a comparison with Grok 4.6.
- Grok API from Russia: connecting without a foreign cardStep by step connection to Grok 4.7, 4.6 and 4.5 through a gateway: key, address, first request in curl and Python, streaming, images and payment by SBP or crypto.
- Claude Sonnet 5.5 via API: connection, prices and cache at October 18, 2026How to call claude-sonnet-5-5 from Python and curl, what a typical request costs with and without cache, and how it differs from Sonnet 5 and Sonnet 4.6.
- Claude on Android in Russia: what to do if the app won't installIf the official Claude app won't install on Android in Russia, you can still use the model from your phone: through the gateway's web chat or a client with your own key.