export default { async fetch(request) { const cors = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type', }; if (request.method === 'OPTIONS') return new Response(null, { headers: cors }); const body = await request.json(); const r = await fetch( 'https://cooperation-ebony-beyond-informal.trycloudflare.com/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer eim_test_2024_fixed_key', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'ammo-card', messages: [{ role: 'user', content: body.message }], max_tokens: 300, }), } ); const data = await r.json(); return new Response(JSON.stringify(data), { headers: { ...cors, 'Content-Type': 'application/json' }, }); }, };