Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix: classify Zhipu "Prompt exceeds max length" 400 as context_too_large (#873) (#893)

Ben Younes15a73e2e4c2d
diff --git a/server/src/__tests__/lib/exhaustion-statuses.test.ts b/server/src/__tests__/lib/exhaustion-statuses.test.ts
index 8f621927..5dc45820 100644
--- a/server/src/__tests__/lib/exhaustion-statuses.test.ts
+++ b/server/src/__tests__/lib/exhaustion-statuses.test.ts
@@ -96,6 +96,21 @@ describe('isContextTooLargeError', () => {
expect(isContextTooLargeError(new Error('request exceeds the maximum number of tokens'))).toBe(true);
});
+ it('flags Zhipu AI prompt-length 400s (error 1261: "Prompt exceeds max length")', () => {
+ // #873: Zhipu returns HTTP 400 with "Prompt exceeds max length" for an
+ // over-long context. Its wording matches none of the OpenAI/Anthropic/Google
+ // markers, so it was mis-bucketed as provider_bad_request instead of
+ // context_too_large.
+ expect(isContextTooLargeError(Object.assign(
+ new Error('Zhipu API error 400: Prompt exceeds max length. Please shorten the prompt or set a longer context length.'),
+ { status: 400 },
+ ))).toBe(true);
+ expect(classifyAttemptError(Object.assign(
+ new Error('Zhipu API error 400: Prompt exceeds max length.'),
+ { status: 400 },
+ ))).toBe('context_too_large');
+ });
+
it('flags literal HTTP 413s, including Groq TPM-ceiling 413s (Requested > Limit can never fit)', () => {
expect(isContextTooLargeError(Object.assign(
new Error('Groq API error 413: Request too large for model `llama-3.3-70b-versatile` in organization `org_x` on tokens per minute (TPM): Limit 30000, Requested 33476'),
diff --git a/server/src/lib/error-classify.ts b/server/src/lib/error-classify.ts
index 2d2df22a..d1a9cdd6 100644
--- a/server/src/lib/error-classify.ts
+++ b/server/src/lib/error-classify.ts
@@ -374,6 +374,10 @@ export function isContextTooLargeError(err: any): boolean {
|| msg.includes('request entity too large')
|| msg.includes('request body too large')
|| msg.includes('content too large')
+ // Zhipu AI (bigmodel.cn) 400, error code 1261: "Prompt exceeds max length"
+ // (#873). Its wording matches none of the markers above, so without this it
+ // was mis-bucketed as provider_bad_request instead of context_too_large.
+ || msg.includes('exceeds max length')
|| msg.includes('api error 413');
}