๐คฏ 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(router): fallback on per-channel image count limit errors (#19959)
YuTengjing5c9ff499cefe
diff --git a/locales/en-US/modelRuntime.json b/locales/en-US/modelRuntime.jsonindex abf32e54a30..e5b7f03cc75 100644--- a/locales/en-US/modelRuntime.json+++ b/locales/en-US/modelRuntime.json@@ -14,6 +14,7 @@"ConversationParentMissing": "The conversation context for this message could not be found. Reopen the conversation or start a new topic, then send the request again.","DatabasePersistError": "A database operation failed while saving or loading this conversation. Please try again; if it persists, contact support.","ExceededContextWindow": "The current request content exceeds the length that the model can handle. Please reduce the amount of content and try again.",+ "ExceededImageLimit": "This conversation contains more images than the model provider allows in one request. Start a new topic or remove some images, then try again.","ExceededToolLimit": "This run reached its tool-call limit. Break the task into smaller steps, or ask the agent owner to adjust the tool-call limit.","HarnessJsonParseError": "An internal payload could not be read back, so this operation stopped. Retrying the same request will hit the same failure โ please start a new message; if it persists, contact support.","InsufficientQuota": "Sorry, the quota for this key has been reached. Please check if your account balance is sufficient or try again after increasing the key's quota.",diff --git a/locales/zh-CN/modelRuntime.json b/locales/zh-CN/modelRuntime.jsonindex dc94129458c..ce00e9c5f32 100644--- a/locales/zh-CN/modelRuntime.json+++ b/locales/zh-CN/modelRuntime.json@@ -14,6 +14,7 @@"ConversationParentMissing": "ๆพไธๅฐ่ฟๆกๆถๆฏๅฏนๅบ็ไผ่ฏไธไธๆใ่ฏท้ๆฐๆๅผๅฏน่ฏๆๆฐๅปบ่ฏ้ข๏ผๅๆฌกๅ้่ฏทๆฑใ","DatabasePersistError": "ไฟๅญๆๅ ่ฝฝๆญคๅฏน่ฏๆถๆฐๆฎๅบๆไฝๅคฑ่ดฅใ่ฏท้่ฏ๏ผๅฆๆ้ฎ้ขไป็ถๅญๅจ๏ผ่ฏท่็ณปๆฏๆใ","ExceededContextWindow": "ๅฝๅ่ฏทๆฑๅ ๅฎน่ถ ๅบไบๆจกๅๅฏๅค็็้ฟๅบฆใ่ฏทๅๅฐๅ ๅฎน้ๅนถ้่ฏใ",+ "ExceededImageLimit": "ๅฝๅๅฏน่ฏไธญ็ๅพ็ๆฐ้่ถ ่ฟไบๆจกๅๆไพๅๅๆฌก่ฏทๆฑๅ ่ฎธ็ไธ้ใ่ฏทๆฐๅปบ่ฏ้ขๆๅ ้ค้จๅๅพ็ๅ้่ฏใ","ExceededToolLimit": "ๆฌๆฌกไปปๅกๅทฒ่พพๅฐๅทฅๅ ท่ฐ็จๆฌกๆฐไธ้ใ่ฏทๅฐไปปๅกๆๅๆ่พๅฐๆญฅ้ชค๏ผๆ่็ณป Agent ็ฎก็ๅ่ฐๆด่ฐ็จๆฌกๆฐไธ้ใ","HarnessJsonParseError": "ๅ ้จๆฐๆฎๅ่ฏปๅคฑ่ดฅ๏ผๆฌๆฌกๆไฝๅทฒไธญๆญขใ้่ฏๅไธ่ฏทๆฑไผ้ๅฐๅๆ ท็ๅคฑ่ดฅ๏ผ่ฏท้ๆฐๅ่ตทไธๆกๆถๆฏ๏ผๅฆๆ้ฎ้ขไป็ถๅญๅจ๏ผ่ฏท่็ณปๆฏๆใ","InsufficientQuota": "ๆฑๆญ๏ผๆญคๅฏ้ฅ็้ ้ขๅทฒ็จๅฐฝใ่ฏทๆฃๆฅๆจ็่ดฆๆทไฝ้ขๆฏๅฆๅ ่ถณๆๅจๅขๅ ๅฏ้ฅ้ ้ขๅ้่ฏใ",diff --git a/packages/locales/src/default/modelRuntime.ts b/packages/locales/src/default/modelRuntime.tsindex 6ddc9b6eb60..74bb97a8ab1 100644--- a/packages/locales/src/default/modelRuntime.ts+++ b/packages/locales/src/default/modelRuntime.ts@@ -28,6 +28,8 @@ export default {'A database operation failed while saving or loading this conversation. Please try again; if it persists, contact support.','ExceededContextWindow':'The current request content exceeds the length that the model can handle. Please reduce the amount of content and try again.',+ 'ExceededImageLimit':+ 'This conversation contains more images than the model provider allows in one request. Start a new topic or remove some images, then try again.','ExceededToolLimit':'This run reached its tool-call limit. Break the task into smaller steps, or ask the agent owner to adjust the tool-call limit.','HarnessJsonParseError':diff --git a/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts b/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.tsindex 24748a56d0c..9239121da4d 100644--- a/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts+++ b/packages/model-runtime/src/core/RouterRuntime/createRuntime.test.ts@@ -1630,7 +1630,28 @@ describe('createRouterRuntime', () => {expect(attemptedKeys).toEqual(['key-1', 'key-2']);});- it('should fallback after a structured remote media download timeout', async () => {+ it.each([+ {+ case: 'a structured remote media download timeout',+ error: {+ code: 'invalid_value',+ message: 'Unable to download content from the provided URL before the timeout.',+ param: 'url',+ type: 'invalid_request_error',+ },+ errorType: AgentRuntimeErrorType.RemoteMediaDownloadTimeout,+ },+ {+ case: 'a per-channel image count limit',+ error: {+ code: null,+ message: 'Exceeded maximum number of images (50) allowed in the request.',+ param: 'input',+ type: 'invalid_request_error',+ },+ errorType: AgentRuntimeErrorType.ExceededImageLimit,+ },+ ])('should fallback after $case', async ({ error, errorType }) => {const attemptedKeys: string[] = [];class RemoteMediaRuntime implements LobeRuntimeAI {@@ -1644,17 +1665,7 @@ describe('createRouterRuntime', () => {attemptedKeys.push(this.apiKey);if (this.apiKey === 'key-1') {- throw {- error: {- code: 'invalid_value',- message: 'Unable to download content from the provided URL before the timeout.',- param: 'url',- type: 'invalid_request_error',- },- errorType: AgentRuntimeErrorType.RemoteMediaDownloadTimeout,- provider: 'azure',- status: 400,- };+ throw { error, errorType, provider: 'azure', status: 400 };}return 'success';diff --git a/packages/model-runtime/src/errors/match.test.ts b/packages/model-runtime/src/errors/match.test.tsindex bae041e1211..5eb07f864b4 100644--- a/packages/model-runtime/src/errors/match.test.ts+++ b/packages/model-runtime/src/errors/match.test.ts@@ -351,6 +351,18 @@ describe('matchErrorPattern โ second residue convergence round', () => {'Unable to download content from the provided URL before the timeout.',AgentRuntimeErrorType.RemoteMediaDownloadTimeout,],+ [+ 'Exceeded maximum number of images (50) allowed in the request.',+ AgentRuntimeErrorType.ExceededImageLimit,+ ],+ [+ 'Too many images in request: 51, maximum allowed: 50.',+ AgentRuntimeErrorType.ExceededImageLimit,+ ],+ [+ 'Exceeded maximum number of images (100) allowed in the request.',+ AgentRuntimeErrorType.ExceededImageLimit,+ ],['404 page not found', AgentRuntimeErrorType.UserConfigError],['{"errors":[{"code":7003,"message":"No route for that URI"}]}',diff --git a/packages/model-runtime/src/errors/patterns.ts b/packages/model-runtime/src/errors/patterns.tsindex ef2fbbebdd6..fefce7dfc08 100644--- a/packages/model-runtime/src/errors/patterns.ts+++ b/packages/model-runtime/src/errors/patterns.ts@@ -1226,6 +1226,22 @@ export const ERROR_PATTERNS: ErrorPattern[] = [match: sub('413 Request Entity Too Large', { caseInsensitive: true }),},+ // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+ // ExceededImageLimit โ per-request image count limit of a channel.+ // Match only the fixed wording, never the count: the cap differs by model+ // and has changed over time, so the number in the message is not stable.+ // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+ {+ code: AgentRuntimeErrorType.ExceededImageLimit,+ match: sub('Exceeded maximum number of images', { caseInsensitive: true }),+ note: 'Azure OpenAI Responses API: "Exceeded maximum number of images (<limit>) allowed in the request."',+ },+ {+ code: AgentRuntimeErrorType.ExceededImageLimit,+ match: sub('Too many images in request', { caseInsensitive: true }),+ note: 'Azure OpenAI Chat Completions: "Too many images in request: <count>, maximum allowed: <limit>."',+ },+// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ// InvalidRequestFormat โ provider rejected as malformed// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdiff --git a/packages/model-runtime/src/errors/specs.ts b/packages/model-runtime/src/errors/specs.tsindex 21a350a6096..b51aeaa8b72 100644--- a/packages/model-runtime/src/errors/specs.ts+++ b/packages/model-runtime/src/errors/specs.ts@@ -335,6 +335,18 @@ export const ERROR_CODE_SPECS: SpecMap = {countAsFailure: false,description: 'Upstream rejected the serialized request body as too large.',},+ [AgentRuntimeErrorType.ExceededImageLimit]: {+ code: AgentRuntimeErrorType.ExceededImageLimit,+ numericId: 4007,+ category: 'request',+ severity: 'info',+ attribution: 'user',+ httpStatus: 400,+ retryable: false,+ routeFallback: true,+ countAsFailure: false,+ description: 'Upstream rejected the request for exceeding its per-request image count limit.',+ },// โโ Cloud-only (tier 9) โโ[ChatErrorType.LobeHubModelDeprecated]: {code: ChatErrorType.LobeHubModelDeprecated,diff --git a/packages/model-runtime/src/providers/azureOpenai/index.test.ts b/packages/model-runtime/src/providers/azureOpenai/index.test.tsindex 11f5fb93ef9..8600b2d9d92 100644--- a/packages/model-runtime/src/providers/azureOpenai/index.test.ts+++ b/packages/model-runtime/src/providers/azureOpenai/index.test.ts@@ -414,6 +414,29 @@ describe('LobeAzureOpenAI', () => {});});+ it('should classify a Responses API image count limit error for route fallback', async () => {+ const message = 'Exceeded maximum number of images (50) allowed in the request.';+ const apiError = new OpenAI.APIError(+ 400,+ { code: null, message, param: 'input', type: 'invalid_request_error' },+ message,+ new Headers(),+ );++ (instance['client'].responses.create as Mock).mockRejectedValue(apiError);++ await expect(+ instance.chat({+ messages: [{ content: 'Describe these images', role: 'user' }],+ model: 'gpt-5.4-mini',+ temperature: 0,+ }),+ ).rejects.toMatchObject({+ errorType: AgentRuntimeErrorType.ExceededImageLimit,+ provider: 'azure',+ });+ });+it('should return AzureBizError with DeploymentNotFound error', async () => {// Arrangeconst error = {diff --git a/packages/model-runtime/src/utils/routeFallback.test.ts b/packages/model-runtime/src/utils/routeFallback.test.tsindex 54a80695dca..aaf7c812d24 100644--- a/packages/model-runtime/src/utils/routeFallback.test.ts+++ b/packages/model-runtime/src/utils/routeFallback.test.ts@@ -102,6 +102,22 @@ describe('shouldStopFallbackForError', () => {).toBe(false);});+ it('allows fallback for a per-channel image count limit', () => {+ expect(+ shouldStopFallbackForError({+ error: {+ code: null,+ message: 'Exceeded maximum number of images (50) allowed in the request.',+ param: 'input',+ status: 400,+ type: 'invalid_request_error',+ },+ errorType: AgentRuntimeErrorType.ExceededImageLimit,+ provider: 'azure',+ }),+ ).toBe(false);+ });+it('does not infer remote media timeout semantics from raw provider text', () => {expect(shouldStopFallbackForError({diff --git a/packages/types/src/agentRuntime.ts b/packages/types/src/agentRuntime.tsindex e12ce3bc655..d9c886e252c 100644--- a/packages/types/src/agentRuntime.ts+++ b/packages/types/src/agentRuntime.ts@@ -213,6 +213,12 @@ export const AgentRuntimeErrorType = {InvalidRequestFormat: 'InvalidRequestFormat',/** Upstream rejected the serialized request body as too large (HTTP 413). */RequestBodyTooLarge: 'RequestBodyTooLarge',+ /**+ * Upstream rejected the request for carrying more images than the channel allows+ * (e.g. Azure OpenAI caps each request at 50). The limit is per channel, so another+ * route for the same model may still accept the request.+ */+ ExceededImageLimit: 'ExceededImageLimit',/*** Upstream proxy / gateway layer failed (openresty, litellm, HTML 5xx,* Cloudflare 525) โ distinct from the provider's own service. Split out of