← Back to PRs

#9173: Fix: Improve error messaging for API rate limits and billing errors

by vishaltandale00 open 2026-02-04 23:44 View on GitHub →
agents stale
## 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