API Guide

Grok API: Pricing, Keys & How to Call It

The Grok API is xAI's programmatic access to the Grok family, and the lineup turned over twice this year. As of July 2026 the served ids are Grok 4.5, the flagship since 9 July, at $2.00/$6.00 per million tokens; Grok 4.3 and the Grok 4.20 variants at $1.25/$2.50; and the coding model grok-build-0.1 at $1.00/$2.00. Grok 4, Grok 3, Grok 3 Mini and Grok Code Fast 1 are retired — if you are budgeting off their old $3/$15 or $0.20/$1.50 numbers, you are pricing models you can no longer call. Cheap per token is also not the same as cheap per job. We ran Grok 4.3 through our own executed coding harness: it cost $1.75 per 1,000 tasks, averaged 8.4 seconds, and missed one of nine tasks. This guide has the current price table, that measured result, how to get an xAI key, and how to call it (it's OpenAI-compatible), direct or via a gateway.

Grok API pricing and access guide — Grok 4.3, Grok 4.20 and grok-build-0.1 token prices

What the Grok API is

The Grok API is xAI's access to the Grok family, and it is OpenAI-compatible, so it drops into existing OpenAI-SDK code. What trips people up is that the lineup turned over: the served ids are now Grok 4.5 (the flagship since 9 July 2026, 500K context), Grok 4.3 (the prior flagship, still live, 1M context), the Grok 4.20 variants, and grok-build-0.1 on the separate Code API. Grok 4, Grok 3, Grok 3 Mini and Grok Code Fast 1 are retired. Two things follow. First, the famous cheap coding tier is gone — the $0.20/$1.50 that half the internet still quotes belongs to a model you cannot call. Second, sticker price is not the bill anyway: the measured section below has our own per-task numbers for Grok 4.3.

How this is sourced. Current list prices and context windows are from xAI's models docs, July 2026, cross-checked against the live DataLLM Lab catalog and, for Grok 4.5, against its OpenRouter listing (verified 27 July 2026) — which is also where the retired status of Grok 4, Grok 3, Grok 3 Mini and Grok Code Fast 1 comes from. Retired-model prices are shown as historical reference only. The per-task costs further down are our own measurements, not vendor figures. For the full verified id-by-id table, see our Grok API key guide.

Grok API pricing

Model idStatusInputOutputContext
grok-4.5 (flagship since 9 Jul 2026)Live$2.00$6.00500K
grok-4.3 (prior flagship)Live$1.25$2.501M
grok-4.20 (reasoning / non-reasoning)Live$1.25$2.502M
grok-4.20-multi-agentLive$1.25$2.502M
grok-build-0.1 (Code API)Live$1.00$2.00256K
grok-4Retired$3$15256K
grok-3Retired$3$15131K
grok-code-fast-1Retired$0.20$1.50256K
grok-3-miniRetired$0.30$0.50131K

Per 1M tokens, USD. Live prices and contexts from xAI's models docs, July 2026, cross-checked against the DataLLM Lab catalog. Retired rows are the last prices those ids carried, kept for reference — they are not callable.

The line most price tables miss: xAI collapsed the ladder. The old lineup ran from $15 output down to $0.50 — a 30x internal spread that made model selection a real cost decision. The current lineup runs $6.00 down to $2.00, a 3x spread — and essentially all of that gap is the new flagship: take Grok 4.5 out and the remaining ids sit between $2.50 and $2.00, a 1.25x spread. Grok 4.3 and both 4.20 variants carry identical $1.25/$2.50 pricing, so choosing among those three is a question of behaviour — reasoning, non-reasoning, multi-agent — and nothing else. That leaves two price levers: staying on the $1.25/$2.50 tier instead of Grok 4.5 (2.4x cheaper on output), and moving coding work to grok-build-0.1 on the Code API, which saves 20% against that tier's output rate — not an order of magnitude.

Grok models by price

The useful comparison is no longer model against model — it is the old ladder against the new one. Grok's price range used to span 30x, from Grok 4's $15 output down to Grok 3 Mini's $0.50. Every one of those rungs is now retired, and what replaced them spans 3x, with three of the four current ids within 25% of each other:

