
    j                          d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZ de
ded	   fd
Z	 ddededee   deeef   fdZ	 ddedee   dedeeef   fdZ	 ddededee   defdZy)zR
Helper util for handling openai-specific cost calculation
- e.g.: prompt caching
    )LiteralOptionalTuple)verbose_loggergeneric_cost_per_token)	CallTypesUsage)get_model_info	call_typereturn)cost_per_tokencost_per_secondc                 R    | t         j                  k(  s| t         j                  k(  ryy)Nr   r   )r	   atranscriptiontranscription)r   s    }/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/litellm/llms/openai/cost_calculation.pycost_routerr      s#    I,,,	Y=T=T0T     Nmodelusageservice_tierc                      t        | |d|      S )aO  
    Calculates the cost per token for a given model, prompt tokens, and completion tokens.

    Input:
        - model: str, the model name without provider prefix
        - usage: LiteLLM Usage block, containing anthropic caching information

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    openai)r   r   custom_llm_providerr   r   )r   r   r   s      r   r   r      s     "$!	 r   r   durationc                 8   t        | |xs d      }d}d}d|v r>|d   9t        j                  d|  d|j                  d       d|        |d   |z  }||fS d|v r<|d   7t        j                  d|  d	|j                  d       d|        |d   |z  }d}||fS )
a  
    Calculates the cost per second for a given model, prompt tokens, and completion tokens.

    Input:
        - model: str, the model name without provider prefix
        - custom_llm_provider: str, the custom llm provider
        - duration: float, the duration of the response in seconds

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    r   r   r           output_cost_per_second
For model= - output_cost_per_second: ; duration: input_cost_per_secondz - input_cost_per_second: )r   r   debugget)r   r   r   
model_infoprompt_costcompletion_costs         r   r   r   V   s       )<)HJ KO 	!J./0<::>>Jb;c:ddpqypz{	
 %%=>I '' 	 :-./;9*..I`:a9bbnownxy	
 !!89HD''r   duration_secondsc                 0   t        | |xs d      }|j                  d      }|#t        j                  d|  d| d|        ||z  S |j                  d      }|#t        j                  d|  d| d|        ||z  S t        j                  d	|  d
       y)aW  
    Calculates the cost for video generation based on duration in seconds.

    Input:
        - model: str, the model name without provider prefix
        - duration_seconds: float, the duration of the generated video in seconds
        - custom_llm_provider: str, the custom llm provider

    Returns:
        float - total_cost_in_usd
    r   r    output_cost_per_video_per_secondr!   z% - output_cost_per_video_per_second: r#   r    r"   z*No cost information found for video model z<. Please add pricing to model_prices_and_context_window.jsonr   )r   r&   r   r%   warning)r   r*   r   r'   video_cost_per_secondr    s         r   video_generation_costr/      s      )<)HJ
 'NN+MN(DEZD[[ghxgyz	
 %'777 (^^,DE):;Q:RR^_o^pq	
 &(888 
4UG;wx r   )N)r   )__doc__typingr   r   r   litellm._loggingr   .litellm.litellm_core_utils.llm_cost_calc.utilsr   litellm.types.utilsr	   r
   litellm.utilsr   r   strfloatr   r   r/    r   r   <module>r9      s   
 , + + Q 0 ( 9  1T)U   =A,4SM
5%<D GJ*(*(%-c]*(>C*(
5%<*(\ OS''"''>Fsm'
'r   