
    i6                     r    d Z ddlmZmZ ddlmZ ddlmZ erddlmZ de	dedee
e
f   fd	Zdd
ddde
fdZy)z
Helper util for handling XAI-specific cost calculation
- Uses the generic cost calculator which already handles tiered pricing correctly
- Handles XAI-specific reasoning token billing (billed as part of completion tokens)
    )TYPE_CHECKINGTuple)Usage)generic_cost_per_token)	ModelInfomodelusagereturnc                 B   t        t        |dd      xs d      }d}t        |d      r0|j                  r$t        t        |j                  dd      xs d      }||z   }t	        |j
                  ||j                  |j                  d      }t        | |d      \  }}||fS )	a  
    Calculates the cost per token for a given XAI model, prompt tokens, and completion tokens.
    Uses the generic cost calculator for all pricing logic, with XAI-specific reasoning token handling.

    Input:
        - model: str, the model name without provider prefix
        - usage: LiteLLM Usage block, containing XAI-specific usage information

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    completion_tokensr   completion_tokens_detailsreasoning_tokensN)prompt_tokensr   total_tokensprompt_tokens_detailsr   xai)r   r	   custom_llm_provider)	intgetattrhasattrr   r   r   r   r   r   )r   r	   r   r   total_completion_tokensmodified_usageprompt_costcompletion_costs           q/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/xai/cost_calculator.pycost_per_tokenr      s     GE+>BGaHu12u7V7VE335GKPq
 02BB))1''#99"&N $:>u$ K ''    r   
model_infor   c                 :   d}d}t        | d      rX| j                  Lt        | j                  d      r6| j                  j                   t        | j                  j                        }n-t        | d      r!| j                  t        | j                        }||z  }|S )aA  
    Calculate the cost of web search requests for X.AI models.

    X.AI Live Search costs $25 per 1,000 sources used.
    Each source costs $0.025.

    The number of sources is stored in prompt_tokens_details.web_search_requests
    by the transformation layer to be compatible with the existing detection system.
    g?r   r   web_search_requestsnum_sources_used)r   r   r    r   r!   )r	   r   cost_per_sourcer!   
total_costs        r   cost_per_web_search_requestr$   6   s     $O 	./''3E//1FG'';;Gu::NNO 
*	+0F0F0Ru556 #33Jr   N)__doc__typingr   r   litellm.types.utilsr   .litellm.litellm_core_utils.llm_cost_calc.utilsr   r   strfloatr   r$    r   r   <module>r,      sY    ( % Q-#(# #(e #(eUl0C #(Lw K E r   