mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
Merge pull request #4286 from BerriAI/litellm_support_options_health_endpoints
feat - support CURL OPTIONS for `/health/readiness` endpoint
This commit is contained in:
commit
93c5625dc6
1 changed files with 49 additions and 19 deletions
|
|
@ -1,22 +1,18 @@
|
|||
from typing import Optional, Literal
|
||||
import litellm
|
||||
import os
|
||||
import asyncio
|
||||
import fastapi
|
||||
import copy
|
||||
import os
|
||||
import traceback
|
||||
from datetime import datetime, timedelta
|
||||
from fastapi import Depends, Request, APIRouter, Header, status
|
||||
from litellm.proxy.health_check import perform_health_check
|
||||
from fastapi import HTTPException
|
||||
import copy
|
||||
from typing import Literal, Optional
|
||||
|
||||
import fastapi
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Request, Response, status
|
||||
|
||||
import litellm
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.proxy._types import CallInfo, ProxyException, UserAPIKeyAuth, WebhookEvent
|
||||
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||
from litellm.proxy._types import (
|
||||
UserAPIKeyAuth,
|
||||
ProxyException,
|
||||
WebhookEvent,
|
||||
CallInfo,
|
||||
)
|
||||
from litellm.proxy.health_check import perform_health_check
|
||||
|
||||
#### Health ENDPOINTS ####
|
||||
|
||||
|
|
@ -63,9 +59,9 @@ async def health_services_endpoint(
|
|||
"""
|
||||
try:
|
||||
from litellm.proxy.proxy_server import (
|
||||
proxy_logging_obj,
|
||||
prisma_client,
|
||||
general_settings,
|
||||
prisma_client,
|
||||
proxy_logging_obj,
|
||||
)
|
||||
|
||||
if service is None:
|
||||
|
|
@ -282,9 +278,9 @@ async def health_endpoint(
|
|||
"""
|
||||
from litellm.proxy.proxy_server import (
|
||||
health_check_results,
|
||||
llm_model_list,
|
||||
use_background_health_checks,
|
||||
user_model,
|
||||
llm_model_list,
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
@ -361,7 +357,7 @@ async def active_callbacks():
|
|||
"""
|
||||
Returns a list of active callbacks on litellm.callbacks, litellm.input_callback, litellm.failure_callback, litellm.success_callback
|
||||
"""
|
||||
from litellm.proxy.proxy_server import proxy_logging_obj, general_settings
|
||||
from litellm.proxy.proxy_server import general_settings, proxy_logging_obj
|
||||
|
||||
_alerting = str(general_settings.get("alerting"))
|
||||
# get success callbacks
|
||||
|
|
@ -413,7 +409,7 @@ async def health_readiness():
|
|||
"""
|
||||
Unprotected endpoint for checking if worker can receive requests
|
||||
"""
|
||||
from litellm.proxy.proxy_server import proxy_logging_obj, prisma_client, version
|
||||
from litellm.proxy.proxy_server import prisma_client, proxy_logging_obj, version
|
||||
|
||||
try:
|
||||
# get success callback
|
||||
|
|
@ -476,3 +472,37 @@ async def health_liveliness():
|
|||
Unprotected endpoint for checking if worker is alive
|
||||
"""
|
||||
return "I'm alive!"
|
||||
|
||||
|
||||
@router.options(
|
||||
"/health/readiness",
|
||||
tags=["health"],
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
)
|
||||
async def health_readiness_options():
|
||||
"""
|
||||
Options endpoint for health/readiness check.
|
||||
"""
|
||||
response_headers = {
|
||||
"Allow": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "*",
|
||||
}
|
||||
return Response(headers=response_headers, status_code=200)
|
||||
|
||||
|
||||
@router.options(
|
||||
"/health/liveliness",
|
||||
tags=["health"],
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
)
|
||||
async def health_liveliness_options():
|
||||
"""
|
||||
Options endpoint for health/liveliness check.
|
||||
"""
|
||||
response_headers = {
|
||||
"Allow": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "*",
|
||||
}
|
||||
return Response(headers=response_headers, status_code=200)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue