
    ^h                         S r SSKJrJrJr  SSKJr  SSKJrJ	r	  SSK
Jr  S\S\S   4S	 jrS
\S\	S\\\4   4S jr SS
\S\\   S\S\\\4   4S jjrg)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                 V    U [         R                  :X  d  U [         R                  :X  a  gg)Nr   r   )r   atranscriptiontranscription)r
   s    ^/home/james-whalen/.local/lib/python3.13/site-packages/litellm/llms/openai/cost_calculation.pycost_routerr      s#    I,,,	Y=T=T0T     modelusagec                 j   [        U SS9nUR                  nSnUR                  (       a5  UR                  R                  (       a  UR                  R                  nX4-
  nX2S   -  nUR	                  S5      b'  U(       a   XTUR	                  SS5      =(       d    S-  -  nUR                  b  UR                  R
                  OSnUR	                  S5      nUb  Ub  Xg-  nXX-  nUS   US	   -  n	UR	                  S
5      n
UR                  b  UR                  R
                  OSnU
b  Ub  X-  nX-  n	XY4$ )a3  
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      sm     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
! 	!"Z0G%HH  5?NN%5 
 **6 	''44 
 $/4H4T)H
%''r   r   durationc                 F   [        X=(       d    SS9nSnSnSU;   a?  US   b9  [        R                  " SU  SUR                  S5       SU 35        US   U-  nXE4$ SU;   a>  US   b8  [        R                  " SU  S	UR                  S5       SU 35        US   U-  nSnXE4$ )
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   