How to Get a Grok 4.5 API Key (July 2026)
xAI released Grok 4.5 on July 8, 2026 — 1.5 trillion parameters, co-trained with Cursor, priced at $2/M input tokens. This guide covers registration, key creation, your first API call, error fixes, and how Grok 4.5 compares to rivals.
1) What is Grok 4.5?
On July 8, 2026, xAI (SpaceXAI) officially released Grok 4.5, co-trained with AI coding company Cursor. It is built on xAI's new V9 architecture with 1.5 trillion parameters — roughly three times the scale of Grok 4.3 — and is the first Grok model specifically designed for coding and agentic tasks.
According to xAI's published benchmarks, Grok 4.5 surpasses Claude Opus 4.8 across multiple software engineering tests. The model runs at 80 tokens per second and achieves twice the token efficiency of competing models on complex coding tasks, which means fewer steps and lower real-world cost per completed task.
2) Register on xAI Console
Go to console.x.ai and sign up with your email or X (Twitter) account. You do not need an active X Premium subscription to access the API — the developer console is a separate product.
After signup, you need to bind a payment method before creating API keys. xAI accepts major international credit cards. There is no permanent free tier, but xAI has offered promotional credits in the past — check the console for active offers after you sign up.
3) Create your API Key
After logging in, navigate to API Keys in the left sidebar (or go directly to console.x.ai/team/default/api-keys). Click "Create API Key", enter a descriptive name, and confirm.
The key is shown only once at creation. Copy it immediately and store it in a password manager or secrets vault — you cannot retrieve it again from the console.
- Navigate to console.x.ai/team/default/api-keys
- Click "Create API Key" → enter a name → confirm
- Copy the key immediately — shown only once
4) Your first Grok 4.5 API call
Grok 4.5's API is fully compatible with the OpenAI chat completions format. The base URL is https://api.x.ai/v1 and the model ID is grok-4.5. If you already use the OpenAI SDK, migration requires only two changes: swap the base URL and the API key.
Always store XAI_API_KEY as a server-side environment variable. Never expose it in frontend JavaScript, mobile apps, or public repositories.
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["XAI_API_KEY"],
base_url="https://api.x.ai/v1",
)
response = client.chat.completions.create(
model="grok-4.5",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the V9 architecture of Grok 4.5 briefly."}
]
)
print(response.choices[0].message.content)Python — using the OpenAI SDK with xAI's base URL
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.XAI_API_KEY,
baseURL: "https://api.x.ai/v1",
});
const response = await client.chat.completions.create({
model: "grok-4.5",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What makes Grok 4.5 efficient for coding tasks?" }
]
});
console.log(response.choices[0].message.content);JavaScript / Node.js — same pattern as Python
curl https://api.x.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-d '{
"model": "grok-4.5",
"messages": [
{"role": "user", "content": "Hello, Grok 4.5!"}
]
}'cURL — quick smoke test to verify your key works
5) Common errors and how to fix them
Most API errors fall into one of three categories: authentication failures (401), quota or rate limit exceeded (429), and malformed requests (400). Here is how to diagnose and fix each one.
If you see a 401 error, the most common causes are: the API key was not set as an environment variable correctly, the key was copied with extra whitespace, or the Authorization header format is wrong. Double-check that you are passing Bearer <key> with a space, not Bearer<key>.
- 401 Unauthorized → check XAI_API_KEY is set and has no leading/trailing spaces
- 401 Unauthorized → verify Authorization: Bearer <space> <key> header format
- 429 Too Many Requests → add exponential backoff retry logic; check your plan's rate limits in the console
- 400 Bad Request → ensure messages array is not empty and model ID is exactly grok-4.5
- Connection timeout → xAI API endpoint is https://api.x.ai/v1 — verify no proxy is blocking it
6) Pricing comparison — Grok 4.5 vs. rivals
Grok 4.5 is priced at $2 per million input tokens and $6 per million output tokens. This is significantly lower than comparable frontier models, while delivering Opus-class benchmark performance.
The cost advantage is amplified by Grok 4.5's efficiency: it completes complex software engineering tasks in fewer token steps than competitors. xAI reports that on typical agentic coding benchmarks, Grok 4.5 uses roughly half the tokens of comparable models per resolved task — making the effective cost difference even larger than the per-token rate suggests.
- Grok 4.5: $2 input / $6 output per million tokens
- Claude Sonnet 5: $3 input / $15 output per million tokens
- Claude Opus 4.8: $15 input / $75 output per million tokens
- Grok 4.5 effective task cost ≈ 2× lower than Claude Sonnet 5 due to token efficiency
FAQ
Why was Grok 4.5 co-trained with Cursor?
xAI acquired AI coding tool Cursor and used Cursor's real-world code data and engineering workflows for training. This makes Grok 4.5 particularly strong at agentic coding — understanding multi-file projects, not just isolated code snippets.
Is Grok 4.5 compatible with the OpenAI SDK?
Yes. Change the base URL to https://api.x.ai/v1 and replace your API key with XAI_API_KEY. The xAI API follows the OpenAI chat completions format, so most existing code works without modification.
Does Grok 4.5 support streaming responses?
Yes. Set stream: true in your request body. The response follows the standard server-sent events (SSE) format, same as OpenAI's streaming API.
Is there a free tier for the xAI API?
There is no permanent free tier. A payment method is required to activate API access. xAI has previously offered promotional credits — check the console dashboard after signing up for any active promotions.
Related Providers
Sources
- SpaceXAI 联合 Cursor 发布 Grok 4.5(钛媒体报道)xAI Docs · Checked 2026-07-21
- xAI API 控制台xAI Console · Checked 2026-07-21
- Grok 4.5 定价:$2/$6 per million tokens(多媒体交叉核验)xAI Docs · Checked 2026-07-21