diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index 28980eb26..7c2864f0f 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -14,6 +14,7 @@ from agents_api.exceptions import PromptTooBigError from pycozo.client import QueryException from temporalio.service import RPCError +from litellm.exceptions import APIError from agents_api.dependencies.auth import get_api_key from agents_api.env import sentry_dsn @@ -120,6 +121,14 @@ async def prompt_too_big_error(request: Request, exc: PromptTooBigError): ) +@app.exception_handler(APIError) +async def litellm_api_error(request: Request, exc: APIError): + return JSONResponse( + status_code=status.HTTP_502_BAD_GATEWAY, + content={"error": {"message": str(exc)}}, + ) + + def main( host="127.0.0.1", port=8000,