From f0a8f2b4251097bcb72f7699bfa1cc8a5cd0567b Mon Sep 17 00:00:00 2001 From: Rhys Date: Wed, 11 Feb 2026 10:30:55 +0700 Subject: [PATCH] fix: output_cost_per_token missing for azure/gpt-image-1.5 --- ...odel_prices_and_context_window_backup.json | 2 + model_prices_and_context_window.json | 2 + .../test_gpt_image_cost_calculator.py | 50 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index e54eaf89d72..62da2e60880 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -4318,6 +4318,7 @@ "input_cost_per_image_token": 8e-06, "litellm_provider": "azure", "mode": "image_generation", + "output_cost_per_token": 1e-05, "output_cost_per_image_token": 3.2e-05, "supported_endpoints": [ "/v1/images/generations", @@ -4331,6 +4332,7 @@ "input_cost_per_image_token": 8e-06, "litellm_provider": "azure", "mode": "image_generation", + "output_cost_per_token": 1e-05, "output_cost_per_image_token": 3.2e-05, "supported_endpoints": [ "/v1/images/generations", diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index e54eaf89d72..62da2e60880 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -4318,6 +4318,7 @@ "input_cost_per_image_token": 8e-06, "litellm_provider": "azure", "mode": "image_generation", + "output_cost_per_token": 1e-05, "output_cost_per_image_token": 3.2e-05, "supported_endpoints": [ "/v1/images/generations", @@ -4331,6 +4332,7 @@ "input_cost_per_image_token": 8e-06, "litellm_provider": "azure", "mode": "image_generation", + "output_cost_per_token": 1e-05, "output_cost_per_image_token": 3.2e-05, "supported_endpoints": [ "/v1/images/generations", diff --git a/tests/test_litellm/test_gpt_image_cost_calculator.py b/tests/test_litellm/test_gpt_image_cost_calculator.py index 620c0734980..31190508d84 100644 --- a/tests/test_litellm/test_gpt_image_cost_calculator.py +++ b/tests/test_litellm/test_gpt_image_cost_calculator.py @@ -268,6 +268,56 @@ class TestGPTImage15OutputImageTokens: f"Expected {expected_cost}, got {cost}. " f"Image tokens may not be included in cost calculation." ) + + def test_azure_gpt_image_15_output_image_tokens_cost(self): + """ + Test that output image tokens are correctly included in cost calculation for Azure. + """ + # Simulate gpt-image-1.5 response with output_tokens_details + usage = Usage( + prompt_tokens=200, + completion_tokens=4800, + total_tokens=5000, + prompt_tokens_details=PromptTokensDetailsWrapper( + text_tokens=200, + image_tokens=0, + ), + completion_tokens_details=CompletionTokensDetailsWrapper( + text_tokens=600, + image_tokens=4200, + ), + ) + + image_response = ImageResponse( + created=1234567890, + data=[ImageObject(b64_json="test")], + ) + image_response.usage = usage + image_response._hidden_params = {"custom_llm_provider": "azure"} + + cost = litellm.completion_cost( + completion_response=image_response, + model="gpt-image-1.5", + call_type="image_generation", + custom_llm_provider="azure", + ) + + # Azure gpt-image-1.5 pricing: + # - input_cost_per_token: 5e-06 ($5/1M for text input) + # - output_cost_per_token: 1e-05 ($10/1M for text output) + # - output_cost_per_image_token: 3.2e-05 ($32/1M for image output) + # + # Expected cost: + # Input text: 200 * $5/1M = $0.001 + # Output text: 600 * $10/1M = $0.006 + # Output image: 4200 * $32/1M = $0.1344 + # Total: $0.1414 + expected_cost = 200 * 5e-06 + 600 * 1e-05 + 4200 * 3.2e-05 + + assert abs(cost - expected_cost) < 1e-6, ( + f"Expected {expected_cost}, got {cost}. " + f"Image tokens may not be included in cost calculation." + ) class TestCompletionCostIntegration: