Grok · Flagship · 500K context window

Grok 4.5 pricing for code generation

$0.0280 per call at 2,000 input / 4,000 output tokens.

Per call

$0.0280

10K calls/mo

$280

Cache savings

85% off input

Batch savings

50% off all

Calculate your Grok 4.5 costs

Adjust token counts, volume, and discount toggles to model your code generation spend. Prices verified daily against provider pricing pages.

Configure your usage

2,000
100100K
4,000
5050K
10,000
1001M

Estimated cost

Monthly cost
$280
10,000 calls/month
Cost per call$0.028
Daily cost$9
Input rate$2.00/MTok
Output rate$6.00/MTok
Analyze your real spend

Quick start

Call Grok 4.5 with the OpenAI Python SDK pointed at api.x.ai:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.x.ai/v1",
    api_key=os.environ["XAI_API_KEY"],
)
response = client.chat.completions.create(
    model="grok-4.5",
    max_tokens=4000,
    messages=[{"role": "user", "content": "Your prompt here"}]
)
# Cost: ~$0.0280 per call at standard rates
# Input:  $2.00/MTok
# Output: $6.00/MTok

How Grok 4.5 compares on cost

Per-call cost for all models scoring 50+ on code generation benchmarks. Hover for details.

Cheapest viable option: Claude Sonnet 5 at $0.0440/call (-57% less, 93/100 quality).

What drives code generation cost

Cost here is dominated by output, not input: the model writes far more than you ask. A prompt with a short spec and a few reference files runs 2K input, but a complete module comes back at 4K output or more, so a model's output rate matters roughly twice as much as its input rate. The biggest saving is not a cheaper model: it is caching the system prompt and coding standards you resend on every call.

For Grok 4.5 specifically, that means output tokens cost 3.0x more than input, at $6.00 vs $2.00 per MTok. At this use case’s 2,000/4,000 token split, output accounts for 86% of the $0.0280 per-call cost.

Complete Grok 4.5 pricing breakdown

Standard token rates

Direction$/MTokTokens per call
Input$2.002,000
Output$6.004,000

Prompt caching: 85% off input tokens

Caching drops input cost from $2.00 to $0.30/MTok. For repeated system prompts, that saves $0.003400 per call.

Batch API: 50% off all tokens

Submit requests asynchronously and receive 50% off all token costs. This works best for offline pipelines where latency requirements are flexible.

Monthly cost projections

Monthly volumeCost per callStandard monthlyCached monthlyYou save with caching
10,000 calls$0.0280$280$246$34
50,000 calls$0.0280$1,400$1,230$170
100,000 calls$0.0280$2,800$2,460$340
500,000 calls$0.0280$14,000$12,300$1,700
1,000,000 calls$0.0280$28,000$24,600$3,400

Grok 4.5 quality benchmarks for code generation

Benchmark data for code generation is pending for Grok 4.5. Test against your own evaluation suite before moving to production.

Performance across all task types

Grok 4.5 scores by task type. Code Generation highlighted.

Task typeConfidence scoreRank out of 20

Confidence scores are a third-party benchmark snapshot from week 29 of 2026. This snapshot is 8 weeks old, so treat the scores as directional and validate against your own evals.

Alternative models for code generation

9 models score 80+ on code generation benchmarks, sorted by input rate. Cheapest: Claude Sonnet 5 (-57% less, 93/100 quality).

ModelProviderInput $/MTokOutput $/MTokQualityPer callvs Grok
Claude Sonnet 5Claude$2.00$10.0093/100$0.044057% more
GPT 5.6 TerraGPT$2.00$12.0086/100$0.052086% more
Gemini 3.1 ProGemini$2.00$12.0086/100$0.052086% more
GPT 5.4GPT$2.50$15.0084/100$0.0650132% more
Claude Sonnet 4.6Claude$3.00$15.0092/100$0.0660136% more
GPT 5.6 SolGPT$4.00$20.0094/100$0.0880214% more
Claude Opus 4.8Claude$5.00$25.0095/100$0.1100293% more
GPT 5.5GPT$5.00$30.0091/100$0.1300364% more
Claude Fable 5Claude$10.00$50.0096/100$0.2200686% more

About Grok 4.5

Provider

Grok

Tier

Flagship

Context

500K tokens

Released

Jul 2026

Same list price as Grok 4.6 but a cheaper cached rate ($0.30/MTok vs $0.50), so cache-heavy workloads are cheaper here than on 4.6. xAI publishes release notes at month granularity only; dated to the start of the month.

Other models from Grok

ModelTierInput $/MTokOutput $/MTokContext
Grok 4.6Flagship$2.00$6.00500K
Grok 4.3Mid-tier$1.25$2.501,000K
Grok Build 0.1Fast / Budget$1.00$2.00256K

You can compare Grok 4.5 head-to-head against any other model on our model comparison pages, or track how pricing has changed over time on the pricing history tracker.

Frequently asked questions

How much does Grok 4.5 cost for code generation per API call?

A typical code generation call using Grok 4.5 costs about $0.0280 per call. This estimate uses 2,000 input tokens and 4,000 output tokens at standard rates. Standard rates are $2.00 per million input tokens and $6.00 per million output tokens.

Is Grok 4.5 the best model for code generation?

Our benchmark data does not yet include a code generation ranking for Grok 4.5. We recommend testing it against your own evaluation criteria before production usage.

What is the cheapest model for code generation with good quality?

The most affordable model for code generation above 80/100 quality is Claude Sonnet 5. It comes from Claude at $2.00 per million input tokens. Output costs $10.00 per million tokens with a quality score of 93/100. Switching from Grok 4.5 to Claude Sonnet 5 saves about -57% per API call.

How can I reduce my Grok 4.5 costs for code generation?

Three strategies lower Grok 4.5 costs for this task type effectively. Prompt caching gives a 85% discount on input tokens when reusing system prompts. The batch API gives 50% off all tokens for asynchronous processing workloads. Prompt optimization reduces token counts through more concise instructions and context windows. Combining caching with batching brings your cost from $0.0280 to about $0.002100 per call.

How does Grok 4.5 pricing compare to other Grok models?

Grok has 3 other models alongside Grok 4.5 today: Grok 4.6 at $2.00/$6.00 per million tokens (flagship), Grok 4.3 at $1.25/$2.50 per million tokens (mid-tier), Grok Build 0.1 at $1.00/$2.00 per million tokens (fast / budget). The right choice depends on whether your code generation workload prioritizes quality, cost, or speed.

What context window does Grok 4.5 support?

Grok 4.5 supports a context window of 500K tokens per API call. This sets the maximum combined length of your input prompt and generated response. For code generation, typical calls use 2,000 input and 4,000 output tokens. That is well within this limit, leaving room for longer prompts or multi-turn conversations.

Track what you spend on AI

This calculator estimates costs based on published rates only. Connect your API usage to see where your money goes and which models drive your spend.