-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: improve OpenAI Compatible rate limit error handling for Chinese users #6929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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
- Added English fallback translations for all supported languages - Ensures translation check CI passes - Maintains consistency across all language files
| } | ||
| } | ||
| } | ||
| } catch (error: any) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this 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}}" |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
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.
|
Not an issue |
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
BaseOpenAiCompatibleProviderChanges
src/api/providers/base-openai-compatible-provider.tsto catch and handle rate limit errors specificallysrc/i18n/locales/en/common.jsonfor OpenAI Compatible errorssrc/i18n/locales/zh-CN/common.jsonTesting
turbo lint)turbo check-types)Related Issues
Fixes #6928
Screenshots
The new error messages will appear as:
Important
Improves error handling for rate limit issues in OpenAI Compatible providers with localized messages for Chinese users.
BaseOpenAiCompatibleProvider.base-openai-compatible-provider.tsto handle rate limit errors.en/common.jsonandzh-CN/common.jsonfor OpenAI Compatible errors.This description was created by
for 996a994. You can customize this summary. It will automatically update as commits are pushed.