Grok API: how to get an xAI key and connect Grok without a foreign cardAn API for AI coding agents: one key, any OpenAI-compatible tool

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

ModelContextInputCached inputOutput
grok-4.7500K$2.00$0.50$6.00
grok-4.6500K$2.00$0.50$6.00
grok-4.31M$1.25$0.20$2.50
grok-4.20 (reasoning / non-reasoning)1M$1.25$0.20$2.50
grok-build-0.1256K$1.00$0.20$2.00
xAI’s prices per 1M tokens for prompts under 200K tokens, docs.x.ai, 7 October 2026. Longer prompts cost twice as much.

Grok through Twelver

SeriesModel$ per 1M
grokGrok 4.73.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.

Template — this will not work as isgrok.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 month
request: $0.1091,000 requests: $109
autoQwen3.7-Plus$67.86 per month
request: $0.0231,000 requests: $22.62
zaiGLM-5.3$231 per month
request: $0.0771,000 requests: $76.98
deepseekDeepSeek V4 Pro$217 per month
request: $0.0721,000 requests: $72.23

Twelver 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?
In the xAI console (console.x.ai): sign up, load credits, then API Keys → create a key. Base URL https://api.x.ai/v1, main model grok-4.7.
How much does the Grok API cost?
At xAI, grok-4.7 is $2 per 1M input and $6 per 1M output tokens for prompts under 200K tokens (twice that above), cached input $0.50. grok-4.3 and grok-4.20 are $1.25 and $2.50.
What is grok.com/api/auth/session?
A service address of the Grok web chat that checks whether you are signed in. It has nothing to do with the developer API, which lives at https://api.x.ai/v1.
Can I use Grok without the xAI console?
Yes, through an OpenAI-compatible provider. Twelver serves Grok 4.7 as the grok series, with a key issued without signup or a card.

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
Rate your experience