Skip to content

๐Ÿคฏ 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.

๐Ÿ› 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.json
index 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.json
index 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.ts
index 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.ts
index 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.ts
index 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.ts
index 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.ts
index 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.ts
index 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 () => {
// Arrange
const error = {
diff --git a/packages/model-runtime/src/utils/routeFallback.test.ts b/packages/model-runtime/src/utils/routeFallback.test.ts
index 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.ts
index 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