
    he                         d Z ddlmZmZmZ ddlmZ erddlmZm	Z	 de
dddeeef   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OptionalTuplegeneric_cost_per_token)	ModelInfoUsagemodelusager	   returnc                     t        | |d      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
    	anthropic)r
   r   custom_llm_providerr   )r
   r   s     c/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/llms/anthropic/cost_calculation.pycost_per_tokenr      s     "5k     N
model_infor   c                     ddl m} | y|"|j                  |j                  j                  y| j	                  di       xs i }|j	                  dd      }||dk(  ry||j                  j                  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   server_tool_useweb_search_requestsget)r   r   r   search_context_pricingcost_per_web_search_request
total_costs         r   !get_cost_for_anthropic_web_searchr      s     >  	  (  44< 	6;Ar  #9"<"<$c# #*.IS.P -u/D/D/X/XXJr   )NN)__doc__typingr   r   r   .litellm.litellm_core_utils.llm_cost_calc.utilsr   r   r   r	   strfloatr   r    r   r   <module>r&      so   
 2 1 Q4# g %u2E " )-# % G   r   