Ë
    tPêj81  ã                   óP   — d dl Z d dlmZmZ d dlZd dlmZ ddlmZ  G d„ d«      Z	y)é    N)ÚAnyÚFinal)Úredact_stringé   )ÚUnauthorizedErrorc                   ó   — e Zd Zd dededz  defd„Zdeeef   fd„Z	 	 	 	 	 	 	 	 	 	 d!dedz  d	edz  d
edz  dedz  dedz  dedz  dedz  dedz  dedz  dedeee	f   e
j                  z  fd„Z	 	 	 	 	 	 	 	 	 	 d!dej                  e   dz  deeef   dz  dedz  dedz  dedz  dedz  d
edz  dedz  deee	f   dz  dedeee	f   e
j                  z  fd„Z	 	 	 d"dej                  e   dz  dej                  e   dz  dedeee	f   e
j                  z  fd„Z	 	 	 	 	 	 	 d#dedej                  e   dz  deeef   dz  dedz  dedz  dedz  dedz  d
edz  deee	f   e
j                  z  fd„Zd$dededeee	f   e
j                  z  fd„Zy)%ÚKeysManagementClientNÚbase_urlÚapi_keyÚtimeoutc                 óL   — |j                  d«      | _        || _        || _        y)a_  
        Initialize the KeysManagementClient.

        Args:
            base_url (str): The base URL of the LiteLLM proxy server (e.g., "http://localhost:8000")
            api_key (Optional[str]): API key for authentication. If provided, it will be sent as a Bearer token.
            timeout (int): Request timeout in seconds (default: 30)
        ú/N)ÚrstripÚ	_base_urlÚ_api_keyÚ_timeout)Úselfr
   r   r   s       ú^/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/client/keys.pyÚ__init__zKeysManagementClient.__init__   s"   € ð "Ÿ™¨Ó-ˆŒØˆŒØˆ�ó    Úreturnc                 óJ   — ddi}| j                   rd| j                   › �|d<   |S )z¬
        Get the headers for API requests, including authorization if api_key is set.

        Returns:
            Dict[str, str]: Headers to use for API requests
        zContent-Typezapplication/jsonzBearer ÚAuthorization)r   )r   Úheaderss     r   Ú_get_headersz!KeysManagementClient._get_headers   s0   € ð )Ð*<Ð=ˆØ�=Š=Ø)0°·±°Ð'@ˆG�OÑ$Øˆr   ÚpageÚsizeÚuser_idÚteam_idÚorganization_idÚkey_hashÚ	key_aliasÚreturn_full_objectÚinclude_team_keysÚreturn_requestc                 ó¨  — | j                   › d�}i }|�||d<   |�||d<   |�||d<   |�||d<   |�||d<   |�||d<   |�||d	<   |�t        |«      j                  «       |d
