Ë
    uPêjò  ã                   ó  — d Z ddlmZmZmZ ddlmZmZ ddlm	Z	m
Z
mZ erddlmZmZ ddlZddedd	d
edz  deeef   fd„Z G d„ de«      Z G d„ de«      Z G d„ de«      Zdededz  fd„Z	 	 dded   ded	   defd„Zy)zU
Helper util for handling anthropic-specific cost calculation
- e.g.: prompt caching
é    )ÚTYPE_CHECKINGÚFinalÚOptional)Ú	BaseModelÚValidationError)Úgeneric_cost_per_tokenÚ$get_provider_specific_geo_multiplierÚ"get_web_search_requests_from_usage)Ú	ModelInfoÚUsageNÚmodelÚusager   Úservice_tierÚreturnc                 óJ  — t        | |d|¬«      \  }}	 t        j                  | d¬«      }|j                  d«      xs i }t	        ||¬«      }t        |dd«      dk(  r|j                  dd	«      nd	}|d	k7  r
||z  }||z  }|d	k7  r
||z  }||z  }||fS # t        $ r Y ||fS w xY w)
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
        - service_tier: the service tier the request was served at (e.g. "priority"),
          read from the Anthropic response usage and used to select tier-specific pricing

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    Ú	anthropic)r   r   Úcustom_llm_providerr   )r   r   Úprovider_specific_entry)Ú
model_infor   ÚspeedNÚfastg      ð?)r   ÚlitellmÚget_model_infoÚgetr	   ÚgetattrÚ	Exception)	r   r   r   Úprompt_costÚcompletion_costr   r   Úgeo_multiplierÚspeed_multipliers	            úl/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/anthropic/cost_calculation.pyÚcost_per_tokenr"      sî   € ô $:ØØØ'Ø!ô	$Ñ €K�ðÜ#×2Ñ2¸ÐT_Ô`ˆ
Ø/9¯~©~Ð>WÓ/XÒ/^Ð\^Ðä DÐPZÐbgÔ hˆä8?ÀÀwÐPTÓ8UÐY_Ò8_Ð#×'Ñ'¨°Ô4Ðehð 	ð ˜sÒ"ØÐ+Ñ+ˆKØÐ/Ñ/ˆOà˜SÒ Ø˜>Ñ)ˆKØ˜~Ñ-ˆOð ˜Ð'Ð'øô ò Øà˜Ð'Ð'ðús   ”A;B Â	B"Â!B"c                   ó"   — e Zd ZU dZedz  ed<   y)Ú_AnthropicServerToolUseProbeNÚweb_search_requests)Ú__name__Ú
__module__Ú__qualname__r%   ÚintÚ__annotations__© ó    r!   r$   r$   @   s   … Ø&*Ð˜˜t™Ô*r,   r$   c                   ó"   — e Zd ZU dZedz  ed<   y)Ú_AnthropicUsageProbeNÚserver_tool_use)r&   r'   r(   r/   r$   r*   r+   r,   r!   r.   r.   D   s   … Ø;?€OÐ1°DÑ8Ô?r,   r.   c                   ó"   — e Zd ZU dZedz  ed<   y)Ú_AnthropicResponseProbeNr   )r&   r'   r(   r   r.   r*   r+   r,   r!   r1   r1   H   s   … Ø)-€EÐ $Ñ&Ô-r,   r1   Úresponse_objectc                 óô   — t        | t        «      sy	 t        j                  | «      }|j
                  �|j
                  j                  €y|j
                  j                  j                  S # t        $ r Y yw xY w)zRead usage.server_tool_use.web_search_requests from a raw Anthropic
    /v1/messages response dict, returning None when absent.N)Ú
isinstanceÚdictr1   Úmodel_validater   r   r/   r%   )r2   Úprobes     r!   Ú/get_anthropic_web_search_requests_from_responser8   L   sn   € ô
 �o¤tÔ,ØðÜ.×=Ñ=¸oÓNˆð ‡{�{Ð˜eŸk™k×9Ñ9ÐAØØ�;‰;×&Ñ&×:Ñ:Ð:øô	 ò Ùðús   “A+ Á+	A7Á6A7r   r   c                 ó¬   — ddl m} | €y|€yt        |«      }|€y| j                  d«      xs  |«       }|j                  dd«      }|�|dk(  ry||z  }|S )z@
    Get the cost of using a web search tool for Anthropic.
    r   )ÚSearchContextCostPerQueryg        Úsearch_context_cost_per_queryÚsearch_context_size_medium)Úlitellm.types.utilsr:   r
   r   )r   r   r:   r%   Úsearch_context_pricingÚcost_per_web_search_requestÚ
total_costs          r!   Ú!get_cost_for_anthropic_web_searchrA   \   s‡   € õ >ð ÐØà€}ØÜ!CÀEÓ!JÐØÐ"Øð 	�‰Ð6Ó7ÒVÑ;TÓ;Vð ð *@×)CÑ)CÐD`ÐbeÓ)fÐØ"Ð*Ð.IÈSÒ.PØð 4Ð6IÑI€JØÐr,   )N)NN)Ú__doc__Útypingr   r   r   Úpydanticr   r   Ú.litellm.litellm_core_utils.llm_cost_calc.utilsr   r	   r
   r=   r   r   r   ÚstrÚtupleÚfloatr"   r$   r.   r1   Úobjectr)   r8   rA   r+   r,   r!   ú<module>rJ      sÍ   ðñ÷
 2Ñ 1ç /÷ñ ñ ß4Û ñ((˜#ð (( gð ((¸SÀ4¹Zð ((ÐSXÐY^Ð`eÐYeÑSfó ((ôV+ 9ô +ô@˜9ô @ô.˜iô .ð;Øð;àˆ4�Zó;ð" )-Ø#ñØ˜Ñ%ðà�GÑðð ôr,   