From 28a20c180fca9531879c969ddd4bc656bcf185b8 Mon Sep 17 00:00:00 2001 From: Chesars Date: Wed, 4 Mar 2026 19:39:48 -0300 Subject: [PATCH] fix: add ProxyException handling to count_tokens endpoint Match the error handling pattern used in the Anthropic count_tokens endpoint: catch ProxyException separately to surface its status code and message, and include error details in the generic 500 fallback. --- litellm/proxy/response_api_endpoints/endpoints.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.py index 96aec60eee1..441b0f1b317 100644 --- a/litellm/proxy/response_api_endpoints/endpoints.py +++ b/litellm/proxy/response_api_endpoints/endpoints.py @@ -520,6 +520,12 @@ async def count_response_input_tokens( except HTTPException: raise + except ProxyException as e: + status_code = int(e.code) if e.code and e.code.isdigit() else 500 + raise HTTPException( + status_code=status_code, + detail={"error": e.message}, + ) except Exception as e: verbose_proxy_logger.exception( "litellm.proxy.response_api_endpoints.count_response_input_tokens(): Exception occurred - {}".format( @@ -527,7 +533,7 @@ async def count_response_input_tokens( ) ) raise HTTPException( - status_code=500, detail={"error": "Internal server error"} + status_code=500, detail={"error": f"Internal server error: {str(e)}"} )