mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-27 11:22:03 +00:00
fix(auxiliary): treat 403 subscription and session-usage-limit errors as payment errors for fallback
Ollama Cloud (and similar) return 403 with bodies like "this model requires a subscription, upgrade for access" or "you have reached your session usage limit, upgrade for higher limits". These are capacity/billing conditions semantically identical to credit exhaustion, but _is_payment_error() did not recognize them (403 missing from the status set; keywords missing), so the configured fallback_chain was never tried and compression failed outright. Adds 403 to the status set and the subscription/session-usage keywords. Salvaged from #49076 by @herbalizer404.
This commit is contained in:
parent
ca714f6189
commit
ff8920299c
2 changed files with 18 additions and 1 deletions
|
|
@ -2470,7 +2470,7 @@ def _is_payment_error(exc: Exception) -> bool:
|
|||
# but sometimes wrap them in 429 or other codes.
|
||||
# Daily quota exhaustion from Bedrock, Vertex AI, and similar providers
|
||||
# uses different language but is semantically identical to credit exhaustion.
|
||||
if status in {402, 404, 429, None}:
|
||||
if status in {402, 403, 404, 429, None}:
|
||||
if any(kw in err_lower for kw in (
|
||||
"credits", "insufficient funds",
|
||||
"can only afford", "billing",
|
||||
|
|
@ -2479,6 +2479,8 @@ def _is_payment_error(exc: Exception) -> bool:
|
|||
"balance_depleted", "no usable credits",
|
||||
"model_not_supported_on_free_tier",
|
||||
"not available on the free tier",
|
||||
"requires a subscription", "upgrade for access",
|
||||
"upgrade for higher limits", "reached your session usage limit",
|
||||
# Daily / monthly / weekly quota exhaustion keywords
|
||||
"quota exceeded", "quota_exceeded",
|
||||
"too many tokens per day", "daily limit",
|
||||
|
|
|
|||
|
|
@ -1406,6 +1406,21 @@ class TestIsPaymentError:
|
|||
exc.status_code = 404
|
||||
assert _is_payment_error(exc) is True
|
||||
|
||||
def test_403_subscription_required_is_payment(self):
|
||||
exc = Exception(
|
||||
"this model requires a subscription, upgrade for access: "
|
||||
"https://ollama.com/upgrade"
|
||||
)
|
||||
setattr(exc, "status_code", 403)
|
||||
assert _is_payment_error(exc) is True
|
||||
|
||||
def test_429_session_usage_limit_is_payment(self):
|
||||
exc = Exception(
|
||||
"you have reached your session usage limit, upgrade for higher limits"
|
||||
)
|
||||
setattr(exc, "status_code", 429)
|
||||
assert _is_payment_error(exc) is True
|
||||
|
||||
def test_404_generic_not_found_is_not_payment(self):
|
||||
exc = Exception("Not Found")
|
||||
exc.status_code = 404
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue