🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: refine ProviderBizError classification for insufficient balance and quota limit (#13740)
Arvin Xu2c79b5ab78ce
diff --git a/locales/en-US/error.json b/locales/en-US/error.jsonindex 289a18699cc..3f93bdef457 100644--- a/locales/en-US/error.json+++ b/locales/en-US/error.json@@ -60,6 +60,7 @@"response.520": "We apologize, the server encountered an unexpected issue that prevented it from completing your request. Please try again later; we are working to resolve this issue.","response.522": "We apologize, the server connection timed out and was unable to respond to your request in a timely manner. This may be due to an unstable network or the server being temporarily inaccessible. Please try again later; we are working to restore service.","response.524": "We apologize, the server timed out while waiting for a response, possibly due to a slow reply. Please try again later.",+ "response.AccountDeactivated": "Your account has been deactivated or suspended. This may be due to policy, security, or account review reasons. Please contact the provider support for assistance.","response.AgentRuntimeError": "Lobe language model runtime execution error. Please troubleshoot or retry based on the following information.","response.ComfyUIBizError": "An error occurred while requesting the ComfyUI service. Please troubleshoot using the information below or try again.","response.ComfyUIEmptyResult": "No image was generated by ComfyUI. Please check the model configuration or try again.",diff --git a/locales/zh-CN/error.json b/locales/zh-CN/error.jsonindex b2b4b3d91e7..61627976f89 100644--- a/locales/zh-CN/error.json+++ b/locales/zh-CN/error.json@@ -60,6 +60,7 @@"response.520": "服务遇到意外问题,暂时无法完成请求,请稍后再试","response.522": "连接超时(可能网络不稳定或服务暂不可达),请稍后再试","response.524": "等待上游响应超时,请稍后再试",+ "response.AccountDeactivated": "你的账户已被停用或暂停。这可能是由于政策、安全或账户审查原因。请联系服务商支持获取帮助。","response.AgentRuntimeError": "助理运行时出错。请根据以下信息排查或重试","response.ComfyUIBizError": "ComfyUI 服务返回错误。请根据以下信息排查或重试","response.ComfyUIEmptyResult": "ComfyUI 未生成结果。请检查模型/工作流配置后重试",diff --git a/packages/model-runtime/src/core/anthropicCompatibleFactory/index.ts b/packages/model-runtime/src/core/anthropicCompatibleFactory/index.tsindex e62cf6ee82d..6aab4bf176b 100644--- a/packages/model-runtime/src/core/anthropicCompatibleFactory/index.ts+++ b/packages/model-runtime/src/core/anthropicCompatibleFactory/index.ts@@ -19,6 +19,7 @@ import { AgentRuntimeError } from '../../utils/createError';import { debugStream } from '../../utils/debugStream';import { desensitizeUrl } from '../../utils/desensitizeUrl';import { getModelPricing } from '../../utils/getModelPricing';+import { isAccountDeactivatedError } from '../../utils/isAccountDeactivatedError';import { isExceededContextWindowError } from '../../utils/isExceededContextWindowError';import { isQuotaLimitError } from '../../utils/isQuotaLimitError';import { MODEL_LIST_CONFIGS, processModelList } from '../../utils/modelParse';@@ -294,6 +295,16 @@ export const handleDefaultAnthropicError = <T extends Record<string, any> = any>const { errorResult, message } = handleAnthropicError(error);const errorMsg = errorResult.message || errorResult.error?.message;++ if (isAccountDeactivatedError(errorMsg)) {+ return {+ endpoint: desensitizedEndpoint,+ error: errorResult,+ errorType: AgentRuntimeErrorType.AccountDeactivated,+ message,+ };+ }+if (isExceededContextWindowError(errorMsg)) {return {endpoint: desensitizedEndpoint,@@ -682,6 +693,17 @@ export const createAnthropicCompatibleRuntime = <T extends Record<string, any> =const { errorResult, message } = handleAnthropicError(error);const errorMsg = errorResult.message || errorResult.error?.message;++ if (isAccountDeactivatedError(errorMsg)) {+ return AgentRuntimeError.chat({+ endpoint: desensitizedEndpoint,+ error: errorResult,+ errorType: AgentRuntimeErrorType.AccountDeactivated,+ message,+ provider: this.id,+ });+ }+if (isExceededContextWindowError(errorMsg)) {return AgentRuntimeError.chat({endpoint: desensitizedEndpoint,diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/index.tsindex 99147ea0c6c..3c9997ceafd 100644--- a/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts+++ b/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts@@ -39,7 +39,9 @@ import { desensitizeUrl } from '../../utils/desensitizeUrl';import { getModelPropertyWithFallback } from '../../utils/getFallbackModelProperty';import { getModelPricing } from '../../utils/getModelPricing';import { handleOpenAIError } from '../../utils/handleOpenAIError';+import { isAccountDeactivatedError } from '../../utils/isAccountDeactivatedError';import { isExceededContextWindowError } from '../../utils/isExceededContextWindowError';+import { isInsufficientQuotaError } from '../../utils/isInsufficientQuotaError';import { isQuotaLimitError } from '../../utils/isQuotaLimitError';import { postProcessModelList } from '../../utils/postProcessModelList';import { StreamingResponse } from '../../utils/response';@@ -965,19 +967,6 @@ export const createOpenAICompatibleRuntime = <T extends Record<string, any> = anlog('error code: %s, message: %s', errorResult.code, errorResult.message);- // Check for "Insufficient Balance" in error message- const errorMessage = errorResult.error?.message || errorResult.message;- if (errorMessage?.includes('Insufficient Balance')) {- log('insufficient balance error detected in message');- return AgentRuntimeError.chat({- endpoint: desensitizedEndpoint,- error: errorResult,- errorType: AgentRuntimeErrorType.InsufficientQuota,- message,- provider: this.id,- });- }-switch (errorResult.code) {case 'insufficient_quota': {log('insufficient quota error');@@ -1016,6 +1005,29 @@ export const createOpenAICompatibleRuntime = <T extends Record<string, any> = an}const errorMsg = errorResult.error?.message || errorResult.message;++ if (isAccountDeactivatedError(errorMsg)) {+ log('account deactivated error detected from message');+ return AgentRuntimeError.chat({+ endpoint: desensitizedEndpoint,+ error: errorResult,+ errorType: AgentRuntimeErrorType.AccountDeactivated,+ message,+ provider: this.id,+ });+ }++ if (isInsufficientQuotaError(errorMsg)) {+ log('insufficient quota error detected from message');+ return AgentRuntimeError.chat({+ endpoint: desensitizedEndpoint,+ error: errorResult,+ errorType: AgentRuntimeErrorType.InsufficientQuota,+ message,+ provider: this.id,+ });+ }+if (isExceededContextWindowError(errorMsg)) {log('context length exceeded detected from message');return AgentRuntimeError.chat({diff --git a/packages/model-runtime/src/utils/isAccountDeactivatedError.test.ts b/packages/model-runtime/src/utils/isAccountDeactivatedError.test.tsnew file mode 100644index 00000000000..ab2a2bc0b6d--- /dev/null+++ b/packages/model-runtime/src/utils/isAccountDeactivatedError.test.ts@@ -0,0 +1,49 @@+import { describe, expect, it } from 'vitest';++import { isAccountDeactivatedError } from './isAccountDeactivatedError';++describe('isAccountDeactivatedError', () => {+ it('should return false for undefined/empty input', () => {+ expect(isAccountDeactivatedError(undefined)).toBe(false);+ expect(isAccountDeactivatedError('')).toBe(false);+ });++ it('should detect "account has been deactivated" errors', () => {+ expect(+ isAccountDeactivatedError('Your account has been deactivated, please contact support'),+ ).toBe(true);+ });++ it('should detect "account has been suspended" errors', () => {+ expect(+ isAccountDeactivatedError('Your account has been suspended due to policy violation'),+ ).toBe(true);+ });++ it('should detect "account has been disabled" errors', () => {+ expect(isAccountDeactivatedError('This account has been disabled')).toBe(true);+ });++ it('should detect "account is disabled" errors', () => {+ expect(isAccountDeactivatedError('Your account is disabled')).toBe(true);+ });++ it('should be case-insensitive', () => {+ expect(isAccountDeactivatedError('ACCOUNT HAS BEEN DEACTIVATED')).toBe(true);+ expect(isAccountDeactivatedError('Account Has Been Suspended')).toBe(true);+ });++ it('should return false for unrelated error messages', () => {+ expect(isAccountDeactivatedError('Insufficient Balance')).toBe(false);+ expect(isAccountDeactivatedError('Invalid API key')).toBe(false);+ expect(isAccountDeactivatedError('Rate limit reached')).toBe(false);+ });++ it('should NOT match billing-related account suspensions', () => {+ expect(+ isAccountDeactivatedError(+ 'Your account is suspended due to insufficient balance, please recharge',+ ),+ ).toBe(false);+ });+});diff --git a/packages/model-runtime/src/utils/isAccountDeactivatedError.ts b/packages/model-runtime/src/utils/isAccountDeactivatedError.tsnew file mode 100644index 00000000000..ae8c8f1c9c2--- /dev/null+++ b/packages/model-runtime/src/utils/isAccountDeactivatedError.ts@@ -0,0 +1,12 @@+const ACCOUNT_DEACTIVATED_PATTERNS = [+ 'account has been deactivated', // OpenAI+ 'account has been suspended', // generic+ 'account has been disabled', // generic+ 'account is disabled', // generic+];++export const isAccountDeactivatedError = (message?: string): boolean => {+ if (!message) return false;+ const lower = message.toLowerCase();+ return ACCOUNT_DEACTIVATED_PATTERNS.some((p) => lower.includes(p));+};diff --git a/packages/model-runtime/src/utils/isInsufficientQuotaError.test.ts b/packages/model-runtime/src/utils/isInsufficientQuotaError.test.tsnew file mode 100644index 00000000000..eb0facb77a0--- /dev/null+++ b/packages/model-runtime/src/utils/isInsufficientQuotaError.test.ts@@ -0,0 +1,65 @@+import { describe, expect, it } from 'vitest';++import { isInsufficientQuotaError } from './isInsufficientQuotaError';++describe('isInsufficientQuotaError', () => {+ it('should return false for undefined/empty input', () => {+ expect(isInsufficientQuotaError(undefined)).toBe(false);+ expect(isInsufficientQuotaError('')).toBe(false);+ });++ it('should detect Moonshot "insufficient balance" errors', () => {+ expect(+ isInsufficientQuotaError(+ 'Your account org-d4cffdc846304e378e12254ef3c9cb16 <ak-f8fmexq3k3wi11gm63d1> is suspended due to insufficient balance, please recharge your account or check your plan and billing details',+ ),+ ).toBe(true);+ });++ it('should detect generic "Insufficient Balance" errors', () => {+ expect(isInsufficientQuotaError('Insufficient Balance: Your account balance is too low')).toBe(+ true,+ );+ });++ it('should detect "insufficient quota" errors', () => {+ expect(isInsufficientQuotaError('You have insufficient quota for this request')).toBe(true);+ });++ it('should detect "balance is not enough" errors', () => {+ expect(isInsufficientQuotaError('Your balance is not enough to complete this request')).toBe(+ true,+ );+ });++ it('should detect OpenAI "billing hard limit" errors', () => {+ expect(isInsufficientQuotaError('Billing hard limit has been reached')).toBe(true);+ });++ it('should NOT detect account deactivation as quota error', () => {+ expect(+ isInsufficientQuotaError('Your account has been deactivated, please contact support'),+ ).toBe(false);+ });++ it('should detect "exceeded your current quota" errors', () => {+ expect(+ isInsufficientQuotaError(+ 'You exceeded your current quota, please check your plan and billing details',+ ),+ ).toBe(true);+ });++ it('should be case-insensitive', () => {+ expect(isInsufficientQuotaError('INSUFFICIENT BALANCE')).toBe(true);+ expect(isInsufficientQuotaError('Insufficient Quota')).toBe(true);+ expect(isInsufficientQuotaError('BILLING HARD LIMIT HAS BEEN REACHED')).toBe(true);+ });++ it('should return false for unrelated error messages', () => {+ expect(isInsufficientQuotaError('Invalid API key')).toBe(false);+ expect(isInsufficientQuotaError('Context length exceeded')).toBe(false);+ expect(isInsufficientQuotaError('Too many requests')).toBe(false);+ expect(isInsufficientQuotaError('Rate limit reached')).toBe(false);+ });+});diff --git a/packages/model-runtime/src/utils/isInsufficientQuotaError.ts b/packages/model-runtime/src/utils/isInsufficientQuotaError.tsnew file mode 100644index 00000000000..4ae71dd9033--- /dev/null+++ b/packages/model-runtime/src/utils/isInsufficientQuotaError.ts@@ -0,0 +1,14 @@+const INSUFFICIENT_QUOTA_PATTERNS = [+ 'insufficient balance', // Moonshot / generic+ 'insufficient quota', // OpenAI+ 'account is suspended due to insufficient balance', // Moonshot+ 'balance is not enough', // generic+ 'billing hard limit has been reached', // OpenAI+ 'exceeded your current quota', // OpenAI+];++export const isInsufficientQuotaError = (message?: string): boolean => {+ if (!message) return false;+ const lower = message.toLowerCase();+ return INSUFFICIENT_QUOTA_PATTERNS.some((p) => lower.includes(p));+};diff --git a/packages/model-runtime/src/utils/isQuotaLimitError.ts b/packages/model-runtime/src/utils/isQuotaLimitError.tsindex d883b27fb97..deb5542d534 100644--- a/packages/model-runtime/src/utils/isQuotaLimitError.ts+++ b/packages/model-runtime/src/utils/isQuotaLimitError.ts@@ -5,6 +5,7 @@ const QUOTA_LIMIT_PATTERNS = ['rate_limit_exceeded', // OpenAI (code in message)'quota exceeded', // generic'too many requests', // generic+ 'too many tokens', // Moonshot / generic (e.g. "Too many tokens per day")];export const isQuotaLimitError = (message?: string): boolean => {diff --git a/packages/types/src/agentRuntime.ts b/packages/types/src/agentRuntime.tsindex ff00da706bf..a45c049d264 100644--- a/packages/types/src/agentRuntime.ts+++ b/packages/types/src/agentRuntime.ts@@ -15,6 +15,7 @@ export const AgentRuntimeErrorType = {AgentRuntimeError: 'AgentRuntimeError', // Agent Runtime module runtime errorLocationNotSupportError: 'LocationNotSupportError',+ AccountDeactivated: 'AccountDeactivated',QuotaLimitReached: 'QuotaLimitReached',InsufficientQuota: 'InsufficientQuota',diff --git a/src/features/Conversation/Error/index.tsx b/src/features/Conversation/Error/index.tsxindex 3f7cbc4d0cd..b9857e7872b 100644--- a/src/features/Conversation/Error/index.tsx+++ b/src/features/Conversation/Error/index.tsx@@ -61,6 +61,7 @@ const getErrorAlertConfig = (switch (errorType) {case ChatErrorType.SystemTimeNotMatchError:+ case AgentRuntimeErrorType.AccountDeactivated:case AgentRuntimeErrorType.PermissionDenied:case AgentRuntimeErrorType.InsufficientQuota:case AgentRuntimeErrorType.ModelNotFound:diff --git a/src/locales/default/error.ts b/src/locales/default/error.tsindex b3e59c6e88e..6d237ecec14 100644--- a/src/locales/default/error.ts+++ b/src/locales/default/error.ts@@ -114,6 +114,8 @@ export default {'unknownError.retry': 'Retry','unknownError.title': 'Oops, the request took a nap',+ 'response.AccountDeactivated':+ 'Your account has been deactivated or suspended. This may be due to policy, security, or account review reasons. Please contact the provider support for assistance.','response.ExceededContextWindow':'The current request content exceeds the length that the model can handle. Please reduce the amount of content and try again.','response.ExceededContextWindowCloud':diff --git a/src/server/modules/AgentRuntime/llmErrorClassification.ts b/src/server/modules/AgentRuntime/llmErrorClassification.tsindex 88ffe718441..828df331df6 100644--- a/src/server/modules/AgentRuntime/llmErrorClassification.ts+++ b/src/server/modules/AgentRuntime/llmErrorClassification.ts@@ -21,6 +21,7 @@ const RETRY_ERROR_TYPES = new Set(['StreamChunkError',]);const STOP_ERROR_TYPES = new Set([+ 'AccountDeactivated','ExceededContextWindow','InsufficientQuota','InvalidBedrockCredentials',diff --git a/src/utils/errorResponse.ts b/src/utils/errorResponse.tsindex 8ee7e3e597f..cc3cae18ba2 100644--- a/src/utils/errorResponse.ts+++ b/src/utils/errorResponse.ts@@ -42,6 +42,10 @@ const getStatus = (errorType: ILobeAgentRuntimeErrorType | ErrorType) => {return 404;}+ case AgentRuntimeErrorType.AccountDeactivated: {+ return 403;+ }+case AgentRuntimeErrorType.InsufficientQuota:case AgentRuntimeErrorType.QuotaLimitReached: {return 429;