<   |	�t        |	«      j                  «       |d<   t        j                  d|| j                  «       |¬«      }|
r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       S # t        j                  j                  $ r*}|j                  j                  dk(  rt!        |«      ‚‚ d}~ww xY w)aæ  
        List all API keys with optional filtering and pagination.

        Args:
            page (Optional[int]): Page number for pagination
            size (Optional[int]): Number of items per page
            user_id (Optional[str]): Filter keys by user ID
            team_id (Optional[str]): Filter keys by team ID
            organization_id (Optional[str]): Filter keys by organization ID
            key_hash (Optional[str]): Filter by specific key hash
            key_alias (Optional[str]): Filter by key alias
            return_full_object (Optional[bool]): Whether to return the full key object
            include_team_keys (Optional[bool]): Whether to include team keys in the response
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True. The response contains a list
            of API keys with their configurations.

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z	/key/listNr   r   r   r   r    r!   r"   r#   r$   ÚGET)r   Úparams©r   é‘  )r   ÚstrÚlowerÚrequestsÚRequestr   ÚSessionÚsendÚpreparer   Úraise_for_statusÚjsonÚ
exceptionsÚ	HTTPErrorÚresponseÚstatus_coder   )r   r   r   r   r   r    r!   r"   r#   r$   r%   Úurlr(   ÚrequestÚsessionr6   Úes                    r   ÚlistzKeysManagementClient.list%   sx  € ðJ Ÿ™Ð' yÐ1ˆØ(*ˆð ÐØ!ˆF�6‰NØÐØ!ˆF�6‰NØÐØ 'ˆF�9ÑØÐØ 'ˆF�9ÑØÐ&Ø(7ˆFÐ$Ñ%ØÐØ!)ˆF�:ÑØÐ Ø"+ˆF�;ÑØÐ)Ü+.Ð/AÓ+B×+HÑ+HÓ+JˆFÐ'Ñ(ØÐ(Ü*-Ð.?Ó*@×*FÑ*FÓ*HˆFÐ&Ñ'ä!×)Ñ)¨%°¸d×>OÑ>OÓ>QÐZ`ÔaˆáØˆNä!×)Ñ)Ó+ˆð	Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Øûð	ús   Â?A
D
 Ä
EÄ'%EÅEÚmodelsÚaliasesÚspendÚdurationÚ	budget_idÚconfigc                 óL  — | j                   › d�}i }|�||d<   |�||d<   |�||d<   |�||d<   |�||d<   |�||d<   |�||d	<   |�||d
<   |	�|	|d<   t        j                  d|| j                  «       |¬«      }|
r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       S # t        j                  j                  $ r*}|j                  j                  dk(  rt        |«      ‚‚ d}~ww xY w)a  
        Generate an API key based on the provided data.

        Docs: https://docs.litellm.ai/docs/proxy/virtual_keys

        Args:
            models (Optional[List[str]]): List of allowed models for this key
            aliases (Optional[Dict[str, str]]): Model alias mappings
            spend (Optional[float]): Maximum spend limit for this key
            duration (Optional[str]): Duration for which the key is valid (e.g. "24h", "7d")
            key_alias (Optional[str]): Alias/name for the key for easier identification
            team_id (Optional[str]): Team ID to associate the key with
            user_id (Optional[str]): User ID to associate the key with
            budget_id (Optional[str]): Budget ID to associate the key with
            config (Optional[Dict[str, Any]]): Additional configuration parameters
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/key/generateNr=   r>   r?   r@   r"   r   r   rA   rB   ÚPOST©r   r3   r)   r*   ©r   r-   r.   r   r/   r0   r1   r   r2   r3   r4   r5   r6   r7   r   )r   r=   r>   r?   r@   r"   r   r   rA   rB   r%   r8   Údatar9   r:   r6   r;   s                    r   ÚgeneratezKeysManagementClient.generatep   sQ  € ðL Ÿ™Ð' }Ð5ˆà&(ˆØÐØ#ˆD�‰NØÐØ%ˆD�‰OØÐØ!ˆD�‰MØÐØ'ˆD�ÑØÐ Ø )ˆD�ÑØÐØ%ˆD�‰OØÐØ%ˆD�‰OØÐ Ø )ˆD�ÑØÐØ#ˆD�‰Nä!×)Ñ)¨&°#¸t×?PÑ?PÓ?RÐY]Ô^ˆáØˆNä!×)Ñ)Ó+ˆð	Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Øûð	ús   ÂA
C ÃD#Ã9%DÄD#ÚkeysÚkey_aliasesc                 óÔ  — | j                   › d�}||dœ}t        j                  d|| j                  «       |¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       S # t        j                  j                  $ r*}	|	j                  j                  dk(  rt        |	«      ‚‚ d}	~	ww xY w)a  
        Delete existing keys

        Args:
            keys (List[str]): List of API keys to delete
            key_aliases (List[str]): List of key aliases to delete
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/key/delete)rI   rJ   rD   rE   r)   r*   NrF   )
r   rI   rJ   r%   r8   rG   r9   r:   r6   r;   s
             r   ÚdeletezKeysManagementClient.delete»   sÒ   € ð, Ÿ™Ð' {Ð3ˆð Ø&ñ
ˆô
 "×)Ñ)¨&°#¸t×?PÑ?PÓ?RÐY]Ô^ˆáØˆNä!×)Ñ)Ó+ˆð	Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Øûð	ús   ÁA
B  Â C'Â=%C"Ã"C'Úkeyc	                 óê  — | j                   › d�}	d|i}
|�||
d<   |�||
d<   |�||
d<   |�||
d<   |�||
d<   |�||
d	<   |�||
d
<   t        j                  d|	| j                  «       |
¬«      }t        j                  «       }d}	 |j                  |j                  «       | j                  ¬«      }|j                  }|j                  «        |j                  «       S # t        $ r t        d|› �«      ‚w xY w)aï  
        Update an existing API key's parameters.

        Args:
            models: Optional[List[str]] = None,
            aliases: Optional[Dict[str, str]] = None,
            spend: Optional[float] = None,
            duration: Optional[str] = None,
            key_alias: Optional[str] = None,
            team_id: Optional[str] = None,
            user_id: Optional[str] = None,

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/key/updaterM   Nr"   r   r   r=   r?   r@   r>   rD   rE   r)   zError updating key: )r   r-   r.   r   r/   r0   r1   r   Útextr2   r3   Ú	Exception)r   rM   r=   r>   r?   r@   r"   r   r   r8   rG   r9   r:   Úresponse_textr6   s                  r   ÚupdatezKeysManagementClient.updateç   s$  € ð> Ÿ™Ð' {Ð3ˆà',¨c lˆàÐ Ø )ˆD�ÑØÐØ%ˆD�‰OØÐØ%ˆD�‰OØÐØ#ˆD�‰NØÐØ!ˆD�‰MØÐØ'ˆD�ÑØÐØ%ˆD�‰OÜ!×)Ñ)¨&°#¸t×?PÑ?PÓ?RÐY]Ô^ˆÜ!×)Ñ)Ó+ˆØ$(ˆð	DØ%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ$ŸM™MˆMØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜò 	DÜÐ2°=°/ÐBÓCÐCð	Dús   ÂAC ÃC2c                 óL  — | j                   › d|› �}t        j                  d|| j                  «       ¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       S # t        j                  j                  $ rj}t        t        |«      «      }|j                  j                  dk(  rt!        |«      d‚t        j                  j                  ||j                  ¬«      d‚d}~ww xY w)a?  
        Get information about API keys.

        Args:
            key (str): The key hash to get information about
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/key/info?key=r'   )r   r)   r*   N)r6   )r   r-   r.   r   r/   r0   r1   r   r2   r3   r4   r5   r   r+   r6   r7   r   )	r   rM   r%   r8   r9   r:   r6   r;   Úredacted_messages	            r   ÚinfozKeysManagementClient.info#  s÷   € ð Ÿ™Ð' ~°c°UÐ;ˆÜ!×)Ñ)¨%°¸d×>OÑ>OÓ>QÔRˆáØˆNä!×)Ñ)Ó+ˆð	aØ%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	aÜ&3´C¸³FÓ&;ÐØ�z‰z×%Ñ%¨Ò,Ü'¨Ó*°Ð4Ü×%Ñ%×/Ñ/Ð0@È1Ï:É:Ð/ÓVÐ\`Ð`ûð		aús   ÁA
B ÂD#Â9A%DÄD#)Né   )
NNNNNNNNNF)NNF)NNNNNNN)F)Ú__name__Ú
__module__Ú__qualname__r+   Úintr   Údictr   Úboolr   r-   r.   r<   ÚbuiltinsÚfloatrH   rL   rR   rU   © r   r   r	   r	      sR  „ ñ  ð  ¨s°T©zð  È3ó  ð
˜d 3¨ 8™nó 
ð  ØØ"Ø"Ø&*Ø#Ø $Ø*.Ø)-Ø$ñIà�D‰jðIð �D‰jðIð �t‘ð	Ið
 �t‘ðIð ˜t™ðIð ˜‘*ðIð ˜‘:ðIð ! 4™KðIð   $™;ðIð ðIð 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*óIðZ -1Ø)-Ø"Ø#Ø $Ø"Ø"Ø $Ø(,Ø$ñIà—‘˜cÑ" TÑ)ðIð �c˜3�h‘ $Ñ&ðIð �t‰|ð	Ið
 ˜‘*ðIð ˜‘:ðIð �t‘ðIð �t‘ðIð ˜‘:ðIð �S˜#�X‘ Ñ%ðIð ðIð 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*óIðZ +/Ø15Ø$ñ	*à�m‰m˜CÑ  4Ñ'ð*ð —]‘] 3Ñ'¨$Ñ.ð*ð ð	*ð
 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*ó*ð^ -1Ø)-Ø"Ø#Ø $Ø"Ø"ñ:Dàð:Dð —‘˜cÑ" TÑ)ð:Dð �c˜3�h‘ $Ñ&ð	:Dð
 �t‰|ð:Dð ˜‘*ð:Dð ˜‘:ð:Dð �t‘ð:Dð �t‘ð:Dð 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*ó:Dñxa˜ð a¨Tð a¸dÀ3ÈÀ8¹nÈx×O_ÑO_Ñ>_ô ar   r	   )
r]   Útypingr   r   r-   Ú+litellm.litellm_core_utils.secret_redactionr   r4   r   r	   r_   r   r   ú<module>rb      s"   ðÛ ß ã å Eå )÷vaò var   