From 5c7cf54d67456666399e3a1f5f1eda47c71c2a75 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Fri, 30 Jan 2026 20:51:24 +0000 Subject: [PATCH] fix: add user-friendly error handling for prompt length exceeded errors Previously, when users exceeded the 200k token limit, they received a generic 400/413 error message that didn't clearly explain the issue. This commit adds specific error handling in the Quilly component to: - Detect prompt length errors from API responses (400/413 status codes with 'prompt is too long' message) - Display clear, actionable error messages to users - Offer two solutions: start a new chat or switch to a model with a larger context window The error handling covers two cases: 1. Specific prompt length errors with message content check 2. Generic 413 (Payload Too Large) status codes This improves UX by helping users understand why their request failed and providing clear next steps to resolve the issue. --- src/components/Quilly.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index cad55379..2a06cc1f 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -146,6 +146,21 @@ function QuillyContent({ error, onDismiss, onNewChat, onOpenModelSelector, onTry }], }; + // Check for prompt length errors (413 or 400 with specific message) + case (error.status === 413 || error.status === 400) && + (error.message?.toLowerCase().includes('prompt is too long') || + error.message?.toLowerCase().includes('prompt') && error.message?.toLowerCase().includes('too long')): + return { + message: 'Your conversation has grown too long for this model. Try starting a new chat or switching to a model with a larger context window.', + actions: [{ + label: 'New chat', + onClick: onNewChat, + }, { + label: 'Change model', + onClick: onOpenModelSelector, + }], + }; + case error.status === 403: return { message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo:`, @@ -158,6 +173,18 @@ function QuillyContent({ error, onDismiss, onNewChat, onOpenModelSelector, onTry }], }; + case error.status === 413: + return { + message: 'Your request is too large for the AI provider. Try starting a new chat to reduce the conversation size.', + actions: [{ + label: 'New chat', + onClick: onNewChat, + }, { + label: 'Change model', + onClick: onOpenModelSelector, + }], + }; + case error.status === 400: return { message: 'The AI provider did not understand the message / data it got. If it persists, try stating a new conversation or using a different model.',