
    g                         d Z ddlmZmZ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
ed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y)zR
Helper util for handling openai-specific cost calculation
- e.g.: prompt caching
    )LiteralOptionalTuple)verbose_logger)	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    Y/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/openai/cost_calculation.pycost_routerr      s#    I,,,	Y=T=T0T     modelusagec                 J   t        | d      }|j                  }d}|j                  r1|j                  j                  r|j                  j                  }||z
  }||d   z  }|j	                  d      |r|||j	                  dd      xs dz  z  }|j                  |j                  j
                  nd}|j	                  d      }||
||z  }||z  }|d   |d	   z  }	|j	                  d
      }
|j                  |j                  j
                  nd}|
|
||
z  }|	|z  }	||	f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   custom_llm_providerNinput_cost_per_tokencache_read_input_token_costr   input_cost_per_audio_tokencompletion_tokensoutput_cost_per_tokenoutput_cost_per_audio_token)r	   prompt_tokensprompt_tokens_detailscached_tokensgetaudio_tokenscompletion_tokens_details)r   r   
model_infonon_cached_text_tokensr"   prompt_cost_audio_tokens_audio_cost_per_token
audio_costcompletion_cost_output_cost_per_audio_token_output_audio_tokenss               r   r   r      s     eJJ #00#'M""u'B'B'P'P33AA!7-!G/*=S2TTK~~34@]}NN8!<A
 	
 &&2 	##00 
 .8^^$.  %:%F),AA
z! 	!"Z0G%HH  5?NN%5 
 **6 	''44 
 $/4H4T),HH
:%''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           output_cost_per_secondz
For model=z - output_cost_per_second: z; duration: input_cost_per_secondz - input_cost_per_second: )r	   r   debugr#   )r   r   r/   r&   r(   r,   s         r   r   r   O   s      )<)HJ KO 	!J./0<::>>Jb;c:ddpqypz{	
 %%=>I '' 	 :-./;9*..I`:a9bbnownxy	
 !!89HD''r   N)r1   )__doc__typingr   r   r   litellm._loggingr   litellm.types.utilsr   r   litellm.utilsr	   r   strfloatr   r    r   r   <module>r=      s   
 , + + 0 ( 9  1T)U  8(# 8(e 8(eUl0C 8(x GJ)()(%-c])(>C)(
5%<)(r   