Ë
    uPêj/  ã                   ó¬   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dedefd	„Zded
edefd„Z	 	 	 ddedededz  dedz  dedz  deeef   fd„Zy)zx
Azure AI cost calculation helper.
Handles Azure AI Foundry Model Router flat cost and other Azure AI specific pricing.
é    )ÚFinal)Úverbose_logger)Úgeneric_cost_per_token)ÚUsage)Úget_model_infoÚmodelÚreturnc                 óD   — | j                  «       }d|v xs d|v xs |dk(  S )a<  
    Check if the model is Azure AI Foundry Model Router.

    Detects patterns like:
    - "azure-model-router"
    - "model-router"
    - "model_router/<actual-model>"
    - "model-router/<actual-model>"

    Args:
        model: The model name

    Returns:
        bool: True if this is a model router model
    zmodel-routerÚmodel_routerzazure-model-router)Úlower)r   Úmodel_lowers     új/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/azure_ai/cost_calculator.pyÚ_is_azure_model_routerr      s/   € ð  Ÿ™›€KØ˜[Ð(Òp¨N¸kÐ,IÒpÈ[Ð\pÑMpÐpó    Úprompt_tokensc                 ór   — t        | «      syt        dd¬«      }|j                  dd«      }|r
|dkD  r||z  S y)a	  
    Calculate the flat cost for Azure AI Foundry Model Router.

    Args:
        model: The model name (should be a model router model)
        prompt_tokens: Number of prompt tokens

    Returns:
        float: The flat cost in USD, or 0.0 if not applicable
    ç        r   Úazure_ai)r   Úcustom_llm_providerÚinput_cost_per_tokenr   )r   r   Úget)r   r   Ú
model_infoÚrouter_flat_cost_per_tokens       r   Ú&calculate_azure_model_router_flat_costr   "   sJ   € ô " %Ô(Øô '¨^ÐQ[Ô\€JØ(2¯©Ð7MÈqÓ(QÐá!Ð&@À1Ò&DØÐ9Ñ9Ð9àr   NÚusageÚresponse_time_msÚrequest_modelÚservice_tierc           	      ó¦  — d}d}t        | «      xs |duxr t        |«      }	 t        | |d|¬«      \  }}|r^|r|n| }	t        |	|j                  «      }
|
dkD  r=t        j                  d|
d›d	|j                  › d
|
|j                  z  d›d�«       ||
z  }||fS # t        $ r-}t        | «      s‚ t        j                  d| |«       Y d}~Œ•d}~ww xY w)aJ  
    Calculate the cost per token for Azure AI models.

    For Azure AI Foundry Model Router:
    - Adds a flat cost of $0.14 per million input tokens (from model_prices_and_context_window.json)
    - Plus the cost of the actual model used (handled by generic_cost_per_token)

    Args:
        model: str, the model name without provider prefix (from response)
        usage: LiteLLM Usage block
        response_time_ms: Optional response time in milliseconds
        request_model: Optional[str], the original request model name (to detect router usage)

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd

    Raises:
        ValueError: If the model is not found in the cost map and cost cannot be calculated
            (except for Model Router models where we return just the routing flat cost)
    r   Nr   )r   r   r   r   z`Azure AI Model Router: model '%s' not in cost map, calculating routing flat cost only. Error: %sr   z"Azure AI Model Router flat cost: $z.6fz (u    tokens Ã— $z.9fz/token))r   r   Ú	Exceptionr   Údebugr   r   )r   r   r   r   r   Úprompt_costÚcompletion_costÚis_router_requestÚeÚrouter_model_for_calcÚrouter_flat_costs              r   Úcost_per_tokenr(   ;   s  € ð6 €KØ€Oô  6°eÓ<ò  Ø˜TÐ!ÒKÔ&<¸]Ó&Kð ð
Ü'=ØØØ *Ø%ô	(
Ñ$ˆ�_ñ& á8E¡}È5ÐÜ"HÐI^Ð`e×`sÑ`sÓ"tÐà˜aÒÜ× Ñ Ø4Ð5EÀcÐ4Jð KØ×'Ñ'Ð(¨Ð5EÈ×H[ÑH[Ñ5[Ð\_Ð4`Ð`gðiôð Ð+Ñ+ˆKà˜Ð'Ð'øô7 ò 	
ô & eÔ,àÜ×ÑØnÐpuÐwx÷	
ñ 	
ûð	
ús   ¤B Â	CÂ##CÃC)r   NN)Ú__doc__Útypingr   Úlitellm._loggingr   Ú.litellm.litellm_core_utils.llm_cost_calc.utilsr   Úlitellm.types.utilsr   Úlitellm.utilsr   ÚstrÚboolr   ÚintÚfloatr   Útupler(   © r   r   ú<module>r5      s¯   ðñõ
 å +Ý QÝ %Ý (ðq #ð q¨$ó qð(°#ð Àcð Èeó ð8 &)Ø $Ø#ñH(ØðH(àðH(ð ˜d‘lðH(ð ˜‘:ð	H(ð
 ˜‘*ðH(ð ˆ5�%ˆ<ÑôH(r   