Grok 4.5 went live on July 8, 2026, and the API is the fastest way to start using it in your own tools. Use model ID grok-4.5, expect pricing at $2 per million input tokens and $6 per million output tokens, and plan around a 500k-token context window. xAI’s announcement positions the model for coding, agentic tasks, and knowledge work at, in Musk’s words, “Opus-class” capability.
This guide shows how to get an API key, make your first request, decide between grok-4.5 and grok-4.3, and test the endpoint in Apidog before you ship.
One availability note: Grok 4.5 is not yet available in the EU, either in the products or the API console. xAI expects EU access in mid-July 2026.
Step 1: Get an xAI API key
- Go to the xAI console and sign in.
- Open the API Keys section.
- Create a new key.
- Store it as an environment variable. Do not hardcode it in source code.
export XAI_API_KEY="xai-..."
New console accounts have received trial credits in the past, with reports ranging from $25 to $150. Check your billing page instead of assuming a fixed amount.
If you want to explore without credits, see how to use Grok 4.5 for free.
Step 2: Make your first request
xAI’s official quickstart uses the Responses endpoint.
curl -s https://api.x.ai/v1/responses \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.5",
"input": "Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}"
}'
Watch for two common mistakes:
-
Use the dot in the model ID.
grok-4.5is valid.grok-4-5returns a model-not-found error. -
The Responses endpoint uses
input. It does not use amessagesarray. If you are migrating OpenAI-style chat code, use xAI’s OpenAI-compatible chat completions endpoint instead.
Use the OpenAI SDK
xAI supports OpenAI-compatible client libraries. In most existing apps, the main change is setting base_url to https://api.x.ai/v1.
This follows the same pattern covered in our Grok 4.3 API guide.
import os
from openai import OpenAI
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 code review assistant."},
{"role": "user", "content": "Review this handler for race conditions: ..."},
],
)
print(response.choices[0].message.content)
Check the xAI docs for the current parameter surface before relying on tool calling, structured outputs, or other launch-week features.
Stream responses
For interactive apps, enable streaming and consume server-sent events.
stream = client.chat.completions.create(
model="grok-4.5",
messages=[
{
"role": "user",
"content": "Refactor this function step by step: ..."
}
],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
Grok 4.5 serves around 80 tokens per second, so streamed responses should feel responsive even for longer outputs.
Step 3: Pick the right model ID
xAI now sells two main chat models. The trade-off is not only price; it is also context length, speed, and output efficiency.
grok-4.5 |
grok-4.3 |
|
|---|---|---|
| Context window | 500k tokens | 1M tokens |
| Input / output per 1M | $2.00 / $6.00 | $1.25 / $2.50 |
| Batch discount | None listed | 20% off |
| Speed | ~80 TPS | Slower per xAI’s positioning |
| Strengths | Agentic coding, token efficiency | Long-context work, price |
grok-4.5 costs more and has half the context window of grok-4.3. In exchange, it targets stronger coding and agentic performance.
On SWE Bench Pro, Grok 4.5 resolves tasks with an average of 15,954 output tokens, about 4.2x fewer than Claude Opus 4.8 max on the same benchmark. For agent loops, fewer output tokens can mean lower bills and shorter waits.
A practical routing rule:
- Use
grok-4.3for long-document RAG, large-context analysis, and cost-sensitive batch work. - Use
grok-4.5for multi-step coding, agentic workflows, and tool-heavy tasks.
For the full cost comparison, see Grok 4.5 pricing explained.
If you prefer an aggregator for failover or unified billing, Grok 4.5 is also listed on OpenRouter. We covered that setup pattern in how to use Grok models via OpenRouter.
Step 4: Test the endpoint in Apidog
Before you put Grok 4.5 behind production code, test it with a repeatable API workflow in Apidog.
Use this workflow:
-
Create a request
Use
POST https://api.x.ai/v1/responses.
If your app uses the OpenAI-compatible API, create the request against the chat completions path instead.
Store the API key as an environment variable
Keep the Bearer token in an Apidog environment so it does not get saved into a shared collection.Send the request and inspect the response
Apidog renders SSE streams as they arrive, so you can verify deltas, latency, and clean stream termination.Add assertions
Assert on the fields your application depends on, such as:
- model name
- finish reason
- usage counts
- response shape
- required JSON fields if you expect structured output
-
A/B test
grok-4.5againstgrok-4.3Duplicate the request, change the model ID, and run both against your real prompts. Compare:
- output quality
- latency
- input tokens
- output tokens
- total estimated cost
- Mock the API response Generate a mock server from the response schema so frontend and QA teams can work against a stable contract while you tune prompts and model selection.
The usage object is especially important with Grok 4.5. Its value proposition depends partly on token efficiency, so track output_tokens per task in your tests. If your prompts still produce very long outputs, the cost advantage shrinks.
You can download Apidog free if you want to follow along. The workflow above works on the free plan.
Costs, limits, and gotchas
- Pricing: $2/M input tokens and $6/M output tokens.
- Search tool calls: Web and X search tool calls bill separately at $5 per 1,000 calls.
- Priority processing: Runs at 2x standard rates.
- Cached input: Secondary sources report a $0.50/M cached-input rate, but neither the release page nor the docs pricing page confirms it as of July 9. Check the console before building cache-heavy cost models.
-
Batch discount: No batch discount is listed for
grok-4.5, unlikegrok-4.3. - EU availability: Blocked until mid-July 2026. Requests from EU-billed accounts fail at the console access level, not as a normal API error.
- Rate limits: Account-tier dependent. The same patterns from Grok’s earlier rate-limit tiers still apply: check your console tier and implement backoff before you need it.
For broader model context, see what is Grok 4.5.
FAQ
What is the Grok 4.5 API model ID?
grok-4.5. The dot is required in API calls.
Does the Grok 4.5 API work with the OpenAI SDK?
Yes. Set base_url to https://api.x.ai/v1 and pass your xAI API key. Existing chat-completions code can migrate with minimal changes.
How much does the Grok 4.5 API cost?
$2 per million input tokens and $6 per million output tokens, with no batch discount listed. See the full pricing breakdown for effective-cost math.
Is there a free way to call Grok 4.5?
Grok Build and Cursor include free Grok 4.5 usage for a limited window, and console trial credits have covered light API testing. Details are in our free-access guide.
What is the context window?
500k tokens. If you need 1M tokens, use grok-4.3 and accept the capability trade-off.



Top comments (0)