fix(cost_calculator): correct gpt-image-1 cost calculation using token-based pricing #17906
+486
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
fix(cost_calculator): correct gpt-image-1 cost calculation using token-based pricing
Relevant issues
Fixes #13847
Pre-Submission checklist
tests/litellm/directorymake test-unitType
🐛 Bug Fix
Changes
Summary
The current cost calculator for
gpt-image-1uses pixel-based pricing (inherited from DALL-E), but OpenAI'sgpt-image-1actually uses token-based pricing.Example
Old calculation (incorrect - DALL-E style):
New calculation (token-based):
Solution
Updated pricing JSON: Changed
gpt-image-1entries frominput_cost_per_pixelto token-based fields:input_cost_per_token: 5e-06 ($5/1M)input_cost_per_image_token: 1e-05 ($10/1M)output_cost_per_image_token: 4e-05 ($40/1M)New cost calculator:
litellm/llms/openai/image_generation/cost_calculator.pyusagedata from the API responseUpdated router: Routes
gpt-image-1models to the new token-based calculator while DALL-E continues to use pixel-based calculationFiles changed
model_prices_and_context_window.json- Updated gpt-image-1 pricinglitellm/model_prices_and_context_window_backup.json- Samelitellm/llms/openai/image_generation/cost_calculator.py- New calculatorlitellm/litellm_core_utils/llm_cost_calc/utils.py- Router updatetests/test_litellm/test_gpt_image_cost_calculator.py- 8 new tests