
    ^hpS                     0   S SK r S SKrS SKrS SKrS SKJrJr  S SKJrJrJ	r	  S SK
r
S SK
JrJrJrJrJrJr  S SKrS SKJr  S SKJrJrJrJrJrJr  S SKJr  S SKJr  \" 5       r\RA                  S	S
/\" \5      /S9S\4S j5       r!\RA                  SS
/\" \5      /SS9\" \5      \
RD                  " SS94S\S\	\S   \#4   4S jj5       r$\RA                  SS
/\" \5      /S9\" \5      \
RD                  " SSS94S\S\\#   4S jj5       r%S\RL                  " 5       S.q'S r(\RA                  SS
/\" \5      /S9\RA                  SS
/\" \5      /S9S  5       5       r)S! r*\RA                  S"S
/\" \5      /S9S# 5       r+\RA                  S$S
/\" \5      /S9\RA                  S%S
/\" \5      /S9S& 5       5       r,\R[                  S"S
/\" \5      /S9S' 5       r.\R[                  S$S
/\" \5      /S9\R[                  S%S
/\" \5      /S9S( 5       5       r/g))    N)datetime	timedelta)LiteralOptionalUnion)	APIRouterDependsHTTPExceptionRequestResponsestatus)verbose_proxy_logger)	AlertTypeCallInfoProxyErrorTypesProxyExceptionUserAPIKeyAuthWebhookEvent)user_api_key_auth)perform_health_checkz/testhealth)tagsdependenciesrequestc                 :   #    SU R                   R                  0$ 7f)z
[DEPRECATED] use `/health/liveliness` instead.

A test endpoint that pings the proxy server to check if it's healthy.

Parameters:
    request (Request): The incoming request.

Returns:
    dict: A dictionary containing the route of the request URL.
route)urlpath)r   s    j/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/health_endpoints/_health_endpoints.pytest_endpointr       s     $ W[[%%&&s   z/health/servicesF)r   r   include_in_schemazSpecify the service being hit.)descriptionuser_api_key_dictservice)slack_budget_alertslangfuseslack	openmeterwebhookemail
braintrustc                  
  #     SSK JnJnJn  Uc  [	        SSS0S9eUS;  a  [	        SSS	U S
