Ë
    uPêj\!  ã                   óR  — d Z ddlm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mZ ddlmZ ded	ed
   fd„Z	 	 ddedededz  dedz  d	eeef   f
d„Zddededz  ded	eeef   fd„Zded	edz  fd„Zdeeef   dedz  d	edz  fd„Z	 	 	 ddedededz  dedz  dedz  d	efd„Zy)zR
Helper util for handling openai-specific cost calculation
- e.g.: prompt caching
é    )ÚMapping)ÚAnyÚFinalÚLiteral)Úverbose_logger©Úgeneric_cost_per_token)Ú	CallTypesÚ	ModelInfoÚ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    úi/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/openai/cost_calculation.pyÚcost_routerr      s#   € Ø”I×,Ñ,Ò,°	¼Y×=TÑ=TÒ0TØ àó    NÚmodelÚusageÚservice_tierÚdata_residencyc                 ó"   — t        | |d||¬«      S )a  
    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
        - data_residency: optional OpenAI data-residency region (e.g. "eu", "us"),
          inferred from api_base. Applies the model's regional-processing
          uplift multiplier when set.

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    Úopenai)r   r   Úcustom_llm_providerr   r   r   )r   r   r   r   s       r   r   r      s    € ô( "ØØØ$Ø!Ø%ôð r   r   Údurationc                 ó  — t        | |xs d¬«      }d}d}|j                  d«      }|�&|dkD  r!t        j                  d| ||«       ||z  }||fS d|v r6|d   �1t        j                  d| |j                  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_secondr   ú7For model=%s - output_cost_per_second: %s; duration: %sÚinput_cost_per_secondz6For model=%s - input_cost_per_second: %s; duration: %s)r   Úgetr   Údebug)r   r   r   Ú
model_infoÚprompt_costÚcompletion_costr#   s          r   r   r   ^   sÍ   € ô '¨UÐH[ÒHgÐ_gÔh€JØ€KØ€Oà$.§N¡NÐ3KÓ$LÐØÐ)Ð.DÀqÒ.HÜ×ÑØEØØ"Øô		
ð 1°8Ñ;ˆð ˜Ð'Ð'ð 
! JÑ	.°:Ð>UÑ3VÐ3bÜ×ÑØDØØ�N‰NÐ2Ó3Øô		
ð !Ð!8Ñ9¸HÑDˆØˆà˜Ð'Ð'r   Ú
resolutionc                 óš   — | j                  «       j                  «       }|sydj                  d„ |D «       «      }|rt        |«      dkD  ry|S )zSMap usage resolution to a safe suffix for ``output_cost_per_second_<suffix>`` keys.NÚ c              3   óL   K  — | ]  }|j                  «       s|d k(  sŒ|–— Œ y­w)Ú_N)Úisalnum)Ú.0Úcs     r   ú	<genexpr>z9_video_resolution_to_cost_field_suffix.<locals>.<genexpr>�   s   è ø€ ÒB ¨!¯)©)¬+¸¸c»œ!ÑBùs   ‚$�$é   )ÚstripÚlowerÚjoinÚlen)r+   ÚrÚsafes      r   Ú&_video_resolution_to_cost_field_suffixr;   ˆ   sH   € à×ÑÓ!×'Ñ'Ó)€AÙØØ—'‘'ÑB QÔBÓB€DÙ”3�t“9˜r’>ØØ€Kr   r(   Úvideo_resolutionc                 óè   — |xs dj                  «       j                  «       }|r0t        |«      }|�#d|› �}| j                  |«      }|�t	        |«      S | j                  d«      }|�t	        |«      S y)a  
    Per-second video output rate from model_info.

    If ``video_resolution`` is set (e.g. ``1080p``, ``720p``, ``4k``), looks up
    ``output_cost_per_second_<resolution>`` first (e.g. ``output_cost_per_second_1080p``),
    then falls back to ``output_cost_per_second``.
    r-   NÚoutput_cost_per_second_r#   )r5   r6   r;   r&   Úfloat)r(   r<   r9   ÚsuffixÚtier_keyÚ	tier_rateÚouts          r   Ú_video_output_cost_per_secondrD   “   s   € ð !Ò& B×-Ñ-Ó/×5Ñ5Ó7€AÙÜ>¸qÓAˆØÐØ 7¸°xÐ@ˆHØ)Ÿ~™~¨hÓ7ˆIØÐ$Ü˜YÓ'Ð'Ø—‘Ð 8Ó9€CØ
€Ü�S‹zÐØr   Úduration_secondsc                 ó  — |€t        | |xs d¬«      }|j                  d«      }|�t        j                  d| ||«       ||z  S t	        ||«      }|�t        j                  d| ||«       ||z  S t        j
                  d| «       y)a”  
    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
        - model_info: Optional[dict], deployment-level model info containing
            custom video pricing. When provided, skips the global
            get_model_info() lookup so that deployment-specific pricing is used.
        - video_resolution: Optional resolution label from usage (e.g. ``720p``, ``1080p``).

    Returns:
        float - total_cost_in_usd
    r   r!   Ú output_cost_per_video_per_secondzAFor model=%s - output_cost_per_video_per_second: %s; duration: %sr$   zhNo cost information found for video model %s. Please add pricing to model_prices_and_context_window.jsonr"   )r   r&   r   r'   rD   Úwarning)r   rE   r   r(   r<   Úvideo_cost_per_secondr#   s          r   Úvideo_generation_costrJ   ¬   s³   € ð. ÐÜ#¨%ÐEXÒEdÐ\dÔeˆ
ð $.§>¡>Ð2TÓ#UÐØÐ(Ü×ÑØOØØ!Øô		
ð %Ð'7Ñ7Ð7ä$AÀ*ÐN^Ó$_ÐØÐ)Ü×ÑØEÀuÐNdÐfvô	
ð &Ð(8Ñ8Ð8ô ×ÑØrØôð r   )NN)r"   )NNN)Ú__doc__Úcollections.abcr   Útypingr   r   r   Úlitellm._loggingr   Ú.litellm.litellm_core_utils.llm_cost_calc.utilsr	   Úlitellm.types.utilsr
   r   r   Úlitellm.utilsr   r   ÚstrÚtupler?   r   r   r;   rD   rJ   © r   r   ú<module>rU      sY  ðñõ
 $ß &Ñ &å +Ý Qß ;Ñ ;Ý (ð ˜9ð  ¨Ð1TÑ)Uó  ð  $Ø!%ñ	Øðàðð ˜‘*ðð ˜$‘Jð	ð
 ˆ5�%ˆ<ÑóñP'(˜3ð '(°S¸4±Zð '(È5ð '(Ð[`ÐafÐhmÐamÑ[nó '(ðT°sð ¸sÀT¹zó ðØ˜˜S˜Ñ!ðà˜D‘jðð ˆT�\óð8 '+Ø#'Ø#'ñ1Øð1àð1ð ˜t™ð1ð ˜DÑ ð	1ð
 ˜D‘jð1ð ô1r   