From 6d46f869646cd9ae2ddb86775a0cd4d4738b44db Mon Sep 17 00:00:00 2001 From: Shroominic Date: Fri, 22 Aug 2025 15:29:20 -0300 Subject: [PATCH] Apply proxy.py changes from reserved-balance-and-fixes branch --- routstr/proxy.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/routstr/proxy.py b/routstr/proxy.py index ed5080a4..2e0d615f 100644 --- a/routstr/proxy.py +++ b/routstr/proxy.py @@ -540,11 +540,10 @@ async def proxy( ) logger.debug("Processing unauthenticated GET request", extra={"path": path}) - # Prepare headers for upstream + # TODO: why is this needed? can we remove it? headers = prepare_upstream_headers(dict(request.headers)) return await forward_get_to_upstream(request, path, headers) - cost_per_request = 0 # Only pay for request if we have request body data (for completions endpoints) if request_body_dict: logger.info( @@ -589,7 +588,7 @@ async def proxy( ) if response.status_code != 200: - await revert_pay_for_request(key, session, cost_per_request) + await revert_pay_for_request(key, session, max_cost_for_model) logger.warning( "Upstream request failed, revert payment", extra={ @@ -597,8 +596,22 @@ async def proxy( "path": path, "key_hash": key.hashed_key[:8] + "...", "key_balance": key.balance, + "max_cost_for_model": max_cost_for_model, + "upstream_headers": response.headers + if hasattr(response, "headers") + else None, + "upstream_response": response.body + if hasattr(response, "body") + else None, }, ) + request_id = ( + request.state.request_id if hasattr(request.state, "request_id") else None + ) + raise HTTPException( + status_code=502, + detail=f"Upstream request failed, please contact support with request id: {request_id}", + ) return response