From 595f24857a0e0362b000f5ed440bca90301e6e70 Mon Sep 17 00:00:00 2001 From: Dayuan Jiang <34411969+DayuanJiang@users.noreply.github.com> Date: Wed, 3 Dec 2025 19:49:58 +0900 Subject: [PATCH] fix: show user-friendly error when model doesn't support images (#55) When models like DeepSeek (deepseek-chat, deepseek-reasoner) receive image inputs, they return a cryptic error about 'unknown variant image_url'. This change detects such errors and shows a clear message asking users to remove the image or switch to a vision-capable model. Fixes #42 --- app/api/chat/route.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index ecb3962..fcc36db 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -331,15 +331,20 @@ IMPORTANT: Keep edits concise: return 'unknown error'; } - if (typeof error === 'string') { - return error; + const errorString = typeof error === 'string' + ? error + : error instanceof Error + ? error.message + : JSON.stringify(error); + + // Check for image not supported error (e.g., DeepSeek models) + if (errorString.includes('image_url') || + errorString.includes('unknown variant') || + (errorString.includes('image') && errorString.includes('not supported'))) { + return 'This model does not support image inputs. Please remove the image and try again, or switch to a vision-capable model.'; } - if (error instanceof Error) { - return error.message; - } - - return JSON.stringify(error); + return errorString; } return result.toUIMessageStreamResponse({