The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): classify OpenAI spend/usage-limit error codes as billing
teknium3ed62fc5e800
diff --git a/agent/error_classifier.py b/agent/error_classifier.pyindex b49ff9b7b36..5d10d05d804 100644--- a/agent/error_classifier.py+++ b/agent/error_classifier.py@@ -113,6 +113,11 @@ _BILLING_ERROR_CODES = frozenset({"insufficient_quota", "billing_not_active", "payment_required", "insufficient_credits","no_usable_credits", "balance_depleted", "model_not_supported_on_free_tier","member_spend_cap_exceeded", "terminal_quota_exhausted", _XAI_SPENDING_LIMIT_ERROR_CODE,+ # OpenAI (and OpenAI-compatible aggregators) spend/usage-limit family:+ # a credit balance or an org/project spend or usage cap is exhausted —+ # terminal for this credential until limits are raised.+ "credit_balance_exhausted", "organization_spend_limit_exceeded",+ "organization_usage_limit_exceeded", "project_spend_limit_exceeded",})# Transient rate limiting. Bedrock "Throttling error: Too many tokens" alsodiff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.pyindex 995a91fb40b..c539e8917b7 100644--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@ -390,6 +390,32 @@ class TestClassifyApiError:assert result.reason == FailoverReason.billingassert result.retryable is False+ @pytest.mark.parametrize(+ "code",+ [+ "credit_balance_exhausted",+ "organization_spend_limit_exceeded",+ "project_spend_limit_exceeded",+ "organization_usage_limit_exceeded",+ ],+ )+ def test_openai_spend_usage_limit_codes_are_billing(self, code):+ # OpenAI / OpenAI-compatible aggregators emit these structured codes+ # when a credit balance or org/project spend/usage cap is exhausted.+ # They must classify as billing (rotate + fallback), not fall through+ # to a generic bucket. (clean-room port of zed-industries/zed#63208)+ # No status_code: SSE/stream-surfaced errors carry only the+ # structured body, exercising the _classify_by_error_code path.+ e = MockAPIError(+ "request rejected",+ body={"error": {"code": code, "message": "request rejected"}},+ )+ result = classify_api_error(e, provider="openai", model="gpt-5")+ assert result.reason == FailoverReason.billing+ assert result.retryable is False+ assert result.should_rotate_credential is True+ assert result.should_fallback is True+def test_429_rate_limit_phrase_never_promotes_to_billing(self):# The exclusion guard: "Rate limit exceeded" contains the# "limit exceeded" usage-limit substring, but an explicit rate-limit