From 466478ccc4a6d42e2bb92cae306214efa16dd34e Mon Sep 17 00:00:00 2001 From: josh <144584931+dancer@users.noreply.github.com> Date: Sun, 21 Sep 2025 13:11:54 +0100 Subject: [PATCH] Revert "fix(auth): show gateway dialog for all authentication errors" (#1230) --- app/(chat)/api/chat/route.ts | 54 +++++------------------------------- components/chat.tsx | 4 +-- 2 files changed, 8 insertions(+), 50 deletions(-) diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index 63827cb..7a62f5a 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -127,23 +127,9 @@ export async function POST(request: Request) { const chat = await getChatById({ id }); if (!chat) { - let title = 'New Chat'; - try { - const generatedTitle = await generateTitleFromUserMessage({ - message, - }); - title = generatedTitle; - } catch (titleError) { - if ( - titleError instanceof Error && - (titleError.message?.includes('AI Gateway authentication failed') || - titleError.message?.includes('No authentication provided') || - titleError.message?.includes('AI Gateway requires a valid credit card')) - ) { - throw titleError; - } - console.warn('Title generation failed, using default:', titleError); - } + const title = await generateTitleFromUserMessage({ + message, + }); await saveChat({ id, @@ -187,22 +173,6 @@ export async function POST(request: Request) { let finalMergedUsage: AppUsage | undefined; - try { - await myProvider.languageModel(selectedChatModel).doGenerate({ - prompt: [{ role: 'user', content: [{ type: 'text', text: 'test' }] }], - maxOutputTokens: 1, - }); - } catch (testError) { - if ( - testError instanceof Error && - (testError.message?.includes('AI Gateway authentication failed') || - testError.message?.includes('No authentication provided') || - testError.message?.includes('AI Gateway requires a valid credit card')) - ) { - throw testError; - } - } - const stream = createUIMessageStream({ execute: ({ writer: dataStream }) => { const result = streamText({ @@ -293,16 +263,7 @@ export async function POST(request: Request) { } } }, - onError: (error) => { - // Check for Vercel AI Gateway authentication errors - if ( - error instanceof Error && - (error.message?.includes('AI Gateway authentication failed') || - error.message?.includes('No authentication provided') || - error.message?.includes('AI Gateway requires a valid credit card')) - ) { - throw error; - } + onError: () => { return 'Oops, an error occurred!'; }, }); @@ -323,13 +284,12 @@ export async function POST(request: Request) { return error.toResponse(); } + // Check for Vercel AI Gateway credit card error if ( error instanceof Error && - (error.message?.includes( + error.message?.includes( 'AI Gateway requires a valid credit card on file to service requests', - ) || - error.message?.includes('AI Gateway authentication failed') || - error.message?.includes('No authentication provided')) + ) ) { return new ChatSDKError('bad_request:activate_gateway').toResponse(); } diff --git a/components/chat.tsx b/components/chat.tsx index 116fc44..b4998ad 100644 --- a/components/chat.tsx +++ b/components/chat.tsx @@ -110,9 +110,7 @@ export function Chat({ if (error instanceof ChatSDKError) { // Check if it's a credit card error if ( - error.message?.includes('AI Gateway requires a valid credit card') || - error.message?.includes('AI Gateway authentication failed') || - error.message?.includes('No authentication provided') + error.message?.includes('AI Gateway requires a valid credit card') ) { setShowCreditCardAlert(true); } else {