mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 11:04:36 +00:00
Revert proxy.py changes - moved to proxy-changes-only branch
This commit is contained in:
+3
-16
@@ -540,10 +540,11 @@ async def proxy(
|
||||
)
|
||||
|
||||
logger.debug("Processing unauthenticated GET request", extra={"path": path})
|
||||
# TODO: why is this needed? can we remove it?
|
||||
# Prepare headers for upstream
|
||||
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(
|
||||
@@ -588,7 +589,7 @@ async def proxy(
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
await revert_pay_for_request(key, session, max_cost_for_model)
|
||||
await revert_pay_for_request(key, session, cost_per_request)
|
||||
logger.warning(
|
||||
"Upstream request failed, revert payment",
|
||||
extra={
|
||||
@@ -596,22 +597,8 @@ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user