Skip to content

fix(pricing): correct xai/grok-4.5 cached input price to $0.30/1M - #36090

Closed
AndrewAvery7 wants to merge 1 commit into
BerriAI:mainfrom
AndrewAvery7:fix/xai-grok-4-5-cached-price
Closed

AndrewAvery7 wants to merge 1 commit into
BerriAI:mainfrom
AndrewAvery7:fix/xai-grok-4-5-cached-price

Conversation

@AndrewAvery7

Copy link
Copy Markdown

Problem

xai/grok-4.5 and xai/grok-4.5-latest overcharge cached tokens by 67%.

xAI's pricing table lists, per 1M tokens:

Model Context Short: Input / Cached / Output Long (≥200k): Input / Cached / Output
grok-4.5 500k $2.00 / $0.30 / $6.00 $4.00 / $0.60 / $12.00
grok-4.3 1M $1.25 / $0.20 / $2.50 $2.50 / $0.40 / $5.00

The map had cache_read_input_token_cost: 5e-07 ($0.50) and cache_read_input_token_cost_above_200k_tokens: 1e-06 ($1.00) — both exactly 0.25× the input rate, rather than the published figures.

Why I'm confident this is a transcription error and not my misreading the columns

  • grok-4.3 in the adjacent row is already correct here (2e-07 / 4e-07 = $0.20 / $0.40), and it comes from the same table with the same column layout. Same columns, right answer — so the layout reading is confirmed by the file itself.
  • Every uncached field on grok-4.5 already matches the vendor exactly: 2e-06 / 6e-06 short, 4e-06 / 1.2e-05 long. Only the two cached fields diverge.
  • The cited source explains the cause. Both entries carried "source": "https://docs.x.ai/docs/models", which lists context windows and capabilities and has no cached-price column at all. The cached values appear to have been inferred as 0.25× input rather than read. This PR repoints source at /developers/pricing, where the figures actually live.

Changes

Four values across two model keys, applied to both model_prices_and_context_window.json and litellm/model_prices_and_context_window_backup.json:

xai/grok-4.5, xai/grok-4.5-latest
  cache_read_input_token_cost:                     5e-07 -> 3e-07
  cache_read_input_token_cost_above_200k_tokens:   1e-06 -> 6e-07
  source: .../docs/models -> .../developers/pricing

Uncached rates are untouched.

Test

Adds test_grok_4_5_cached_input_matches_published_pricing to the existing tests/test_litellm/llms/xai/test_xai_cost_calculator.py. It pins both cached bands to the published figures, and also asserts the four uncached rates so a later edit cannot correct one column by breaking another. The assertion fails against the previous values.

Scope

Deliberately one problem. I also noticed deepseek-v4-* carries max_output_tokens: 8192 against DeepSeek's published 384K — but #31018, #32107 and #32417 already propose that fix, so it is not bundled here.

xAI publishes grok-4.5 at $2.00 input / $0.30 cached / $6.00 output for
short context, and $4.00 / $0.60 / $12.00 above the 200k long-context
threshold (https://docs.x.ai/developers/pricing).

The cached figures were recorded as $0.50 and $1.00 — 0.25x the input
rate rather than the published numbers, a 67% overcharge on cached
tokens. The cited source was the models page, which carries no cached
column at all; the rates live on the pricing page, so the source is
updated to match.

Uncached rates were already correct and are unchanged. grok-4.3 in the
same table is transcribed correctly ($0.20 / $0.40), which is what makes
this a transcription error on one row rather than a misread column.

Applied to both the map and its backup.
@CLAassistant

CLAassistant commented Aug 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR corrects cached-input pricing for the two xAI grok-4.5 model aliases and updates their pricing source. It also adds regression assertions covering cached and uncached rates.

  • Changes short-context cached input pricing from $0.50 to $0.30 per million tokens.
  • Changes long-context cached input pricing from $1.00 to $0.60 per million tokens.
  • Keeps the root pricing map and packaged backup map synchronized.
  • Adds data-integrity coverage for both grok-4.5 aliases.

Confidence Score: 4/5

The pricing correction appears safe to merge after removing the newly added inline comments required by repository guidance.

The canonical and backup pricing maps remain synchronized and the regression test verifies both corrected cached-price bands; the only accepted concern is a non-blocking repository-style violation in the test.

Files Needing Attention: tests/test_litellm/llms/xai/test_xai_cost_calculator.py

Important Files Changed

Filename Overview
model_prices_and_context_window.json Correctly updates both grok-4.5 cached-token price tiers and their authoritative source in the canonical pricing map.
litellm/model_prices_and_context_window_backup.json Mirrors the canonical grok-4.5 pricing corrections in the packaged backup map.
tests/test_litellm/llms/xai/test_xai_cost_calculator.py Adds focused pricing assertions, but two newly added inline comments conflict with repository guidance.

Reviews (1): Last reviewed commit: "fix(pricing): correct xai/grok-4.5 cache..." | Re-trigger Greptile

Comment on lines +489 to +490
# Uncached rates were already correct; asserted here so a future
# edit cannot fix one column by breaking another.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 New inline test comments

These explanatory comments conflict with the repository guideline prohibiting new code comments unless explicitly requested, adding prose that maintainers require contributors to omit.

Suggested change
# Uncached rates were already correct; asserted here so a future
# edit cannot fix one column by breaking another.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing AndrewAvery7:fix/xai-grok-4-5-cached-price (e30c42b) with main (ead6252)

Open in CodSpeed

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Superseded by rolling registry audit #37902, which reverified and absorbed the provider-documented metadata changes at field level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants