Skip to content

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]

Fix - support azure dall e custom pricing (#10339)

Krish Dholakia31313dd4899b
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py
index eafd924bc63..593cdb2850a 100644
--- a/litellm/cost_calculator.py
+++ b/litellm/cost_calculator.py
@@ -643,9 +643,9 @@ def completion_cost( # noqa: PLR0915
or isinstance(completion_response, dict)
): # tts returns a custom class
if isinstance(completion_response, dict):
- usage_obj: Optional[Union[dict, Usage]] = (
- completion_response.get("usage", {})
- )
+ usage_obj: Optional[
+ Union[dict, Usage]
+ ] = completion_response.get("usage", {})
else:
usage_obj = getattr(completion_response, "usage", {})
if isinstance(usage_obj, BaseModel) and not _is_known_usage_objects(
@@ -1124,6 +1124,7 @@ def default_image_cost_calculator(
model_name_with_v2_quality,
model_with_quality_without_provider,
model_without_provider,
+ model,
]
for model in models_to_check:
if model in litellm.model_cost:
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py
index 9f77d5b3629..1e419387bc9 100644
--- a/litellm/litellm_core_utils/litellm_logging.py
+++ b/litellm/litellm_core_utils/litellm_logging.py
@@ -63,7 +63,7 @@ from litellm.types.llms.openai import (
ResponsesAPIResponse,
)
from litellm.types.rerank import RerankResponse
-from litellm.types.router import SPECIAL_MODEL_INFO_PARAMS
+from litellm.types.router import CustomPricingLiteLLMParams
from litellm.types.utils import (
CallTypes,
EmbeddingResponse,
@@ -251,9 +251,9 @@ class Logging(LiteLLMLoggingBaseClass):
self.litellm_trace_id: str = litellm_trace_id or str(uuid.uuid4())
self.function_id = function_id
self.streaming_chunks: List[Any] = [] # for generating complete stream response
- self.sync_streaming_chunks: List[Any] = (
- []
- ) # for generating complete stream response
+ self.sync_streaming_chunks: List[
+ Any
+ ] = [] # for generating complete stream response
self.log_raw_request_response = log_raw_request_response
# Initialize dynamic callbacks
@@ -446,13 +446,10 @@ class Logging(LiteLLMLoggingBaseClass):
if "stream_options" in additional_params:
self.stream_options = additional_params["stream_options"]
## check if custom pricing set ##
- if (
- litellm_params.get("input_cost_per_token") is not None
- or litellm_params.get("input_cost_per_second") is not None
- or litellm_params.get("output_cost_per_token") is not None
- or litellm_params.get("output_cost_per_second") is not None
- ):
- self.custom_pricing = True
+ custom_pricing_keys = CustomPricingLiteLLMParams.model_fields.keys()
+ for key in custom_pricing_keys:
+ if litellm_params.get(key) is not None:
+ self.custom_pricing = True
if "custom_llm_provider" in self.model_call_details:
self.custom_llm_provider = self.model_call_details["custom_llm_provider"]
@@ -544,9 +541,9 @@ class Logging(LiteLLMLoggingBaseClass):
if anthropic_cache_control_logger := AnthropicCacheControlHook.get_custom_logger_for_anthropic_cache_control_hook(
non_default_params
):
- self.model_call_details["prompt_integration"] = (
- anthropic_cache_control_logger.__class__.__name__
- )
+ self.model_call_details[
+ "prompt_integration"
+ ] = anthropic_cache_control_logger.__class__.__name__
return anthropic_cache_control_logger
return None
@@ -598,9 +595,9 @@ class Logging(LiteLLMLoggingBaseClass):
model
): # if model name was changes pre-call, overwrite the initial model call name with the new one
self.model_call_details["model"] = model
- self.model_call_details["litellm_params"]["api_base"] = (
- self._get_masked_api_base(additional_args.get("api_base", ""))
- )
+ self.model_call_details["litellm_params"][
+ "api_base"
+ ] = self._get_masked_api_base(additional_args.get("api_base", ""))
def pre_call(self, input, api_key, model=None, additional_args={}): # noqa: PLR0915
# Log the exact input to the LLM API
@@ -629,10 +626,10 @@ class Logging(LiteLLMLoggingBaseClass):
try:
# [Non-blocking Extra Debug Information in metadata]
if turn_off_message_logging is True:
- _metadata["raw_request"] = (
- "redacted by litellm. \
+ _metadata[
+ "raw_request"
+ ] = "redacted by litellm. \
'litellm.turn_off_message_logging=True'"
- )
else:
curl_command = self._get_request_curl_command(
api_base=additional_args.get("api_base", ""),
@@ -643,32 +640,32 @@ class Logging(LiteLLMLoggingBaseClass):
_metadata["raw_request"] = str(curl_command)
# split up, so it's easier to parse in the UI
- self.model_call_details["raw_request_typed_dict"] = (
- RawRequestTypedDict(
- raw_request_api_base=str(
- additional_args.get("api_base") or ""
- ),
- raw_request_body=self._get_raw_request_body(
- additional_args.get("complete_input_dict", {})
- ),
- raw_request_headers=self._get_masked_headers(
- additional_args.get("headers", {}) or {},
- ignore_sensitive_headers=True,
- ),
- error=None,
- )
+ self.model_call_details[
+ "raw_request_typed_dict"
+ ] = RawRequestTypedDict(
+ raw_request_api_base=str(
+ additional_args.get("api_base") or ""
+ ),
+ raw_request_body=self._get_raw_request_body(
+ additional_args.get("complete_input_dict", {})
+ ),
+ raw_request_headers=self._get_masked_headers(
+ additional_args.get("headers", {}) or {},
+ ignore_sensitive_headers=True,
+ ),
+ error=None,
)
except Exception as e:
- self.model_call_details["raw_request_typed_dict"] = (
- RawRequestTypedDict(
- error=str(e),
- )
+ self.model_call_details[
+ "raw_request_typed_dict"
+ ] = RawRequestTypedDict(
+ error=str(e),
)
- _metadata["raw_request"] = (
- "Unable to Log \
+ _metadata[
+ "raw_request"
+ ] = "Unable to Log \
raw request: {}".format(
- str(e)
- )
+ str(e)
)
if self.logger_fn and callable(self.logger_fn):
try:
@@ -998,9 +995,9 @@ class Logging(LiteLLMLoggingBaseClass):
verbose_logger.debug(
f"response_cost_failure_debug_information: {debug_info}"
)
- self.model_call_details["response_cost_failure_debug_information"] = (
- debug_info
- )
+ self.model_call_details[
+ "response_cost_failure_debug_information"
+ ] = debug_info
return None
try:
@@ -1025,9 +1022,9 @@ class Logging(LiteLLMLoggingBaseClass):
verbose_logger.debug(
f"response_cost_failure_debug_information: {debug_info}"
)
- self.model_call_details["response_cost_failure_debug_information"] = (
- debug_info
- )
+ self.model_call_details[
+ "response_cost_failure_debug_information"
+ ] = debug_info
return None
@@ -1087,9 +1084,9 @@ class Logging(LiteLLMLoggingBaseClass):
end_time = datetime.datetime.now()
if self.completion_start_time is None:
self.completion_start_time = end_time
- self.model_call_details["completion_start_time"] = (
- self.completion_start_time
- )
+ self.model_call_details[
+ "completion_start_time"
+ ] = self.completion_start_time
self.model_call_details["log_event_type"] = "successful_api_call"
self.model_call_details["end_time"] = end_time
self.model_call_details["cache_hit"] = cache_hit
@@ -1168,39 +1165,39 @@ class Logging(LiteLLMLoggingBaseClass):
"response_cost"
]
else:
- self.model_call_details["response_cost"] = (
- self._response_cost_calculator(result=logging_result)
- )
+ self.model_call_details[
+ "response_cost"
+ ] = self._response_cost_calculator(result=logging_result)
## STANDARDIZED LOGGING PAYLOAD
- self.model_call_details["standard_logging_object"] = (
- get_standard_logging_object_payload(
- kwargs=self.model_call_details,
- init_response_obj=logging_result,
- start_time=start_time,
- end_time=end_time,
- logging_obj=self,
- status="success",
- standard_built_in_tools_params=self.standard_built_in_tools_params,
- )
+ self.model_call_details[
+ "standard_logging_object"
+ ] = get_standard_logging_object_payload(
+ kwargs=self.model_call_details,
+ init_response_obj=logging_result,
+ start_time=start_time,
+ end_time=end_time,
+ logging_obj=self,
+ status="success",
+ standard_built_in_tools_params=self.standard_built_in_tools_params,
)
elif isinstance(result, dict) or isinstance(result, list):
## STANDARDIZED LOGGING PAYLOAD
- self.model_call_details["standard_logging_object"] = (
- get_standard_logging_object_payload(
- kwargs=self.model_call_details,
- init_response_obj=result,
- start_time=start_time,
- end_time=end_time,
- logging_obj=self,
- status="success",
- standard_built_in_tools_params=self.standard_built_in_tools_params,
- )
+ self.model_call_details[
+ "standard_logging_object"
+ ] = get_standard_logging_object_payload(
+ kwargs=self.model_call_details,
+ init_response_obj=result,
+ start_time=start_time,
+ end_time=end_time,
+ logging_obj=self,
+ status="success",
+ standard_built_in_tools_params=self.standard_built_in_tools_params,
)
elif standard_logging_object is not None:
- self.model_call_details["standard_logging_object"] = (
- standard_logging_object
- )
+ self.model_call_details[
+ "standard_logging_object"
+ ] = standard_logging_object
else: # streaming chunks + image gen.
self.model_call_details["response_cost"] = None
@@ -1256,23 +1253,23 @@ class Logging(LiteLLMLoggingBaseClass):
verbose_logger.debug(
"Logging Details LiteLLM-Success Call streaming complete"
)
- self.model_call_details["complete_streaming_response"] = (
- complete_streaming_response
- )
- self.model_call_details["response_cost"] = (
- self._response_cost_calculator(result=complete_streaming_response)
- )
+ self.model_call_details[
+ "complete_streaming_response"
+ ] = complete_streaming_response
+ self.model_call_details[
+ "response_cost"
+ ] = self._response_cost_calculator(result=complete_streaming_response)
## STANDARDIZED LOGGING PAYLOAD
- self.model_call_details["standard_logging_object"] = (
- get_standard_logging_object_payload(
- kwargs=self.model_call_details,
- init_response_obj=complete_streaming_response,
- start_time=start_time,
- end_time=end_time,
- logging_obj=self,
- status="success",
- standard_built_in_tools_params=self.standard_built_in_tools_params,
- )
+ self.model_call_details[
+ "standard_logging_object"
+ ] = get_standard_logging_object_payload(
+ kwargs=self.model_call_details,
+ init_response_obj=complete_streaming_response,
+ start_time=start_time,
+ end_time=end_time,
+ logging_obj=self,
+ status="success",
+ standard_built_in_tools_params=self.standard_built_in_tools_params,
)
callbacks = self.get_combined_callback_list(
dynamic_success_callbacks=self.dynamic_success_callbacks,
@@ -1621,10 +1618,10 @@ class Logging(LiteLLMLoggingBaseClass):
)
else:
if self.stream and complete_streaming_response:
- self.model_call_details["complete_response"] = (
- self.model_call_details.get(
- "complete_streaming_response", {}
- )
+ self.model_call_details[
+ "complete_response"
+ ] = self.model_call_details.get(
+ "complete_streaming_response", {}
)
result = self.model_call_details["complete_response"]
openMeterLogger.log_success_event(
@@ -1664,10 +1661,10 @@ class Logging(LiteLLMLoggingBaseClass):
)
else:
if self.stream and complete_streaming_response:
- self.model_call_details["complete_response"] = (
- self.model_call_details.get(
- "complete_streaming_response", {}
- )
+ self.model_call_details[
+ "complete_response"
+ ] = self.model_call_details.get(
+ "complete_streaming_response", {}
)
result = self.model_call_details["complete_response"]
@@ -1774,9 +1771,9 @@ class Logging(LiteLLMLoggingBaseClass):
if complete_streaming_response is not None:
print_verbose("Async success callbacks: Got a complete streaming response")
- self.model_call_details["async_complete_streaming_response"] = (
- complete_streaming_response
- )
+ self.model_call_details[
+ "async_complete_streaming_response"
+ ] = complete_streaming_response
try:
if self.model_call_details.get("cache_hit", False) is True:
self.model_call_details["response_cost"] = 0.0
@@ -1786,10 +1783,10 @@ class Logging(LiteLLMLoggingBaseClass):
model_call_details=self.model_call_details
)
# base_model defaults to None if not set on model_info
- self.model_call_details["response_cost"] = (
- self._response_cost_calculator(
- result=complete_streaming_response
- )
+ self.model_call_details[
+ "response_cost"
+ ] = self._response_cost_calculator(
+ result=complete_streaming_response
)
verbose_logger.debug(
@@ -1802,16 +1799,16 @@ class Logging(LiteLLMLoggingBaseClass):
self.model_call_details["response_cost"] = None
## STANDARDIZED LOGGING PAYLOAD
- self.model_call_details["standard_logging_object"] = (
- get_standard_logging_object_payload(
- kwargs=self.model_call_details,
- init_response_obj=complete_streaming_response,
- start_time=start_time,
- end_time=end_time,
- logging_obj=self,
- status="success",
- standard_built_in_tools_params=self.standard_built_in_tools_params,
- )
+ self.model_call_details[
+ "standard_logging_object"
+ ] = get_standard_logging_object_payload(
+ kwargs=self.model_call_details,
+ init_response_obj=complete_streaming_response,
+ start_time=start_time,
+ end_time=end_time,
+ logging_obj=self,
+ status="success",
+ standard_built_in_tools_params=self.standard_built_in_tools_params,
)
callbacks = self.get_combined_callback_list(
dynamic_success_callbacks=self.dynamic_async_success_callbacks,
@@ -2017,18 +2014,18 @@ class Logging(LiteLLMLoggingBaseClass):
## STANDARDIZED LOGGING PAYLOAD
- self.model_call_details["standard_logging_object"] = (
- get_standard_logging_object_payload(
- kwargs=self.model_call_details,
- init_response_obj={},
- start_time=start_time,
- end_time=end_time,
- logging_obj=self,
- status="failure",
- error_str=str(exception),
- original_exception=exception,
- standard_built_in_tools_params=self.standard_built_in_tools_params,
- )
+ self.model_call_details[
+ "standard_logging_object"
+ ] = get_standard_logging_object_payload(
+ kwargs=self.model_call_details,
+ init_response_obj={},
+ start_time=start_time,
+ end_time=end_time,
+ logging_obj=self,
+ status="failure",
+ error_str=str(exception),
+ original_exception=exception,
+ standard_built_in_tools_params=self.standard_built_in_tools_params,
)
return start_time, end_time
@@ -2802,9 +2799,9 @@ def _init_custom_logger_compatible_class( # noqa: PLR0915
endpoint=arize_config.endpoint,
)
- os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = (
- f"space_key={arize_config.space_key},api_key={arize_config.api_key}"
- )
+ os.environ[
+ "OTEL_EXPORTER_OTLP_TRACES_HEADERS"
+ ] = f"space_key={arize_config.space_key},api_key={arize_config.api_key}"
for callback in _in_memory_loggers:
if (
isinstance(callback, ArizeLogger)
@@ -2828,9 +2825,9 @@ def _init_custom_logger_compatible_class( # noqa: PLR0915
# auth can be disabled on local deployments of arize phoenix
if arize_phoenix_config.otlp_auth_headers is not None:
- os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = (
- arize_phoenix_config.otlp_auth_headers
- )
+ os.environ[
+ "OTEL_EXPORTER_OTLP_TRACES_HEADERS"
+ ] = arize_phoenix_config.otlp_auth_headers
for callback in _in_memory_loggers:
if (
@@ -2921,9 +2918,9 @@ def _init_custom_logger_compatible_class( # noqa: PLR0915
exporter="otlp_http",
endpoint="https://langtrace.ai/api/trace",
)
- os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = (
- f"api_key={os.getenv('LANGTRACE_API_KEY')}"
- )
+ os.environ[
+ "OTEL_EXPORTER_OTLP_TRACES_HEADERS"
+ ] = f"api_key={os.getenv('LANGTRACE_API_KEY')}"
for callback in _in_memory_loggers:
if (
isinstance(callback, OpenTelemetry)
@@ -3148,10 +3145,11 @@ def use_custom_pricing_for_model(litellm_params: Optional[dict]) -> bool:
metadata: dict = litellm_params.get("metadata", {}) or {}
model_info: dict = metadata.get("model_info", {}) or {}
- for _custom_cost_param in SPECIAL_MODEL_INFO_PARAMS:
- if litellm_params.get(_custom_cost_param, None) is not None:
+ custom_pricing_keys = CustomPricingLiteLLMParams.model_fields.keys()
+ for key in custom_pricing_keys:
+ if litellm_params.get(key, None) is not None:
return True
- elif model_info.get(_custom_cost_param, None) is not None:
+ elif model_info.get(key, None) is not None:
return True
return False
@@ -3429,10 +3427,10 @@ class StandardLoggingPayloadSetup:
for key in StandardLoggingHiddenParams.__annotations__.keys():
if key in hidden_params:
if key == "additional_headers":
- clean_hidden_params["additional_headers"] = (
- StandardLoggingPayloadSetup.get_additional_headers(
- hidden_params[key]
- )
+ clean_hidden_params[
+ "additional_headers"
+ ] = StandardLoggingPayloadSetup.get_additional_headers(
+ hidden_params[key]
)
else:
clean_hidden_params[key] = hidden_params[key] # type: ignore
@@ -3793,9 +3791,9 @@ def scrub_sensitive_keys_in_metadata(litellm_params: Optional[dict]):
):
for k, v in metadata["user_api_key_metadata"].items():
if k == "logging": # prevent logging user logging keys
- cleaned_user_api_key_metadata[k] = (
- "scrubbed_by_litellm_for_sensitive_keys"
- )
+ cleaned_user_api_key_metadata[
+ k
+ ] = "scrubbed_by_litellm_for_sensitive_keys"
else:
cleaned_user_api_key_metadata[k] = v
diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.html
deleted file mode 100644
index c3e98077c62..00000000000
--- a/litellm/proxy/_experimental/out/onboarding.html
+++ /dev/null
@@ -1 +0,0 @@
-<!DOCTYPE html><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/ui/_next/static/chunks/webpack-75a5453f51d60261.js"/><script src="/ui/_next/static/chunks/fd9d1056-205af899b895cbac.js" async=""></script><script src="/ui/_next/static/chunks/117-1c5bfc45bfc4237d.js" async=""></script><script src="/ui/_next/static/chunks/main-app-475d6efe4080647d.js" async=""></script><title>LiteLLM Dashboard</title><meta name="description" content="LiteLLM Proxy Admin UI"/><link rel="icon" href="/ui/favicon.ico" type="image/x-icon" sizes="16x16"/><meta name="next-size-adjust"/><script src="/ui/_next/static/chunks/polyfills-42372ed130431b0a.js" noModule=""></script></head><body><script src="/ui/_next/static/chunks/webpack-75a5453f51d60261.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/ui/_next/static/media/a34f9d1faa5f3315-s.p.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n2:HL[\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"style\"]\n3:HL[\"/ui/_next/static/css/ec485413ca556f63.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"4:I[12846,[],\"\"]\n6:I[19107,[],\"ClientPageRoot\"]\n7:I[12011,[\"665\",\"static/chunks/3014691f-b7b79b78e27792f3.js\",\"42\",\"static/chunks/42-014374badc35fe9b.js\",\"899\",\"static/chunks/899-54ea329f41297bf0.js\",\"250\",\"static/chunks/250-e89ed9abfb0cf3c4.js\",\"461\",\"static/chunks/app/onboarding/page-a2a9f8973d4d96b3.js\"],\"default\",1]\n8:I[4707,[],\"\"]\n9:I[36423,[],\"\"]\nb:I[61060,[],\"\"]\nc:[]\n"])</script><script>self.__next_f.push([1,"0:[\"$\",\"$L4\",null,{\"buildId\":\"fBZBAyE4lYGQGcCvHmfb5\",\"assetPrefix\":\"/ui\",\"urlParts\":[\"\",\"onboarding\"],\"initialTree\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{}]}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{},[[\"$L5\",[\"$\",\"$L6\",null,{\"props\":{\"params\":{},\"searchParams\":{}},\"Component\":\"$7\"}],null],null],null]},[null,[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"onboarding\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\"}]],null]},[[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/ec485413ca556f63.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[\"$\",\"body\",null,{\"className\":\"__className_cf7686\",\"children\":[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":\"404\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],\"notFoundStyles\":[]}]}]}]],null],null],\"couldBeIntercepted\":false,\"initialHead\":[null,\"$La\"],\"globalErrorComponent\":\"$b\",\"missingSlots\":\"$Wc\"}]\n"])</script><script>self.__next_f.push([1,"a:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"LiteLLM Dashboard\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"LiteLLM Proxy Admin UI\"}],[\"$\",\"link\",\"4\",{\"rel\":\"icon\",\"href\":\"/ui/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"meta\",\"5\",{\"name\":\"next-size-adjust\"}]]\n5:null\n"])</script></body></html>
\ No newline at end of file
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml
index 67fab9732fa..976895d1a1b 100644
--- a/litellm/proxy/_new_secret_config.yaml
+++ b/litellm/proxy/_new_secret_config.yaml
@@ -21,6 +21,14 @@ model_list:
model: openrouter/openrouter_model
api_key: os.environ/OPENROUTER_API_KEY
api_base: http://0.0.0.0:8090
+ - model_name: dall-e-3-azure
+ litellm_params:
+ model: azure/dall-e-3-test
+ api_version: "2023-12-01-preview"
+ api_base: os.environ/AZURE_SWEDEN_API_BASE
+ api_key: os.environ/AZURE_SWEDEN_API_KEY
+ model_info:
+ input_cost_per_pixel: 10
- model_name: "claude-3-7-sonnet"
litellm_params:
model: databricks/databricks-claude-3-7-sonnet
diff --git a/litellm/types/router.py b/litellm/types/router.py
index 22467fa3b0f..bd2990d5fb8 100644
--- a/litellm/types/router.py
+++ b/litellm/types/router.py
@@ -96,18 +96,16 @@ class ModelInfo(BaseModel):
id: Optional[
str
] # Allow id to be optional on input, but it will always be present as a str in the model instance
- db_model: bool = (
- False # used for proxy - to separate models which are stored in the db vs. config.
- )
+ db_model: bool = False # used for proxy - to separate models which are stored in the db vs. config.
updated_at: Optional[datetime.datetime] = None
updated_by: Optional[str] = None
created_at: Optional[datetime.datetime] = None
created_by: Optional[str] = None
- base_model: Optional[str] = (
- None # specify if the base model is azure/gpt-3.5-turbo etc for accurate cost tracking
- )
+ base_model: Optional[
+ str
+ ] = None # specify if the base model is azure/gpt-3.5-turbo etc for accurate cost tracking
tier: Optional[Literal["free", "paid"]] = None
"""
@@ -170,6 +168,8 @@ class CustomPricingLiteLLMParams(BaseModel):
output_cost_per_token: Optional[float] = None
input_cost_per_second: Optional[float] = None
output_cost_per_second: Optional[float] = None
+ input_cost_per_pixel: Optional[float] = None
+ output_cost_per_pixel: Optional[float] = None
class GenericLiteLLMParams(CredentialLiteLLMParams, CustomPricingLiteLLMParams):
@@ -180,12 +180,12 @@ class GenericLiteLLMParams(CredentialLiteLLMParams, CustomPricingLiteLLMParams):
custom_llm_provider: Optional[str] = None
tpm: Optional[int] = None
rpm: Optional[int] = None
- timeout: Optional[Union[float, str, httpx.Timeout]] = (
- None # if str, pass in as os.environ/
- )
- stream_timeout: Optional[Union[float, str]] = (
- None # timeout when making stream=True calls, if str, pass in as os.environ/
- )
+ timeout: Optional[
+ Union[float, str, httpx.Timeout]
+ ] = None # if str, pass in as os.environ/
+ stream_timeout: Optional[
+ Union[float, str]
+ ] = None # timeout when making stream=True calls, if str, pass in as os.environ/
max_retries: Optional[int] = None
organization: Optional[str] = None # for openai orgs
configurable_clientside_auth_params: CONFIGURABLE_CLIENTSIDE_AUTH_PARAMS = None
@@ -255,9 +255,9 @@ class GenericLiteLLMParams(CredentialLiteLLMParams, CustomPricingLiteLLMParams):
if max_retries is not None and isinstance(max_retries, str):
max_retries = int(max_retries) # cast to int
# We need to keep max_retries in args since it's a parameter of GenericLiteLLMParams
- args["max_retries"] = (
- max_retries # Put max_retries back in args after popping it
- )
+ args[
+ "max_retries"
+ ] = max_retries # Put max_retries back in args after popping it
super().__init__(**args, **params)
def __contains__(self, key):
diff --git a/tests/litellm/litellm_core_utils/test_litellm_logging.py b/tests/litellm/litellm_core_utils/test_litellm_logging.py
index eedc15dd362..6d4b9c4a421 100644
--- a/tests/litellm/litellm_core_utils/test_litellm_logging.py
+++ b/tests/litellm/litellm_core_utils/test_litellm_logging.py
@@ -32,3 +32,13 @@ def test_get_masked_api_base(logging_obj):
masked_api_base = logging_obj._get_masked_api_base(api_base)
assert masked_api_base == "https://api.openai.com/v1"
assert type(masked_api_base) == str
+
+
+def test_use_custom_pricing_for_model():
+ from litellm.litellm_core_utils.litellm_logging import use_custom_pricing_for_model
+
+ litellm_params = {
+ "custom_llm_provider": "azure",
+ "input_cost_per_pixel": 10,
+ }
+ assert use_custom_pricing_for_model(litellm_params) == True
diff --git a/tests/litellm/test_cost_calculator.py b/tests/litellm/test_cost_calculator.py
index 870906845a8..600075cc7be 100644
--- a/tests/litellm/test_cost_calculator.py
+++ b/tests/litellm/test_cost_calculator.py
@@ -238,3 +238,31 @@ def test_azure_realtime_cost_calculator():
)
assert cost > 0
+
+
+def test_default_image_cost_calculator(monkeypatch):
+ from litellm.cost_calculator import default_image_cost_calculator
+
+ temp_object = {
+ "litellm_provider": "azure",
+ "input_cost_per_pixel": 10,
+ }
+
+ monkeypatch.setattr(
+ litellm,
+ "model_cost",
+ {
+ "azure/bf9001cd7209f5734ecb4ab937a5a0e2ba5f119708bd68f184db362930f9dc7b": temp_object
+ },
+ )
+
+ args = {
+ "model": "azure/bf9001cd7209f5734ecb4ab937a5a0e2ba5f119708bd68f184db362930f9dc7b",
+ "custom_llm_provider": "azure",
+ "quality": "standard",
+ "n": 1,
+ "size": "1024-x-1024",
+ "optional_params": {},
+ }
+ cost = default_image_cost_calculator(**args)
+ assert cost == 10485760