module.exports = async function handler(req, res) { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); if (req.method === 'OPTIONS') { return res.status(200).end(); } if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }); } const apiKey = process.env.ANTHROPIC_API_KEY; if (!apiKey) { return res.status(500).json({ error: 'API key not configured' }); } try { const response = await fetch('https://api.anthropic.com/v1/messages', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, 'anthropic-version': '2023-06-01', }, body: JSON.stringify(req.body), }); const data = await response.json(); return res.status(response.status).json(data); } catch (error) { return res.status(500).json({ error: 'Failed to reach Anthropic API', details: error.message }); } };