The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(cost): repoint the Azure image cost test at gpt-image-2 (#42631)
devin-ai-integration[bot]2d2b7e8fa048
diff --git a/tests/local_testing/test_completion_cost.py b/tests/local_testing/test_completion_cost.pyindex 3ce99f893d8..c24e6c32369 100644--- a/tests/local_testing/test_completion_cost.py+++ b/tests/local_testing/test_completion_cost.py@@ -5,7 +5,7 @@ import litellm.cost_calculatorimport asyncioimport time-from typing import Optional+from typing import Final, Optionalfrom unittest.mock import MagicMock, patchimport pytest@@ -21,6 +21,9 @@ import jsonimport httpxfrom litellm.types.utils import PromptTokensDetailsfrom litellm.litellm_core_utils.litellm_logging import CustomLogger+from litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response import (+ convert_to_model_response_object,+)class CustomLoggingHandler(CustomLogger):@@ -328,35 +331,39 @@ def test_whisper_azure():assert round(cost, 5) == round(expected_cost, 5)-def test_dalle_3_azure_cost_tracking():- litellm.set_verbose = True- # model = "azure/dall-e-3-test"- # response = litellm.image_generation(- # model=model,- # prompt="A cute baby sea otter",- # api_version="2023-12-01-preview",- # api_base=os.getenv("AZURE_SWEDEN_API_BASE"),- # api_key=os.getenv("AZURE_SWEDEN_API_KEY"),- # base_model="dall-e-3",- # )- # print(f"response: {response}")- response = litellm.ImageResponse(- created=1710265780,- data=[- {- "b64_json": None,- "revised_prompt": "A close-up image of an adorable baby sea otter. Its fur is thick and fluffy to provide buoyancy and insulation against the cold water. Its eyes are round, curious and full of life. It's lying on its back, floating effortlessly on the calm sea surface under the warm sun. Surrounding the otter are patches of colorful kelp drifting along the gentle waves, giving the scene a touch of vibrancy. The sea otter has its small paws folded on its chest, and it seems to be taking a break from its play.",- "url": "test-azure-blob-url-with-sas-token",- }- ],+def test_gpt_image_2_azure_cost_tracking():+ azure_image_generation_response: Final = {+ "created": 1758585600,+ "data": [{"b64_json": "iVBORw0KGgo=", "revised_prompt": None, "url": None}],+ "output_format": "png",+ "quality": "low",+ "size": "1024x1024",+ "usage": {+ "input_tokens": 12,+ "input_tokens_details": {"image_tokens": 0, "text_tokens": 12},+ "output_tokens": 196,+ "output_tokens_details": {"image_tokens": 196, "text_tokens": 0},+ "total_tokens": 208,+ },+ }+ response: Final = convert_to_model_response_object(+ response_object=azure_image_generation_response,+ model_response_object=litellm.ImageResponse(),+ response_type="image_generation",+ hidden_params={"model": "gpt-image-2", "custom_llm_provider": "azure"},)- response.usage = {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0}- response._hidden_params = {"model": "dall-e-3", "model_id": None}- print(f"response hidden params: {response._hidden_params}")- cost = litellm.completion_cost(- completion_response=response, call_type="image_generation"++ cost: Final = litellm.completion_cost(+ completion_response=response,+ model="azure/my-gpt-image-2-deployment",+ custom_llm_provider="azure",+ base_model="gpt-image-2",+ call_type="image_generation",)- assert cost > 0++ pricing: Final = litellm.model_cost["azure/gpt-image-2"]+ expected_cost: Final = pricing["input_cost_per_token"] * 12 + pricing["output_cost_per_image_token"] * 196+ assert round(cost, 8) == round(expected_cost, 8)def test_replicate_llama3_cost_tracking():