Grok output price per 1M tokens: the ladder collapsedxAI list price, July 2026 · a 30x spread became a 3x spreadRETIRED — NOT CALLABLEgrok-4$15grok-code-fast-1$1.50grok-3-mini$0.50CURRENT — SERVED TODAYgrok-4.5$6.00grok-4.3$2.50grok-4.20$2.50grok-build-0.1$2.00
Chart: DataLLM Lab — Grok output price per 1M tokens, retired ids versus the ids xAI serves today. Prices from xAI's models docs, July 2026 (Grok 4.5 cross-checked against its OpenRouter listing); retired status from the live DataLLM Lab catalog, July 2026. The cheap tier did not get cheaper — it disappeared, and the floor rose from $0.50 to $2.00.

This matters for anyone who built a cost model on the old lineup. A high-volume coding loop that budgeted Grok Code Fast 1 at $0.20 in / $1.50 out now has to run on grok-build-0.1 at $1.00 / $2.00. That is 33% more on output but 5x more on input, and a coding loop that resends context every turn is input-dominated, so the realistic bill increase is far closer to the 5x than the 33%. It is also not a one-line change: grok-build-0.1 sits on the separate Code API, not chat completions.

What Grok 4.3 actually cost per task

A list price is a rate, not a bill. We ran Grok 4.3 through our own executed coding harness — 13 models, nine Python tasks, temperature 0, max_tokens 4000, every returned solution run against assertions the model never sees — so the cost below is real token usage at list price, not an estimate. Grok 4.3 is the only Grok model in that run: Grok 3, Grok 4 and Grok Code Fast 1 were not tested, and we will not guess where they would land. Here is the Grok row, with three models from the same run for scale:

ModelScore$/1,000 tasksAvg latency
Grok 4.3 (missed flatten)8/9$1.758.4s
Claude Sonnet 59/9$1.677.2s
Qwen3 Coder Next (cheapest 9/9 in the run)9/9$0.107.0s
GPT-5.5 (priciest 9/9 in the run)9/9$8.8310.5s

DataLLM Lab executed test: real token usage × list price, scaled to 1,000 tasks. Nine Python tasks, one scored attempt each, scored by execution.

Two results here are not on any spec sheet. First, Grok 4.3 was one of only three models in the run that did not score 9/9 — 10 of 13 did — and the task it missed was flatten, flattening a nested structure, not an exotic algorithm. At $1.75 per 1,000 tasks it also landed just above Claude Sonnet 5, which cost $1.67, ran faster at 7.2s, and returned working code on all nine. Of the eight models that cost less per 1,000 tasks than Grok 4.3, seven scored 9/9. Grok 4.3's list price is genuinely low for a 1M-context reasoning model; on this workload that discount did not translate into a lower bill than the models around it.

Second, where the money went. Grok 4.3 is a reasoning model and spent 482 reasoning tokens per task in this run — tokens you never read but pay for at the output rate. Claude Sonnet 5 and Qwen3 Coder Next spent 0. That is the mechanism behind the whole spread: the cheapest perfect score in the run cost $0.10 per 1,000 tasks and the most expensive cost $8.83, an 88x gap for output that passed identical tests. Anyone budgeting Grok 4.3 from the $1.25/$2.50 sticker alone will under-count the thinking tokens.

What this test does not measure. Nine short Python functions, one shot each, scored pass or fail. It says nothing about long-context reasoning, multi-file refactoring, agentic tool use, or non-Python work — and nothing at all about Grok 3, Grok 4 or Grok Code Fast 1, which we have not run. Treat it as one hard data point on cost-per-completed-task, not a verdict on the model. Full run: the 13-model coding cost benchmark. How it was measured: our methodology.

How to get a Grok (xAI) API key

  1. Sign up at the xAI developer console (console.x.ai) and verify your account.
  2. Add billing/credit.
  3. Create an API key and copy it once; store it as export XAI_API_KEY=...

How to call the Grok API

Grok is OpenAI-compatible — use the OpenAI SDK with xAI's base URL:

from openai import OpenAI

client = OpenAI(base_url="https://api.x.ai/v1", api_key="$XAI_API_KEY")

resp = client.chat.completions.create(
    model="grok-4.3",         # or a grok-4.20 variant; grok-build-0.1 is on the Code API
    messages=[{"role": "user", "content": "Implement and test this function..."}],
)
print(resp.choices[0].message.content)

Which Grok model to use

Grok 4.3 Benchmarked pick

  • $1.25/$2.50, 1M context. Scored 8/9 at $1.75 per 1,000 tasks in our executed coding run — solid, not a clean sweep. The only Grok model we have benchmarked.

