fix proxy x-cashu model forwarding

This commit is contained in:
9qeklajc
2025-10-24 22:20:03 +02:00
parent 430bf8a610
commit c3c4e886c8
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -242,7 +242,7 @@ async def proxy(
check_token_balance(headers, request_body_dict, max_cost_for_model)
if x_cashu := headers.get("x-cashu", None):
return await upstream.handle_x_cashu(request, x_cashu, path, max_cost_for_model)
return await upstream.handle_x_cashu(request, x_cashu, path, max_cost_for_model, model_obj)
elif auth := headers.get("authorization", None):
key = await get_bearer_token_key(headers, path, session, auth)
+6 -2
View File
@@ -1343,6 +1343,7 @@ class UpstreamProvider:
amount: int,
unit: str,
max_cost_for_model: int,
model_obj: Model,
) -> Response | StreamingResponse:
"""Forward request paid with X-Cashu token to upstream service.
@@ -1353,6 +1354,7 @@ class UpstreamProvider:
amount: Payment amount from X-Cashu token
unit: Payment unit (sat or msat)
max_cost_for_model: Maximum cost for the model
model_obj: Model object for the request
Returns:
Response or StreamingResponse with refund if applicable
@@ -1363,7 +1365,7 @@ class UpstreamProvider:
url = f"{self.base_url}/{path}"
request_body = await request.body()
transformed_body = self.prepare_request_body(request_body)
transformed_body = self.prepare_request_body(request_body, model_obj)
logger.debug(
"Forwarding request to upstream",
@@ -1494,7 +1496,7 @@ class UpstreamProvider:
)
async def handle_x_cashu(
self, request: Request, x_cashu_token: str, path: str, max_cost_for_model: int
self, request: Request, x_cashu_token: str, path: str, max_cost_for_model: int, model_obj: Model
) -> Response | StreamingResponse:
"""Handle request with X-Cashu token payment, redeeming token and forwarding request.
@@ -1503,6 +1505,7 @@ class UpstreamProvider:
x_cashu_token: X-Cashu token from request header
path: Request path
max_cost_for_model: Maximum cost for the model
model_obj: Model object for the request
Returns:
Response or StreamingResponse from upstream with refund if applicable
@@ -1535,6 +1538,7 @@ class UpstreamProvider:
amount,
unit,
max_cost_for_model,
model_obj,
)
except Exception as e:
error_message = str(e)