fix(batches): price against the deployment model, not the router alias

self.model can carry the router's model_group alias, which no cost map resolves,
so a bedrock batch still priced at $0 after the model name started being passed.
The deployment's own litellm_params model is used when present.

Verified against the local (image-bound) cost map that dev and prod both force:
alias 'claude-opus-4-5' prices $0.000000 while
'bedrock/global.anthropic.claude-opus-4-5-20251101-v1:0' prices $0.017000
This commit is contained in:
Marty Sullivan 2026-08-16 17:00:12 -04:00 committed by mateo-berri
parent 727905dfc3
commit 0797e266cd

View file

@ -580,6 +580,17 @@ class Logging(LiteLLMLoggingBaseClass):
return model_id
return None
def get_deployment_model_for_cost(self) -> str | None:
"""The provider-qualified model to price against.
self.model can be the router's model_group alias, which no cost map
resolves, so the deployment's own litellm_params model wins when present.
"""
deployment_model: Final = self.litellm_params.get("model") if hasattr(self, "litellm_params") else None
if isinstance(deployment_model, str) and deployment_model:
return deployment_model
return self.model
def get_router_deployment_model_info(self) -> ModelInfo | None:
"""Pricing the router registered under this deployment's model_info.id.
@ -2627,7 +2638,7 @@ class Logging(LiteLLMLoggingBaseClass):
) = await _handle_completed_batch(
batch=result,
custom_llm_provider=self.custom_llm_provider,
model_name=self.model,
model_name=self.get_deployment_model_for_cost(),
litellm_params=self.litellm_params,
model_info=self.get_router_deployment_model_info(),
)