Grok 4.20 Same price, different behaviour

  • $1.25/$2.50, 2M context — the widest in the lineup — in reasoning, non-reasoning and multi-agent variants, identically priced to Grok 4.3, so pick on behaviour. We have not benchmarked the 4.20 family.

grok-build-0.1 Coding, on the Code API

  • $1.00/$2.00, 256K context — the current coding model and the one remaining price lever, worth 20% off output. We have not benchmarked it, so treat the price as the only verified fact.

Pattern Escalate across vendors, not inside Grok

  • With the chat family flat at one price, a cheap-first-pass rule no longer exists inside Grok — it means routing across vendors. Note our own run does not support escalating to Grok on coding: Grok 4.3 scored 8/9 at $1.75 per 1,000 tasks, and seven of the eight models that cost less scored a perfect 9/9. An escalation target should out-score the cheap first pass, and on these tasks it did not. Score any routing rule by running the output, not by comparing sticker prices: our run had an 88x cost gap between models that passed the same tests.

Calling Grok through a gateway

DataLLM Lab carries Grok 4.3 plus the Grok 4.20 variants and grok-build-0.1 today — reachable with one OpenAI-compatible key alongside Claude, GPT and DeepSeek, with automatic failover. The benchmark above was not run on it — we call models through OpenRouter for testing precisely so the numbers do not depend on our own infrastructure. What the gateway gives you is the same one-key access pattern for production:

client = OpenAI(base_url="https://www.datallmlab.com/v1", api_key="$DATALLMLAB_API_KEY")
# reaches x-ai/grok-4.3, x-ai/grok-4.20, anthropic/claude-sonnet-5, ...

Call Grok and 300+ models with one key

Grok 4.3, grok-build-0.1, Claude Sonnet 5, GPT-5.5 and more — one OpenAI-compatible endpoint, live price comparison, automatic failover.

FAQ

How much does the Grok API cost?

Per 1M tokens, as of July 2026: Grok 4.5, the flagship since 9 July, is $2.00 in / $6.00 out; Grok 4.3 and the Grok 4.20 variants are $1.25 / $2.50; and the coding model grok-build-0.1 is $1.00 / $2.00. Those three chat ids below the flagship share one price, so choosing among them is about behaviour, not cost. The older ids people still quote — Grok 4 and Grok 3 at $3/$15, Grok 3 Mini at $0.30/$0.50, Grok Code Fast 1 at $0.20/$1.50 — are retired and no longer served.

How do I get a Grok (xAI) API key?

Sign up at console.x.ai, add billing, create a key. OpenAI-compatible at https://api.x.ai/v1. Or reach Grok via a gateway like DataLLM Lab.

Is the Grok API OpenAI-compatible?

Yes — use the OpenAI SDK with base_url https://api.x.ai/v1 and a current model id (grok-4.3, or grok-build-0.1 on the Code API). Switching to/from a gateway is one line.

Is Grok Code Fast still available?

No. Grok Code Fast 1 (grok-code-fast-1), xAI's old $0.20/$1.50 coding model, is retired and no longer in the live catalog as of July 2026. The current coding model is grok-build-0.1 at $1.00/$2.00 per 1M tokens with a 256K context. Guides still quoting $0.20/$1.50 are quoting a model you cannot call.

Which Grok model should I use?

Grok 4.5 is the flagship as of 9 July 2026, at $2.00 / $6.00 with a 500K context. Grok 4.3 is the prior flagship and the only Grok model we have benchmarked — 8/9 at $1.75 per 1,000 tasks in our executed coding run — and it carries a 1M context, wider than Grok 4.5's 500K, though the Grok 4.20 variants reach 2M. The Grok 4.20 variants cost the same as 4.3, so choose between them on behaviour rather than price. Use grok-build-0.1 for coding work on the Code API. We have not benchmarked Grok 4.5, the 4.20 family or grok-build-0.1.

Can I use the Grok API through a gateway?

Yes — DataLLM Lab carries Grok 4.3, the Grok 4.20 variants and grok-build-0.1, callable through one OpenAI-compatible key with failover.

Written by

Founder of DataLLM Lab, the unified LLM gateway. Kevin tests models the boring way — same prompts, real costs, unedited outputs — and writes up what the runs actually show. Articles are drafted with AI assistance and published under his name; every first-party number comes from an executed run.

One API for every model

One API, every model.

Get a single API key for Claude Opus 4.7, GPT-5.4, and 300+ more — with automatic price comparison and routing to the best model for every request.