fix: output_cost_per_token missing for azure/gpt-image-1.5

This commit is contained in:
Rhys 2026-02-11 10:30:55 +07:00
parent 6134984008
commit f0a8f2b425
3 changed files with 54 additions and 0 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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: