Ë
    tPêjx  ã                   óx   — d Z ddlZddlmZ ddlZddlmZ dedz  fd„Zdede	fd„Z
d	edz  d
edz  dedz  fd„Zy)aö  
Throttle a key after it exceeds its own ``max_budget`` instead of blocking it.

When a key opts in via ``throttle_on_budget_exceeded`` and a global
``budget_exceeded_throttle_percentage`` is configured, an over-budget key keeps
serving requests but at a reduced TPM/RPM (the configured percentage of its
configured limits). The decision (over budget + opted in) is made once during
auth; the scaling is recomputed from the key's original limits on every request
so it never compounds across requests.
é    N)ÚFinal)ÚUserAPIKeyAuthÚreturnc                  ó¢   — t         j                  } t        | t        t        f«      rt        | t
        «      ryd| cxk  rdk  sy yt	        | «      S )z«
    The global throttle percentage, or None when throttling is disabled /
    misconfigured (in which case an over-budget key is hard-blocked, the safe
    default).
    Nr   é   )ÚlitellmÚ#budget_exceeded_throttle_percentageÚ
isinstanceÚintÚfloatÚbool)Úpcts    úg/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/auth/budget_throttle.pyÚbudget_throttle_percentager      sI   € ô ×<Ñ<€CÜ�cœC¤˜<Ô(¬J°s¼DÔ,AØØˆsŒ<�aŠ<Øð ØÜ�‹:Ðó    Úvalid_tokenc                 ó�   — | j                   xs i j                  d«      dury| j                  €| j                  €yt	        «       duS )an  
    True when a key that exceeded its own ``max_budget`` should be throttled
    rather than blocked: it opted in, a valid global percentage is set, and the
    key has a TPM or RPM limit to scale down. A key with neither limit has
    nothing to throttle, so it stays hard-blocked (the safe default) rather than
    serving unlimited requests past its budget.
    Úthrottle_on_budget_exceededTFN)ÚmetadataÚgetÚ	tpm_limitÚ	rpm_limitr   )r   s    r   Úshould_throttle_budget_exceededr   !   sN   € ð 	×ÑÒ" ×'Ñ'Ð(EÓFÈdÑRØØ×ÑÐ$¨×)>Ñ)>Ð)FØÜ%Ó'¨tÐ3Ð3r   Úlimitr   c                 óR   — | �|€| S t        dt        j                  | |z  «      «      S )zÚ
    Scale a TPM/RPM limit to ``pct`` of its value, keeping a trickle of at least
    1 so a throttled key is slowed rather than fully locked out. An unset limit
    or unset percentage leaves the limit unchanged.
    r   )ÚmaxÚmathÚfloor)r   r   s     r   Úthrottled_limitr   0   s,   € ð €}˜˜ØˆÜˆq”$—*‘*˜U S™[Ó)Ó*Ð*r   )Ú__doc__r   Útypingr   r   Úlitellm.proxy._typesr   r   r   r   r   r   r   © r   r   ú<module>r$      sa   ðñ	ó Ý ã Ý /ð E¨D¡Ló ð4°ð 4ÀDó 4ð+˜3 ™:ð +¨E°D©Lð +¸SÀ4¹Zô +r   