Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 11, 2025

Summary

This PR improves the error handling for rate limiting in OpenAI Compatible providers, specifically addressing the issue reported by a Chinese user who was experiencing unclear error messages when hitting API rate limits.

Problem

The user reported in #6928 that they were getting rate limit errors when using OpenAI Compatible API with gemini2.5pro model, but the error messages were not clear or helpful, especially in Chinese.

Solution

  1. Enhanced Error Handling: Added specific error handling for HTTP 429 (rate limit) status codes in BaseOpenAiCompatibleProvider
  2. Localized Error Messages: Added clear, actionable error messages in both English and Chinese that:
    • Explicitly state that the rate limit has been exceeded
    • Suggest waiting before making another request
    • Recommend upgrading the plan or reducing request frequency if using a free tier
  3. Better Error Context: The error messages now include the provider name for better debugging

Changes

  • Modified src/api/providers/base-openai-compatible-provider.ts to catch and handle rate limit errors specifically
  • Added new translation keys in src/i18n/locales/en/common.json for OpenAI Compatible errors
  • Added corresponding Chinese translations in src/i18n/locales/zh-CN/common.json

Testing

  • ✅ Code passes linting (turbo lint)
  • ✅ Type checking passes (turbo check-types)
  • The error messages will now be clearer and more helpful for users experiencing rate limiting

Related Issues

Fixes #6928

Screenshots

The new error messages will appear as:

  • English: "{Provider} API rate limit exceeded. Please wait a moment before making another request. If using a free tier, consider upgrading your plan or reducing request frequency."
  • Chinese: "{Provider} API 速率限制已超出。请稍等片刻后再发起请求。如果您使用的是免费套餐,请考虑升级您的计划或降低请求频率。"

Important

Improves error handling for rate limit issues in OpenAI Compatible providers with localized messages for Chinese users.

  • Behavior:
    • Enhanced error handling for HTTP 429 status codes in BaseOpenAiCompatibleProvider.
    • Localized error messages in English and Chinese for rate limit issues, suggesting waiting, upgrading plan, or reducing request frequency.
    • Error messages include provider name for better debugging.
  • Files:
    • Modified base-openai-compatible-provider.ts to handle rate limit errors.
    • Added translation keys in en/common.json and zh-CN/common.json for OpenAI Compatible errors.
  • Testing:
    • Code passes linting and type checking.
    • Improved clarity and helpfulness of error messages for rate limiting.

This description was created by Ellipsis for 996a994. You can customize this summary. It will automatically update as commits are pushed.

- Add specific error handling for 429 status codes in BaseOpenAiCompatibleProvider
- Add localized error messages for rate limiting in English and Chinese
- Provide clearer guidance to users when hitting rate limits
- Suggest upgrading plan or reducing request frequency

Fixes #6928
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 11, 2025 11:18
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working documentation Improvements or additions to documentation labels Aug 11, 2025
@roomote roomote bot mentioned this pull request Aug 11, 2025
- Added English fallback translations for all supported languages
- Ensures translation check CI passes
- Maintains consistency across all language files
}
}
}
} catch (error: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement handling rate limits. Consider preserving the original error’s stack (e.g. using error chaining if available) to aid debugging.


if (error instanceof Error) {
throw new Error(`${this.providerName} completion error: ${error.message}`)
throw new Error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the completePrompt catch block, error messages are localized correctly. Again, consider chaining the original error to preserve context.

Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this code 5 minutes ago and already found 5 things wrong with it. Classic me.

"openaiCompatible": {
"rateLimitExceeded": "{{provider}} API rate limit exceeded. Please wait a moment before making another request. If using a free tier, consider upgrading your plan or reducing request frequency.",
"genericError": "{{provider}} API error: {{error}}",
"completionError": "{{provider}} completion error: {{error}}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice we're only adding translations for English and Chinese, but the project supports 17 other locales. Should we add placeholder translations for the other languages (ca, de, es, fr, hi, id, it, ja, ko, nl, pl, pt-BR, ru, tr, vi, zh-TW) to maintain consistency?

Even English fallbacks in those files would be better than missing keys that could cause runtime issues.

}
} catch (error: any) {
// Handle rate limiting errors specifically
if (error?.status === 429 || error?.response?.status === 429) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error detection pattern is duplicated here and in the method. Would it make sense to extract this into a helper function?

Then add a private method:

const errorMessage = t("common:errors.openaiCompatible.rateLimitExceeded", {
provider: this.providerName,
})
throw new Error(errorMessage)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this base class affects 5 providers (Fireworks, Chutes, ZAi, SambaNova, Groq), would it be helpful to add unit tests for this rate limit handling? This would ensure the error handling works consistently across all inheriting providers.

} catch (error) {
} catch (error: any) {
// Handle rate limiting errors specifically
if (error?.status === 429 || error?.response?.status === 429) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also checking for rate limit indicators in error messages or error codes, as some OpenAI-compatible providers might return rate limit errors differently. For example:

},
"mode_import_failed": "Ha fallat la importació del mode: {{error}}"
"mode_import_failed": "Ha fallat la importació del mode: {{error}}",
"openaiCompatible": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new 'openaiCompatible' translation block has been added with English text. For proper localization, non‐English locales should contain appropriate translations rather than English fallback text (e.g. for Chinese users, ensure that zh‑CN/zh‑TW contain proper Chinese error messages). This issue appears consistently across all affected locale files.

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 11, 2025
@daniel-lxs
Copy link
Member

Not an issue

@daniel-lxs daniel-lxs closed this Aug 13, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 13, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

roo code使用问题

4 participants