#9173: Fix: Improve error messaging for API rate limits and billing errors
agents
stale
Cluster:
Error Handling Improvements
## Summary
This PR improves error messaging when API keys hit rate limits or run out of credits, addressing issue #9067 where users were confused by generic error messages and resorted to unnecessary troubleshooting (like reinstalling OpenClaw).
## Problem
When users' API keys hit rate limits or billing quotas, they received generic error messages that didn't explain:
- **What** the actual problem was (rate limit vs billing vs other errors)
- **Why** it happened (API key limits, credits exhausted)
- **How** to fix it (wait, add credits, upgrade plan)
This led to user confusion, with one user reporting: "Currently there's no indication your keys are maxed out. I ended up deleting and reinstalling openclaw but all I had to do was buy some more tokens."
## Solution
Enhanced error messages in `src/agents/pi-embedded-helpers/errors.ts`:
### Rate Limit Errors
**Before:**
```
The AI service is temporarily overloaded. Please try again in a moment.
```
**After:**
```
Rate limit exceeded: Your API key has hit its usage limit.
Wait for the limit to reset, upgrade your plan, or add more credits.
Check your provider's dashboard for details.
```
### Billing/Quota Errors
**Before:**
Generic HTTP error formatting
**After:**
```
Billing error: Your API credits may be exhausted or payment is required.
Please check your provider's billing dashboard and add credits or update your payment method.
No need to reinstall OpenClaw - just top up your account!
```
## Changes Made
1. **formatAssistantErrorText()** - Added specific handlers for rate limit and billing errors before falling through to generic formatting
2. **sanitizeUserFacingText()** - Added the same specific handlers for consistency across all error display paths
## Why This Works
The error detection functions (`isRateLimitErrorMessage`, `isBillingErrorMessage`) were already correctly identifying these error types, but the messages were falling through to generic formatting. Now they get clear, actionable guidance.
## Testing
- ✅ TypeScript compilation passes (`pnpm tsgo`)
- ✅ No breaking changes - only improved error messages
- ✅ Existing error detection logic preserved
- ✅ Falls back gracefully for other error types
## Impact
- **Better UX**: Users immediately understand the problem
- **Reduced support burden**: Clear instructions prevent unnecessary troubleshooting
- **Explicit reassurance**: "No need to reinstall" directly addresses the reported user behavior
## Fixes
Closes #9067
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Updates assistant-facing error formatting to provide explicit, actionable messages for detected API rate-limit and billing/quota errors (instead of falling back to generic overloaded/HTTP formatting). Changes are localized to the Pi embedded helper error formatter so downstream CLI/UI surfaces can show clearer remediation steps (wait/reset limits, add credits/upgrade, check provider dashboard).
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge, with minor UX consistency considerations.
- Change is isolated to error-message formatting and uses existing detection helpers; no functional control flow changes beyond message selection. I couldn’t execute the full test suite in this environment (pnpm missing), so confidence is slightly reduced.
- src/agents/pi-embedded-helpers/errors.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#15109: fix: distinguish transient API errors from billing errors
by jwchmodx · 2026-02-13
87.7%
#8661: fix: display rate limit errors correctly instead of as context over...
by dbottme · 2026-02-04
85.4%
#19271: fix: remove false-positive billing text rewrite in sanitizeUserFaci...
by MisterGuy420 · 2026-02-17
80.2%
#18907: Fix: Improve browser error messages to avoid misleading agents
by jriff · 2026-02-17
80.1%
#16307: fix: surface billing/auth FailoverErrors as user-friendly messages
by petter-b · 2026-02-14
79.1%
#14368: fix: skip auth profile cooldown on format errors to prevent provide...
by koatora20 · 2026-02-12
78.3%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
77.7%
#19451: fix(errors): surface provider hint for role-ordering failures
by rafaelipuente · 2026-02-17
77.7%
#13960: fix(ui): preserve structured config validation error details
by constansino · 2026-02-11
77.4%
#17647: fix: Display error messages instead of (no output) for non-Claude m...
by MisterGuy420 · 2026-02-16
77.0%