Grok API: how to get an xAI key and connect Grok without a foreign card
The Grok API is OpenAI-compatible: a key, a base_url and a model name, and Grok works in any OpenAI SDK code, Cline, Kilo Code or OpenCode. Below: the official route through the xAI console, the models and prices, an OpenAI-compatible route through Twelver, a Python example and a cost calculator.
Short answer
Officially: sign up at console.x.ai, load credits, then API Keys → create a key. Base URL https://api.x.ai/v1, main model grok-4.7. Through Twelver: the grok series (Grok 4.7), with a key issued on this page with no signup and no card.
Models and official prices
| Model | Context | Input | Cached input | Output |
|---|---|---|---|---|
| grok-4.7 | 500K | $2.00 | $0.50 | $6.00 |
| grok-4.6 | 500K | $2.00 | $0.50 | $6.00 |
| grok-4.3 | 1M | $1.25 | $0.20 | $2.50 |
| grok-4.20 (reasoning / non-reasoning) | 1M | $1.25 | $0.20 | $2.50 |
| grok-build-0.1 | 256K | $1.00 | $0.20 | $2.00 |
Grok through Twelver
| Series | Model | $ per 1M |
|---|---|---|
| grok | Grok 4.7 | 3.25 / 9.75 |
Right here
Base URL and key for Grok
Your own values appear in the block and drop straight into the code below.
Press it and get your base_url and API key.
No sign-up, no card.
Free. Your key appears right here.
grok.pyThe highlighted parts are stand-ins. The button above issues them in seconds, no sign-up.from openai import OpenAI
client = OpenAI(base_url="https://twelver.ru/api/ai/<your-config-id>/v1", api_key="sk-<your-key>")
reply = client.chat.completions.create(
model="grok",
messages=[{"role": "user", "content": "Find the bug in this function: ..."}],
)
print(reply.choices[0].message.content)Work out what the requests cost
Pick a workload or type your own numbers — the calculator multiplies them by each series’ rates. A token is roughly 4 characters of English text or code.
grokGrok 4.7$328 per monthautoQwen3.7-Plus$67.86 per monthzaiGLM-5.3$231 per monthdeepseekDeepSeek V4 Pro$217 per monthTwelver rates as of 4 November 2026; tokens are billed as actually used, caching and discounts not included. The arithmetic runs in your browser.
Grok Imagine (images and video) is called with the same key through the media API, with "toolsets": ["grok-image-generation"] or grok-video-generation. More: Grok in Twelver. Agent setup: Cline, Kilo Code, OpenCode. Other models: GLM API, DeepSeek API. The whole book: API for AI agents.
Frequently asked questions
How do I get a Grok API key?
How much does the Grok API cost?
What is grok.com/api/auth/session?
Can I use Grok without the xAI console?
Try it yourself
Everything in this guide runs inside Twelver
One chat for text, images, video, music and voice — no separate services or subscriptions.
Open Twelver chat