mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge 5c2c6d312c into 40be7fa1a8
This commit is contained in:
commit
2230bdcb19
3 changed files with 24 additions and 3 deletions
|
|
@ -2051,6 +2051,7 @@ def completion_cost(
|
|||
call_type=call_type,
|
||||
model_info=_deployment_model_info(litellm_logging_obj, custom_pricing, router_model_id),
|
||||
vertex_location=vertex_location,
|
||||
data_residency=data_residency,
|
||||
)
|
||||
elif call_type in _VIDEO_CALL_TYPES:
|
||||
### VIDEO GENERATION COST CALCULATION ###
|
||||
|
|
|
|||
|
|
@ -2287,6 +2287,7 @@ class CostCalculatorUtils:
|
|||
call_type: str | None = None,
|
||||
model_info: ModelInfo | None = None,
|
||||
vertex_location: str | None = None,
|
||||
data_residency: str | None = None,
|
||||
) -> float:
|
||||
"""
|
||||
Route the image generation cost calculator based on the custom_llm_provider
|
||||
|
|
@ -2398,6 +2399,8 @@ class CostCalculatorUtils:
|
|||
image_response=completion_response,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
model_info=pricing,
|
||||
data_residency=data_residency,
|
||||
optional_params=optional_params,
|
||||
)
|
||||
# Fall through to default for DALL-E models
|
||||
return default_image_cost_calculator(
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ def cost_calculator(
|
|||
image_response: ImageResponse,
|
||||
custom_llm_provider: str | None = None,
|
||||
model_info: ModelInfo | None = None,
|
||||
data_residency: str | None = None,
|
||||
optional_params: dict | None = None,
|
||||
) -> float:
|
||||
"""Calculate cost for OpenAI gpt-image models (token-based pricing)."""
|
||||
provider: Final = custom_llm_provider or "openai"
|
||||
|
|
@ -38,7 +40,12 @@ def cost_calculator(
|
|||
# A chat Usage with an explicit output breakdown: cost via generic_cost_per_token.
|
||||
if isinstance(usage, Usage) and usage.completion_tokens_details is not None:
|
||||
prompt_cost, completion_cost = generic_cost_per_token(
|
||||
model=model, usage=usage, custom_llm_provider=provider, model_info=price_table
|
||||
model=model,
|
||||
usage=usage,
|
||||
custom_llm_provider=provider,
|
||||
model_info=price_table,
|
||||
data_residency=data_residency,
|
||||
optional_params=optional_params,
|
||||
)
|
||||
return prompt_cost + completion_cost
|
||||
|
||||
|
|
@ -48,7 +55,12 @@ def cost_calculator(
|
|||
# does not itemize output and splitting text/image when it does.
|
||||
if getattr(usage, "input_tokens", None) is not None:
|
||||
token_based_cost: Final = calculate_image_response_cost_from_usage(
|
||||
model=model, image_response=image_response, custom_llm_provider=provider, model_info=price_table
|
||||
model=model,
|
||||
image_response=image_response,
|
||||
custom_llm_provider=provider,
|
||||
model_info=price_table,
|
||||
data_residency=data_residency,
|
||||
optional_params=optional_params,
|
||||
)
|
||||
if token_based_cost is not None:
|
||||
return token_based_cost
|
||||
|
|
@ -57,7 +69,12 @@ def cost_calculator(
|
|||
# cost via generic_cost_per_token (text rate) instead of returning 0.0.
|
||||
if isinstance(usage, Usage):
|
||||
prompt_cost, completion_cost = generic_cost_per_token(
|
||||
model=model, usage=usage, custom_llm_provider=provider, model_info=price_table
|
||||
model=model,
|
||||
usage=usage,
|
||||
custom_llm_provider=provider,
|
||||
model_info=price_table,
|
||||
data_residency=data_residency,
|
||||
optional_params=optional_params,
|
||||
)
|
||||
return prompt_cost + completion_cost
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue