diff --git a/routstr/core/settings.py b/routstr/core/settings.py index efaa8484..35560a4c 100644 --- a/routstr/core/settings.py +++ b/routstr/core/settings.py @@ -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") diff --git a/routstr/payment/helpers.py b/routstr/payment/helpers.py index 2064727c..c44d3010 100644 --- a/routstr/payment/helpers.py +++ b/routstr/payment/helpers.py @@ -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, diff --git a/tests/unit/test_payment_helpers.py b/tests/unit/test_payment_helpers.py index ad757e89..6ac4a6f1 100644 --- a/tests/unit/test_payment_helpers.py +++ b/tests/unit/test_payment_helpers.py @@ -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"