Add src/app/api/claude/route.ts

This commit is contained in:
2026-03-11 21:11:38 +00:00
parent 0d1570268c
commit b180a49edc

View File

@@ -0,0 +1,50 @@
import { Anthropic } from '@anthropic-ai/sdk';
import { NextRequest, NextResponse } from 'next/server';
const client = new Anthropic();
export async function POST(request: NextRequest) {
try {
const { message } = await request.json();
if (!message || typeof message !== 'string') {
return NextResponse.json(
{ error: 'Invalid message' },
{ status: 400 }
);
}
const response = await client.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [
{
role: 'user',
content: `You are an expert cold email writer. Generate a professional, compelling cold email based on the following brief: "${message}"
The email should:
- Be concise (100-150 words)
- Have a compelling subject line
- Include a clear call-to-action
- Be personalized and professional
- Avoid being pushy or salesy
Format the response as:
Subject: [subject line]
[email body]`
}
]
});
const email = response.content[0].type === 'text' ? response.content[0].text : '';
return NextResponse.json({ email });
} catch (error) {
console.error('Claude API error:', error);
return NextResponse.json(
{ error: 'Failed to generate email' },
{ status: 500 }
);
}
}