diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 82acd10c186..a256bc85425 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -296,12 +296,29 @@ def _get_additional_costs( return None -def _transcription_usage_has_token_details( +def _transcription_uses_token_pricing( + model: str, + custom_llm_provider: str | None, usage_block: Usage | None, ) -> bool: if usage_block is None: return False + model_info: Final = _cached_get_model_info_helper(model=model, custom_llm_provider=custom_llm_provider) + has_token_pricing: Final = any( + model_info.get(field) + for field in ( + "input_cost_per_token", + "output_cost_per_token", + "input_cost_per_audio_token", + "output_cost_per_audio_token", + ) + ) + if not has_token_pricing and ( + model_info.get("input_cost_per_second") is not None or model_info.get("output_cost_per_second") is not None + ): + return False + prompt_tokens_val: Final = getattr(usage_block, "prompt_tokens", 0) or 0 completion_tokens_val: Final = getattr(usage_block, "completion_tokens", 0) or 0 prompt_details: Final[PromptTokensDetailsWrapper | None] = getattr(usage_block, "prompt_tokens_details", None) @@ -628,25 +645,7 @@ def cost_per_token( data_residency=data_residency, ) elif call_type == "atranscription" or call_type == "transcription": - transcription_model_info: Final = _cached_get_model_info_helper( - model=model_without_prefix, custom_llm_provider=custom_llm_provider - ) - has_token_pricing: Final = any( - transcription_model_info.get(field) - for field in ( - "input_cost_per_token", - "output_cost_per_token", - "input_cost_per_audio_token", - "output_cost_per_audio_token", - ) - ) - if _transcription_usage_has_token_details(usage_block) and ( - has_token_pricing - or ( - transcription_model_info.get("input_cost_per_second") is None - and transcription_model_info.get("output_cost_per_second") is None - ) - ): + if _transcription_uses_token_pricing(model_without_prefix, custom_llm_provider, usage_block): return generic_cost_per_token( model=model_without_prefix, usage=usage_block, diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 3eba410b4aa..f1ac550f182 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -3285,14 +3285,7 @@ class Logging(LiteLLMLoggingBaseClass): ## BUILD COMPLETE STREAMED RESPONSE if "async_complete_streaming_response" in self.model_call_details: return # break out of this. - complete_streaming_response: Final[ - ModelResponse - | TextCompletionResponse - | ResponsesAPIResponse - | InteractionsAPIResponse - | TranscriptionResponse - | None - ] = self._get_assembled_streaming_response( + complete_streaming_response: Final = self._get_assembled_streaming_response( result=result, start_time=start_time, end_time=end_time,