How to Use the Grok 4.5 API ?

Call the Grok 4.5 API in minutes: get an xAI key, use the grok-4.5 model ID (dot, not dash), stream responses, pick 4.5 vs 4.3, and test it all in Apidog.

Ashley Innocent

Ashley Innocent

9 July 2026

How to Use the Grok 4.5 API ?

Apidog for Enterprise

On-Premises Deploy

SSO & RBAC

SOC 2 Compliant

Explore Apidog Enterprise

Grok 4.5 went live on July 8, 2026, and the API path is the fastest way to put it to work. The model ID is grok-4.5, pricing is $2 per million input tokens and $6 per million output, and the context window is 500k tokens. xAI’s announcement positions it for coding, agentic tasks, and knowledge work at, in Musk’s words, “Opus-class” capability.

This guide walks through getting a key, making your first call, choosing between grok-4.5 and the older grok-4.3, and testing the endpoint properly in Apidog before you ship anything that depends on it.

button

One availability note before you start: Grok 4.5 is not yet available in the EU, in either the products or the API console. xAI expects EU access in mid-July 2026.

Step 1: Get an xAI API key

  1. Go to the xAI console and sign in.
  2. Open the API Keys section and create a new key.
  3. Store it as an environment variable. Never hardcode it:
export XAI_API_KEY="xai-..."

New console accounts have received trial credits in the past (reports range from $25 to $150). Check your billing page rather than counting on a specific amount. If you want to explore without credits at all, see how to use Grok 4.5 for free.

Step 2: Make your first request

xAI’s official quickstart uses the Responses endpoint. This is the exact shape from the release page:

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]}"
  }'

Two details trip people up:

Using the OpenAI SDK

Because xAI keeps compatibility with the OpenAI client libraries, pointing an existing client at https://api.x.ai/v1 is usually a one-line change. This is the same pattern we covered for earlier models in our Grok 4.3 API guide:

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. Features move quickly in the first weeks after a launch, and the docs are the source of truth for tool calling and structured outputs.

Streaming

For interactive use, 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, fast-model territory, so streams feel responsive even on long outputs.

Step 3: Pick the right model ID

xAI now sells two main chat models, and the trade-off between them is unusual:

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

The new model costs more and holds half the context. What you get in exchange is capability and efficiency: 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 means lower bills and shorter waits.

Rule of thumb: long-document RAG and giant-context analysis stay on grok-4.3; multi-step coding and agentic tool use move to grok-4.5. The full cost math, including how token efficiency changes the comparison, is in Grok 4.5 pricing explained.

If you’d rather route through 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 Grok 4.5 goes anywhere near production, put the endpoint under a proper test harness. Here’s the workflow in Apidog:

  1. Create a request for POST https://api.x.ai/v1/responses (or the chat completions path if you’re using the compatible surface).
  2. Store the key as an environment variable in an Apidog environment, so the Bearer token never lands in a shared collection.
  3. Send and inspect. Apidog renders SSE streams as they arrive, so you can watch deltas and confirm the stream terminates cleanly.
  4. Assert on the response. Add visual assertions on the fields your app depends on, like the model name echoed back, finish reason, and usage counts.
  5. A/B the two models. Duplicate the request, switch grok-4.5 to grok-4.3, and compare output quality, latency, and token usage side by side on your real prompts instead of trusting benchmark averages.
  6. Mock it. Generate a mock server from the response schema so your frontend and QA teams build against a stable shape while you tune prompts. No xAI credits burned on UI development.

The usage object matters more with this model than most. Grok 4.5’s pitch is token efficiency, so track output_tokens per task in your assertions. If your prompts produce Opus-length outputs anyway, the cost advantage shrinks.

Download Apidog free if you want to follow along; the whole flow above works on the free plan.

Costs, limits, and gotchas

For the bigger picture on what this model is and where it beats or trails Opus 4.8, start with 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 key. Existing chat-completions code migrates 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 in our free-access guide.

What’s the context window? 500k tokens. If you need 1M, use grok-4.3 and accept the capability trade-off.

Explore more

How to Use Grok 4.5 in Cursor ?

How to Use Grok 4.5 in Cursor ?

Grok 4.5 is live in Cursor on all plans with doubled usage for launch week. How to enable it, what it costs, the $4/$18 fast variant, and when to pick it.

9 July 2026

Grok 4.5 Was Trained on Cursor Sessions: What That Means for Developers

Grok 4.5 Was Trained on Cursor Sessions: What That Means for Developers

Grok 4.5 trained on trillions of tokens of Cursor developer sessions. What's confirmed, what privacy mode covers, what to check in your settings, and why it matters.

9 July 2026

How Much Does Grok 4.5 API Cost?

How Much Does Grok 4.5 API Cost?

Grok 4.5 pricing: $2/M input, $6/M output, no batch discount, unconfirmed cached rate, and the token-efficiency math that makes it ~17x cheaper per task than Opus 4.8.

9 July 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs

How to Use the Grok 4.5 API ?