feat(openai): add gpt-image-2 to model prices and context window

gpt-image-2 was released on 2026-04-21 and is available in the API.
This adds pricing entries for the model:

- Base entry: $8/1M image input tokens, $32/1M image output tokens
- Per-quality per-size entries for low/medium/high at 1024x1024:
  - low:    $0.006/image
  - medium: $0.053/image
  - high:   $0.211/image

Closes #26232

Relates to litellm_oss_branch
This commit is contained in:
Kcstring 2026-04-23 21:46:52 +08:00
parent 3bd76e2aa0
commit 0d7fa42359
2 changed files with 107 additions and 0 deletions

View file

@ -18268,6 +18268,18 @@
"supports_vision": true,
"supports_pdf_input": true
},
"gpt-image-2": {
"input_cost_per_token": 8e-06,
"input_cost_per_image_token": 8e-06,
"output_cost_per_image_token": 3.2e-05,
"litellm_provider": "openai",
"mode": "image_generation",
"supported_endpoints": [
"/v1/images/generations",
"/v1/images/edits"
],
"supports_vision": true
},
"low/1024-x-1024/gpt-image-1.5": {
"input_cost_per_image": 0.009,
"litellm_provider": "openai",
@ -18598,6 +18610,36 @@
"supports_vision": true,
"supports_pdf_input": true
},
"low/1024-x-1024/gpt-image-2": {
"input_cost_per_image": 0.006,
"litellm_provider": "openai",
"mode": "image_generation",
"supported_endpoints": [
"/v1/images/generations",
"/v1/images/edits"
],
"supports_vision": true
},
"medium/1024-x-1024/gpt-image-2": {
"input_cost_per_image": 0.053,
"litellm_provider": "openai",
"mode": "image_generation",
"supported_endpoints": [
"/v1/images/generations",
"/v1/images/edits"
],
"supports_vision": true
},
"high/1024-x-1024/gpt-image-2": {
"input_cost_per_image": 0.211,
"litellm_provider": "openai",
"mode": "image_generation",
"supported_endpoints": [
"/v1/images/generations",
"/v1/images/edits"
],
"supports_vision": true
},
"gpt-5": {
"cache_read_input_token_cost": 1.25e-07,
"cache_read_input_token_cost_flex": 6.25e-08,

View file

@ -8,6 +8,10 @@ gpt-image-1 uses token-based pricing:
- Text Input: $5.00/1M tokens
- Image Input: $10.00/1M tokens
- Image Output: $40.00/1M tokens
gpt-image-2 uses token-based pricing:
- Image Input: $8.00/1M tokens
- Image Output: $32.00/1M tokens
"""
import os
@ -305,3 +309,64 @@ class TestCompletionCostIntegration:
if __name__ == "__main__":
pytest.main([__file__, "-v"])
class TestGPTImage2CostCalculator:
"""Test the OpenAI gpt-image-2 cost calculator.
gpt-image-2 pricing (https://openai.com/api/pricing/):
- Image Input: $8.00 / 1M tokens (8e-6 per token)
- Image Output: $32.00 / 1M tokens (3.2e-5 per token)
"""
def test_gpt_image_2_token_cost(self):
"""Test token-based cost calculation for gpt-image-2."""
from litellm.llms.openai.image_generation.cost_calculator import cost_calculator
usage = ImageUsage(
input_tokens=1000,
output_tokens=5000,
total_tokens=6000,
input_tokens_details=ImageUsageInputTokensDetails(
text_tokens=0,
image_tokens=1000,
),
)
image_response = ImageResponse(
created=1234567890,
data=[ImageObject(url="http://example.com/image.jpg")],
)
image_response.usage = usage
cost = cost_calculator(
model="gpt-image-2",
image_response=image_response,
custom_llm_provider="openai",
)
# Expected cost:
# Image input: 1000 * $8/1M = 0.008
# Image output: 5000 * $32/1M = 0.16
# Total: 0.168
expected_cost = 1000 * 8e-6 + 5000 * 3.2e-5
assert abs(cost - expected_cost) < 1e-6, f"Expected {expected_cost}, got {cost}"
def test_gpt_image_2_in_model_prices(self):
"""Test that gpt-image-2 is present in the model prices registry."""
model_info = litellm.get_model_info("gpt-image-2")
assert model_info is not None, "gpt-image-2 not found in model prices"
assert model_info.get("litellm_provider") == "openai"
assert model_info.get("mode") == "image_generation"
assert model_info.get("input_cost_per_image_token") == 8e-6
assert model_info.get("output_cost_per_image_token") == 3.2e-5
def test_gpt_image_2_per_quality_entries(self):
"""Test that per-quality per-size entries exist for gpt-image-2."""
for quality in ("low", "medium", "high"):
key = f"{quality}/1024-x-1024/gpt-image-2"
model_info = litellm.get_model_info(key)
assert model_info is not None, f"{key} not found in model prices"
assert model_info.get("litellm_provider") == "openai"
assert model_info.get("mode") == "image_generation"
assert model_info.get("input_cost_per_image") is not None