@@ -877,6 +877,29 @@ def completion_cost( # noqa: PLR0915
877877 size = size ,
878878 optional_params = optional_params ,
879879 )
880+ elif (
881+ call_type == CallTypes .create_video .value
882+ or call_type == CallTypes .acreate_video .value
883+ ):
884+ ### VIDEO GENERATION COST CALCULATION ###
885+ if completion_response is not None and hasattr (completion_response , 'usage' ):
886+ usage_obj = completion_response .usage
887+ duration_seconds = usage_obj .get ('duration_seconds' )
888+
889+ if duration_seconds is not None :
890+ # Calculate cost based on video duration using video-specific cost calculation
891+ from litellm .llms .openai .cost_calculation import video_generation_cost
892+ return video_generation_cost (
893+ model = model ,
894+ duration_seconds = duration_seconds ,
895+ custom_llm_provider = custom_llm_provider
896+ )
897+ # Fallback to default video cost calculation if no duration available
898+ return default_video_cost_calculator (
899+ model = model ,
900+ duration_seconds = 0.0 , # Default to 0 if no duration available
901+ custom_llm_provider = custom_llm_provider
902+ )
880903 elif (
881904 call_type == CallTypes .speech .value
882905 or call_type == CallTypes .aspeech .value
@@ -1344,6 +1367,80 @@ def default_image_cost_calculator(
13441367 return cost_info ["input_cost_per_pixel" ] * height * width * n
13451368
13461369
1370+ def default_video_cost_calculator (
1371+ model : str ,
1372+ duration_seconds : float ,
1373+ custom_llm_provider : Optional [str ] = None ,
1374+ ) -> float :
1375+ """
1376+ Default video cost calculator for video generation
1377+
1378+ Args:
1379+ model (str): Model name
1380+ duration_seconds (float): Duration of the generated video in seconds
1381+ custom_llm_provider (Optional[str]): Custom LLM provider
1382+
1383+ Returns:
1384+ float: Cost in USD for the video generation
1385+
1386+ Raises:
1387+ Exception: If model pricing not found in cost map
1388+ """
1389+ # Build model names for cost lookup
1390+ base_model_name = model
1391+ model_name_without_custom_llm_provider : Optional [str ] = None
1392+ if custom_llm_provider and model .startswith (f"{ custom_llm_provider } /" ):
1393+ model_name_without_custom_llm_provider = model .replace (
1394+ f"{ custom_llm_provider } /" , ""
1395+ )
1396+ base_model_name = f"{ custom_llm_provider } /{ model_name_without_custom_llm_provider } "
1397+
1398+ verbose_logger .debug (
1399+ f"Looking up cost for video model: { base_model_name } "
1400+ )
1401+
1402+ model_without_provider = model .split ('/' )[- 1 ]
1403+
1404+ # Try model with provider first, fall back to base model name
1405+ cost_info : Optional [dict ] = None
1406+ models_to_check : List [Optional [str ]] = [
1407+ base_model_name ,
1408+ model ,
1409+ model_without_provider ,
1410+ model_name_without_custom_llm_provider ,
1411+ ]
1412+ for _model in models_to_check :
1413+ if _model is not None and _model in litellm .model_cost :
1414+ cost_info = litellm .model_cost [_model ]
1415+ break
1416+
1417+ # If still not found, try with custom_llm_provider prefix
1418+ if cost_info is None and custom_llm_provider :
1419+ prefixed_model = f"{ custom_llm_provider } /{ model } "
1420+ if prefixed_model in litellm .model_cost :
1421+ cost_info = litellm .model_cost [prefixed_model ]
1422+ if cost_info is None :
1423+ raise Exception (
1424+ f"Model not found in cost map. Tried checking { models_to_check } "
1425+ )
1426+
1427+ # Check for video-specific cost per second first
1428+ video_cost_per_second = cost_info .get ("output_cost_per_video_per_second" )
1429+ if video_cost_per_second is not None :
1430+ return video_cost_per_second * duration_seconds
1431+
1432+ # Fallback to general output cost per second
1433+ output_cost_per_second = cost_info .get ("output_cost_per_second" )
1434+ if output_cost_per_second is not None :
1435+ return output_cost_per_second * duration_seconds
1436+
1437+ # If no cost information found, return 0
1438+ verbose_logger .info (
1439+ f"No cost information found for video model { model } . Please add pricing to model_prices_and_context_window.json"
1440+ )
1441+ return 0.0
1442+
1443+
13471444def batch_cost_calculator (
13481445 usage : Usage ,
13491446 model : str ,
0 commit comments