This commit is contained in:
9qeklajc
2025-10-14 00:16:16 +02:00
parent 9911ce9dcd
commit b4eac33542
3 changed files with 12 additions and 15 deletions
-1
View File
@@ -53,7 +53,6 @@ class Settings(BaseSettings):
tolerance_percentage: float = Field(default=1.0, env="TOLERANCE_PERCENTAGE")
# Minimum per-request charge in millisatoshis when model pricing is free/zero
min_request_msat: int = Field(default=1, env="MIN_REQUEST_MSAT")
cashu_mint_fee_msat: int = Field(default=60, env="CASHU_MINT_FEE_MSAT")
# Network
cors_origins: list[str] = Field(default_factory=lambda: ["*"], env="CORS_ORIGINS")
+1 -1
View File
@@ -72,7 +72,7 @@ def check_token_balance(headers: dict, body: dict, max_cost_for_model: int) -> N
token_obj.amount if token_obj.unit == "msat" else token_obj.amount * 1000
)
fee_buffer = getattr(settings, "cashu_mint_fee_msat", 60)
fee_buffer = 60
if max_cost_for_model > amount_msat + fee_buffer:
raise HTTPException(
status_code=413,
+11 -13
View File
@@ -139,10 +139,9 @@ async def test_check_token_balance_with_fee_buffer(
monkeypatch.setattr(
"routstr.payment.helpers.deserialize_token_from_string", mock_deserialize
)
with patch.object(settings, "cashu_mint_fee_msat", 100):
headers = {"x-cashu": "token"}
body = {"model": "gpt-4"}
check_token_balance(headers, body, max_cost_for_model=320450)
headers = {"x-cashu": "token"}
body = {"model": "gpt-4"}
check_token_balance(headers, body, max_cost_for_model=320450)
def test_check_token_balance_insufficient(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -156,12 +155,11 @@ def test_check_token_balance_insufficient(monkeypatch: pytest.MonkeyPatch) -> No
monkeypatch.setattr(
"routstr.payment.helpers.deserialize_token_from_string", mock_deserialize
)
with patch.object(settings, "cashu_mint_fee_msat", 100):
headers = {"x-cashu": "token"}
body = {"model": "gpt-4"}
with pytest.raises(HTTPException) as exc:
check_token_balance(headers, body, max_cost_for_model=320450)
assert exc.value.status_code == 413
detail = exc.value.detail # type: ignore[assignment]
assert isinstance(detail, dict)
assert detail.get("type") == "minimum_balance_required"
headers = {"x-cashu": "token"}
body = {"model": "gpt-4"}
with pytest.raises(HTTPException) as exc:
check_token_balance(headers, body, max_cost_for_model=320450)
assert exc.value.status_code == 413
detail = exc.value.detail # type: ignore[assignment]
assert isinstance(detail, dict)
assert detail.get("type") == "minimum_balance_required"