S/ 30S9eUS:X  d   US:X  d  U[
        R                  ;   a=  US:w  a7  [
        R                  " SSSS./SSS9I Sh  vN nSSR                  U5      S.$ US:X  aG  SSK	J
n  U" 5       nUR                  R                  5         [
        R                  " SSSS./SSS9nSSS.$ US:X  aW  [        U R                  =(       d    SSSU R                   U R"                  U R$                  S9nUR'                  SUS 9I Sh  vN   US!:X  d  US:X  Ga  S!UR)                  S"/ 5      ;   Ga  UR*                  R,                   Gb  UR*                  R,                   H  n	UR*                  R.                   b  U	UR*                  R.                  ;  a  M7  S#n
U	[0        R2                  :X  a  S$n
OU	[0        R4                  :X  a  S%n
OuU	[0        R6                  :X  a  S&n
O^U	[0        R&                  :X  a  S'n
OGU	[0        R8                  :X  a  S(n
O0U	[0        R:                  :X  a  S)n
OU	[0        R<                  :X  a  S*n
OS'n
UR?                  U
S+U	S,9I Sh  vN   M     O'UR?                  S-S+[0        R&                  S,9I Sh  vN   Ub\  [@        RB                  " UR*                  RE                  5       5        [@        RB                  " UR*                  RG                  5       5        UR*                  R.                  =(       d    / n[I        U5      nSUS.S/.$ [	        S0SS1R                  U5      0S9eUS2:X  as  [K        S3S4S5U R                  =(       d    SS6SSU R                   [L        RN                  " S75      U R$                  S89
nUR*                  RQ                  US99I Sh  vN   SS:S.$ g GN[ GN GN[ GN2 N! [R         Ga  n[T        RV                  " S;R                  [Y        U5      5      5        [T        RZ                  " [\        R^                  " 5       5        [a        U[        5      (       aV  [c        [e        US<S=[Y        U5       S>35      [f        Rh                  [e        US?S@5      [e        USA[j        Rl                  5      SB9e[a        U[b        5      (       a  Ue[c        SC[Y        U5      -   [f        Rh                  [e        US?S@5      [j        Rl                  SB9eSnAff = f7f)Dz^
Hidden endpoint.

Used by the UI to let user check if slack alerting is working as expected.
r   )general_settingsprisma_clientproxy_logging_objNi  errorzService must be specified.status_codedetail)
r%   r*   r&   r'   r(   r)   r+   otelcustom_callback_api	langsmithz!Service must be in list. Service=z. List=r%   r(   r+   r&   z"openai/litellm-mock-response-modeluserzHey, how's it going?)rolecontentzlitellm:/health/serviceszThis is a mock response)modelmessagesr7   mock_responsesuccessz!Mock LLM request made - check {}.)r   message)LangFuseLoggerz'Mock LLM request made - check langfuse.r)       )tokenspend
max_budgetuser_id	key_aliasteam_iduser_budget)type	user_infor'   alertingzdefault test messagezLLM Exception test alertzLLM Too Slow test alertzLLM Requests Hanging test alertzBudget Alert test alertzDB Exception test alertz!Outage Alert Exception test alertzDaily Reports test alertLow)r>   level
alert_typez"This is a test slack alert messagezBMock Slack Alert sent, verify Slack Alert Received on your channel)r   alert_typesr>   i  z@"{}" not in proxy config: general_settings. Unable to test this.r*   key_createdkeyzTest Email AlertzNEmail Test key (This is only a test alert key. DO NOT USE THIS IN PRODUCTION.)TEST_EMAIL_ADDRESS)
eventevent_groupevent_messagerB   rF   rC   rD   rE   
user_emailrG   )webhook_eventz2Mock Email Alert sent, verify Email Alert ReceivedzMlitellm.proxy.proxy_server.health_services_endpoint(): Exception occured - {}r3   zAuthentication Error()paramNoner2   )r>   rI   rY   codezAuthentication Error, )7litellm.proxy.proxy_serverr-   r.   r/   r
   litellmsuccess_callbackacompletionformat&litellm.integrations.langfuse.langfuser?   Langfuse
auth_check
completionr   rB   rE   rF   rG   budget_alertsgetslack_alerting_instancealert_to_webhook_urlrO   r   llm_exceptionsllm_too_slowllm_requests_hangingdb_exceptionsoutage_alertsdaily_reportsalerting_handlerasynciocreate_tasksend_monthly_spend_reportsend_weekly_spend_reportlistr   osgetenv&send_key_created_or_user_invited_email	Exceptionr   r0   strdebug	traceback
format_exc
isinstancer   getattrr   
auth_errorr   HTTP_500_INTERNAL_SERVER_ERROR)r#   r$   r-   r.   r/   _r?   langfuse_loggerrJ   rN   test_messagerO   rW   es                 r   health_services_endpointr   2   sn    4C
	
 	
 ?2N(O   
 
  @	RgQhPij  {",&7333:8M)):#)6LMN/7	 A $>EEgN 
 j M,.O$$//1"":#)6LMN/7	A $D 
 i '--3)11+55)11I $11"# 2   
 g,A!A*..z2>> &==RR 
 +BBWW # .EEQQ#'( *#4#L#L#X#X!Y %'=%)A)AA+EL'9+A+AA+DL'9+I+II+LL'9+B+BB+DL'9+B+BB+DL'9+B+BB+NL'9+B+BB+EL+DL/@@$0* A   9 X@ ,<< D##,#:#: =    !,'')AA[[] '')AAZZ\
 &==IIOR  #;/'#.c  $ #!c!j!j#"  g(#!0'--3j)1199%9:)11M $;;bb+ c   
 $O ' gHV^  
""[bbA	

 	""9#7#7#9:a'' 8/DSVHA-NO$//a&1Qv/T/TU	  >**G,s1v5 ++!Wf-66	
 	
!
s   TA6O# :O;O# TAO# T AO# 8O9EO#  O+O# ,O-BO# ?T B
O# 
O!O# TO# O# O# O# !O# #T.DTTTz/healthz!Specify the model name (optional)r:   c                 n  #    SSK JnJnJnJnJn   UcJ  Ub-  [        / XbS9I Sh  vN u  pxUU[        U5      [        U5      S.$ [        [        R                  SS0S9e[        R                  " U5      n	[        U R                  5      S:  a  O U(       a  U$ [        XUS	9I Sh  vN u  pxUU[        U5      [        U5      S.$  N N!! [         a^  n
[        R                   " S
R#                  [%        U
5      5      5        [        R&                  " [(        R*                  " 5       5        U
eSn
A
ff = f7f)u  
🚨 USE `/health/liveliness` to health check the proxy 🚨

See more 👉 https://docs.litellm.ai/docs/proxy/health


Check the health of all the endpoints in config.yaml

To run health checks in the background, add this to config.yaml:
```
general_settings:
    # ... other settings
    background_health_checks: True
```
else, the health checks will be run on models when /health is called.
r   )health_check_detailshealth_check_resultsllm_model_listuse_background_health_checks
user_modelN)
model_list	cli_modeldetails)healthy_endpointsunhealthy_endpointshealthy_countunhealthy_countr0   zModel list not initializedr1   )r   zHlitellm.proxy.proxy_server.py::health_endpoint(): Exception occured - {})r\   r   r   r   r   r   r   lenr
   r   r   copydeepcopymodelsrx   r   r0   r`   ry   rz   r{   r|   )r#   r:   r   r   r   r   r   r   r   _llm_model_listr   s              r   health_endpointr     sJ    . +!%?S!Z@ :6! *;+>%():%;'*+>'?	   "AA!=>  --7 ''(1,''';O0D< 62
 &7':!$%6!7#&':#;	 5:,6  ""V]]A	

 	""9#7#7#9:sd   D5C
 CC
 D5AC
 D5C
 &C'C
 D5C
 C
 

D2AD--D22D5unknownr   last_updatedc                  F  #    SSK Jn   [        R                  " 5       [        S   -
  n[        S   S:w  a  U[        SS9:  a  [        $ U c  S[        R                  " 5       S	.q[        $ U R                  5       I S h  vN   S
[        R                  " 5       S	.q[        $  N"7f)Nr   )r.   r   r   r      )minutesdisconnectedr   	connected)r\   r.   r   nowdb_health_cacher   health_check)r.   	time_diffs     r   _db_health_readiness_checkr   b  s     8 !@@Ix I-)iPQ>R2R%3X\\^T

$
$
&&&!,hllnMO 's   A:B!<B=#B!z	/settingsz/active/callbacksc                    #    SSK Jn Jn  [        U R	                  S5      5      n[
        R                   Vs/ s H  n[        U5      PM     nn[
        R                   Vs/ s H  n[        U5      PM     nn[
        R                   Vs/ s H  n[        U5      PM     nn[
        R                   Vs/ s H  n[        U5      PM     nn[
        R                   Vs/ s H  n[        U5      PM     nn[
        R                   Vs/ s H  n[        U5      PM     n	n[
        R                   Vs/ s H  n[        U5      PM     n
nUU-   U-   U-   U-   U	-   U
-   nUR                  nSnU(       a   [        U[        5      (       a  [!        U5      nUUUUUUU	U
U[!        U5      U[
        R"                  S.$ s  snf s  snf s  snf s  snf s  snf s  snf s  snf 7f)a%  
Returns a list of litellm level settings

This is useful for debugging and ensuring the proxy server is configured correctly.

Response schema:
```
{
    "alerting": _alerting,
    "litellm.callbacks": litellm_callbacks,
    "litellm.input_callback": litellm_input_callbacks,
    "litellm.failure_callback": litellm_failure_callbacks,
    "litellm.success_callback": litellm_success_callbacks,
    "litellm._async_success_callback": litellm_async_success_callbacks,
    "litellm._async_failure_callback": litellm_async_failure_callbacks,
    "litellm._async_input_callback": litellm_async_input_callbacks,
    "all_litellm_callbacks": all_litellm_callbacks,
    "num_callbacks": len(all_litellm_callbacks),
    "num_alerting": _num_alerting,
    "litellm.request_timeout": litellm.request_timeout,
}
```
r   )r-   r/   rK   )rK   zlitellm.callbackszlitellm.input_callbackzlitellm.failure_callbackzlitellm.success_callbackzlitellm._async_success_callbackzlitellm._async_failure_callbackzlitellm._async_input_callbackall_litellm_callbacksnum_callbacksnum_alertingzlitellm.request_timeout)r\   r-   r/   ry   rf   r]   	callbacksinput_callbackfailure_callbackr^   _async_success_callback_async_failure_callback_async_input_callbackrK   r}   rt   r   request_timeout)r-   r/   	_alertingxlitellm_callbackslitellm_input_callbackslitellm_failure_callbackslitellm_success_callbackslitellm_async_success_callbackslitellm_async_failure_callbackslitellm_async_input_callbacksr   rK   _num_alertings                 r   active_callbacksr   w  s    F O$((45I *1):):;):AQ):;/6/E/EF/E!s1v/EF181I1I J1IAQ1I J181I1I J1IAQ1I J7>7V7V&W7V!s1v7V#&W7>7V7V&W7V!s1v7V#&W5<5R5R$S5RSV5R!$S 	
!	"
#	$ $	$ *		*
 *	* (	(  !))HMJx..H ."9$=$=+J+J)F!623%#*#:#: / <F J J&W&W$SsY   5GF3G F85G	F=G2GGG0GGG-GBGc                     [        U [        5      (       a  U $  U R                  $ ! [         a7     U R                  R                  s $ ! [         a    [        U 5      s s $ f = ff = f)N)r}   ry   __name__AttributeError	__class__)callbacks    r   callback_namer     sd    (C  !    !	!%%... 	!x= 	!!s,   % 
A&AA&A"A&!A""A&z/health/readinessc                    #    SSK Jn Jn   / n [        R                   Vs/ s H  n[        U5      PM     nnSn[        R                  b~  SSKJ	n  [        R                  R                  n[        [        R                  R                  U5      (       a5   [        R                  R                  R                  5       I Sh  vN nXFS.nU b  [        5       I Sh  vN nSSUUUS	.UE$ SS
UUUS	.$ s  snf ! [         a    [        R                  n Nf = f NT! [         a  nS[        U5      -   n SnANoSnAff = f Nb! [         a  n[!        SS[        U5       S3S9eSnAff = f7f)zB
Unprotected endpoint for checking if worker can receive requests
r   )r.   versionN)RedisSemanticCachezindex does not exist - error: )rI   
index_infohealthyr   )r   dbcachelitellm_versionsuccess_callbackszNot connectedi  zService Unhealthy (rX   r1   )r\   r.   r   r]   r^   r   r   r   litellm.caching.cachingr   rI   r}   _index_inforx   ry   r   r
   )	r.   r   success_callback_namesr   
cache_typer   r   r   db_health_statuss	            r   health_readinessr     s|     B2U!#	> +2*B*B&*BQa *B # & 
==$B ++J'----/ABBK'.}}':':'F'F'H!HJ '1K
 $%?%AA#!##*%; #  $%##*%; G&  	>%,%=%="	> "I  K!ACF!JJK  B"  U6I#a&QR4STTUs   	E'D> C5 C0C5 AD> +D  DD D> D<D> 'E'(D> /E'0C5 5DD> DD> D 
D9!D4/D> 4D99D> >
E$EE$$E'z/health/livelinessz/health/livenessc                     #    g7f)z6
Unprotected endpoint for checking if worker is alive
z
I'm alive! r       r   health_livelinessr     s
      s   c                  *   #    SSSS.n [        U SS9$ 7f)z.
Options endpoint for health/readiness check.
GET, OPTIONS*AllowzAccess-Control-Allow-MethodszAccess-Control-Allow-Headers   headersr2   r   response_headerss    r   health_readiness_optionsr   $  s(       (6(+
 ,#>>   c                  *   #    SSSS.n [        U SS9$ 7f)z/
Options endpoint for health/liveliness check.
r   r   r   r   r   r   r   s    r   health_liveliness_optionsr   5  s(       (6(+
 ,#>>r   )0rp   r   ru   r{   r   r   typingr   r   r   fastapir   r	   r
   r   r   r   r]   litellm._loggingr   litellm.proxy._typesr   r   r   r   r   r   $litellm.proxy.auth.user_api_key_authr   litellm.proxy.health_checkr   routerrf   r    Queryry   r   r   r   r   r   r   r   r   r   optionsr   r   r   r   r   <module>r      s     	  ( + +  P P  1  C ; 
 
+,-  
' '
'  
+,-	   )00A(B 	"BCW
%W
	
 			W
W
t IXJg>O6P5QR(/0A(B"===I%IC=I SIX 'G* 
+,-  
 
+,-  
BBJ
! 
+,-  
8U
8Uv 
+,-  
 
+,-  
 
+,-  
	?
	? 
+,-  
 
+,-  
	?	?r   