litellm - ✅(Solved) Fix [Bug]: OpenAI GPT-Image-2 cost [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#26863Fetched 2026-05-01 05:34:42
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×2referenced ×1

Fix Action

Fixed

PR fix notes

PR #26865: fix(cost): add gpt-image-2 pricing and routing

Description (problem / solution / changelog)

Summary

Closes #26863. gpt-image-2 cost was always 0 because it was both missing from the cost map and misrouted to the per-image (DALL-E) calculator instead of the token-based calculator.

Changes

  • Cost map (model_prices_and_context_window.json + litellm/model_prices_and_context_window_backup.json): add gpt-image-2, gpt-image-2-2026-04-21, azure/gpt-image-2, azure/gpt-image-2-2026-04-21 with token pricing per OpenAI docs:
    • text input: $5/1M, cached $1.25/1M
    • image input: $8/1M, cached $2/1M
    • image output: $30/1M
  • Routing (litellm/litellm_core_utils/llm_cost_calc/utils.py): replace the "gpt-image-1" in model_lower substring check with model_lower.startswith("gpt-image-") or "/gpt-image-" in model_lower. The old substring incidentally matched gpt-image-1.5, but never gpt-image-2. New matcher covers all current and future gpt-image-* variants and Azure-prefixed forms.
  • Tests (tests/test_litellm/test_gpt_image_cost_calculator.py): add TestGPTImage2Cost with two cases — direct completion_cost for gpt-image-2, and azure/gpt-image-2 routing through CostCalculatorUtils. Both use LITELLM_LOCAL_MODEL_COST_MAP=True so they don't depend on the remote cost map.

Test plan

  • pytest tests/test_litellm/test_gpt_image_cost_calculator.py -v → 10/10 pass
  • Verified gpt-image-1 and gpt-image-1.5 still route correctly (existing tests unchanged)
  • Verified DALL-E still routes to per-image calculator (existing test unchanged)

Notes

  • output_cost_per_token (text output) is intentionally omitted — OpenAI's gpt-image-2 pricing section lists token costs but does not include a separate text output rate (unlike gpt-image-1.5 which lists $10/1M).
  • Per-image quality/size variants (high/1024-x-1024/gpt-image-2 etc.) are not added because OpenAI's gpt-image-2 pricing page only lists token-based pricing.

Changed files

  • litellm/litellm_core_utils/llm_cost_calc/utils.py (modified, +2/-2)
  • litellm/model_prices_and_context_window_backup.json (modified, +58/-0)
  • model_prices_and_context_window.json (modified, +58/-0)
  • tests/test_litellm/test_gpt_image_cost_calculator.py (modified, +88/-0)

PR #26866: feat(pricing): add gpt-image-2 and azure_ai/gpt-image-2 model pricing

Description (problem / solution / changelog)

Summary

Adds pricing entries for OpenAI's gpt-image-2 model and its Azure AI Foundry (azure_ai/gpt-image-2) variant to both model_prices_and_context_window.json and litellm/model_prices_and_context_window_backup.json.

Pricing values sourced from https://platform.openai.com/docs/models/gpt-image-2 and https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/:

FieldValue
input_cost_per_token (text)5e-06 ($5.00 / 1M tokens)
cache_read_input_token_cost1.25e-06 ($1.25 / 1M tokens)
input_cost_per_image_token8e-06 ($8.00 / 1M image tokens)
cache_read_input_image_token_cost2e-06 ($2.00 / 1M image tokens)
output_cost_per_image_token3e-05 ($30.00 / 1M image tokens)

Both openai and azure_ai providers support /v1/images/generations and /v1/images/edits endpoints.

Closes #26765 Relates to #26863 (gpt-image-2 cost always 0 — this adds the missing cost entry)

Test plan

  • Both JSON files parse as valid JSON (python3 -c "import json; json.load(open(...))")
  • Pricing values match the official OpenAI API pricing page for gpt-image-2
  • Entry format mirrors existing gpt-image-1 / azure/gpt-image-1 structure

Changed files

  • litellm/model_prices_and_context_window_backup.json (modified, +28/-0)
  • model_prices_and_context_window.json (modified, +28/-0)
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

the cost of an image generation using gpt-image-2 is always 0

using gpt-image 1.5 the cost is well calculated

Steps to Reproduce

  1. create an image with the model using the playground
  2. see logs

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

las version on staging branch

Twitter / LinkedIn details

No response

extent analysis

TL;DR

The issue with the cost of image generation using GPT-Image-2 always being 0 may be resolved by investigating the cost calculation logic differences between GPT-Image-1.5 and GPT-Image-2.

Guidance

  • Review the cost calculation logic in GPT-Image-2 to identify potential discrepancies with GPT-Image-1.5.
  • Compare the model configurations and parameters used in both versions to ensure consistency.
  • Investigate the logs for any errors or warnings related to cost calculation in GPT-Image-2.
  • Consider testing with a different image generation model or version to isolate the issue.

Notes

The lack of relevant log output and specific details about the cost calculation logic in GPT-Image-2 makes it challenging to provide a more precise solution.

Recommendation

Apply workaround: Temporarily use GPT-Image-1.5 for image generation until the cost calculation issue in GPT-Image-2 is resolved, as it is known to calculate costs correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Bug]: OpenAI GPT-Image-2 cost [2 pull requests, 1 participants]