From f1926d152ee6ba06d528a011ed335b84165019ee Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 22 May 2026 11:07:07 +0000 Subject: [PATCH] fix: avoid credit charges when Anthropic is unconfigured Co-authored-by: Cole Collins --- app/api/app-idea-chat/route.ts | 7 +++++++ app/api/pattern-analyzer/route.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/api/app-idea-chat/route.ts b/app/api/app-idea-chat/route.ts index d9b28da..1b54694 100644 --- a/app/api/app-idea-chat/route.ts +++ b/app/api/app-idea-chat/route.ts @@ -61,6 +61,13 @@ export async function POST(request: NextRequest) { return NextResponse.json({ error: 'Message is required' }, { status: 400 }) } + if (!process.env.ANTHROPIC_API_KEY) { + return NextResponse.json( + { error: 'App Idea Chat is not configured. Missing ANTHROPIC_API_KEY.' }, + { status: 503 }, + ) + } + const creditResult = await deductCredits( user.id, CREDITS.PATTERN_ANALYZER_COST, diff --git a/app/api/pattern-analyzer/route.ts b/app/api/pattern-analyzer/route.ts index 5100fce..c4a1799 100644 --- a/app/api/pattern-analyzer/route.ts +++ b/app/api/pattern-analyzer/route.ts @@ -54,6 +54,13 @@ export async function POST(request: NextRequest) { return NextResponse.json({ error: 'analysisId is required' }, { status: 400 }) } + if (!process.env.ANTHROPIC_API_KEY) { + return NextResponse.json( + { error: 'Pattern Analyzer is not configured. Missing ANTHROPIC_API_KEY.' }, + { status: 503 }, + ) + } + const creditResult = await deductCredits(user.id, CREDITS.PATTERN_ANALYZER_COST, 'pattern_analyzer', { analysisId }) if (!creditResult.success) { return NextResponse.json({ error: creditResult.error || 'Insufficient credits' }, { status: 402 })