Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions litellm/model_prices_and_context_window_backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -7195,7 +7195,6 @@
"input_cost_per_image_token": 8e-06,
"litellm_provider": "azure",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
"/v1/images/generations",
Expand All @@ -7210,7 +7209,6 @@
"input_cost_per_image_token": 8e-06,
"litellm_provider": "azure",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
"/v1/images/generations",
Expand Down Expand Up @@ -22189,7 +22187,6 @@
"input_cost_per_token": 5e-06,
"litellm_provider": "openai",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"input_cost_per_image_token": 8e-06,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
Expand All @@ -22204,7 +22201,6 @@
"input_cost_per_token": 5e-06,
"litellm_provider": "openai",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"input_cost_per_image_token": 8e-06,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
Expand Down
4 changes: 0 additions & 4 deletions model_prices_and_context_window.json
Original file line number Diff line number Diff line change
Expand Up @@ -7195,7 +7195,6 @@
"input_cost_per_image_token": 8e-06,
"litellm_provider": "azure",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
"/v1/images/generations",
Expand All @@ -7210,7 +7209,6 @@
"input_cost_per_image_token": 8e-06,
"litellm_provider": "azure",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
"/v1/images/generations",
Expand Down Expand Up @@ -22264,7 +22262,6 @@
"input_cost_per_token": 5e-06,
"litellm_provider": "openai",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"input_cost_per_image_token": 8e-06,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
Expand All @@ -22279,7 +22276,6 @@
"input_cost_per_token": 5e-06,
"litellm_provider": "openai",
"mode": "image_generation",
"output_cost_per_token": 1e-05,
"input_cost_per_image_token": 8e-06,
"output_cost_per_image_token": 3e-05,
"supported_endpoints": [
Expand Down
19 changes: 4 additions & 15 deletions tests/test_litellm/test_gpt_image_cost_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def test_gpt_image_2_cost_with_text_and_image_tokens(self):
image_tokens=500,
),
completion_tokens_details=CompletionTokensDetailsWrapper(
text_tokens=1000,
image_tokens=4000,
image_tokens=5000,
),
)

Expand All @@ -192,12 +191,7 @@ def test_gpt_image_2_cost_with_text_and_image_tokens(self):
custom_llm_provider="openai",
)

# GPT Image 2 pricing:
# Text input: 100 * $5/1M = 0.0005
# Image input: 500 * $8/1M = 0.004
# Text output: 1000 * $10/1M = 0.01
# Image output: 4000 * $30/1M = 0.12
expected_cost = 0.0005 + 0.004 + 0.01 + 0.12
expected_cost = 100 * 5e-6 + 500 * 8e-6 + 5000 * 3e-5
assert abs(cost - expected_cost) < 1e-6, f"Expected {expected_cost}, got {cost}"


Expand Down Expand Up @@ -432,10 +426,7 @@ def test_gpt_image_2_output_priced_as_image_when_no_breakdown(self):
f"are likely being priced at the text output_cost_per_token rate."
)

def test_gpt_image_2_chat_usage_without_breakdown_is_costed_not_zero(self):
"""A chat ``Usage`` with ``completion_tokens_details=None`` must still be
costed via ``generic_cost_per_token`` (output at the text rate) rather than
erroring or silently returning 0.0."""
def test_gpt_image_2_chat_usage_without_breakdown_uses_image_rate(self):
from litellm.llms.openai.image_generation.cost_calculator import (
cost_calculator,
)
Expand Down Expand Up @@ -463,9 +454,7 @@ def test_gpt_image_2_chat_usage_without_breakdown_is_costed_not_zero(self):
custom_llm_provider="openai",
)

# No output breakdown -> output priced at the text rate (output_cost_per_token):
# text in 100*$5/1M + image in 500*$8/1M + output 5000*$10/1M
expected_cost = 100 * 5e-6 + 500 * 8e-6 + 5000 * 1e-5
expected_cost = 100 * 5e-6 + 500 * 8e-6 + 5000 * 3e-5
assert abs(cost - expected_cost) < 1e-6, f"Expected {expected_cost}, got {cost}"


Expand Down
29 changes: 27 additions & 2 deletions tests/test_litellm/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_gpt_image_2_provider_and_model_info(local_model_cost_map):
assert model_info["mode"] == "image_generation"
assert model_info["input_cost_per_token"] == 5e-06
assert model_info["input_cost_per_image_token"] == 8e-06
assert model_info["output_cost_per_token"] == 1e-05
assert model_info["output_cost_per_token"] == 0
assert model_info["output_cost_per_image_token"] == 3e-05
assert (
"/v1/images/generations"
Expand All @@ -271,6 +271,7 @@ def test_gpt_image_2_snapshot_model_info(local_model_cost_map):
model_info = litellm.get_model_info(model="gpt-image-2-2026-04-21")
assert model_info["litellm_provider"] == "openai"
assert model_info["mode"] == "image_generation"
assert model_info["output_cost_per_token"] == 0
assert model_info["output_cost_per_image_token"] == 3e-05


Expand All @@ -289,10 +290,34 @@ def test_azure_gpt_image_2_model_info(local_model_cost_map):
assert model_info["mode"] == "image_generation"
assert model_info["input_cost_per_token"] == 5e-06
assert model_info["input_cost_per_image_token"] == 8e-06
assert model_info["output_cost_per_token"] == 1e-05
assert model_info["output_cost_per_token"] == 0
assert model_info["output_cost_per_image_token"] == 3e-05


def test_gpt_image_2_cost_maps_have_no_text_output_price():
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
cost_map_paths = (
os.path.join(repo_root, "model_prices_and_context_window.json"),
os.path.join(
repo_root, "litellm", "model_prices_and_context_window_backup.json"
),
)
model_names = (
"gpt-image-2",
"gpt-image-2-2026-04-21",
"azure/gpt-image-2",
"azure/gpt-image-2-2026-04-21",
)

for cost_map_path in cost_map_paths:
with open(cost_map_path) as cost_map_file:
cost_map = json.load(cost_map_file)

for model_name in model_names:
assert "output_cost_per_token" not in cost_map[model_name]
assert cost_map[model_name]["output_cost_per_image_token"] == 3e-05


def test_all_model_configs():
from litellm.llms.vertex_ai.vertex_ai_partner_models.ai21.transformation import (
VertexAIAi21Config,
Expand Down
Loading