API call for AI chat completions worked on local but 500 on Cloudflare production

For Workers & Pages, what is the name of the domain?

What is the error number?

500

What is the error message?

Internal Server Error

What is the issue or error you’re encountering

I am having problems with deploying my NextJS app, which is using an API endpoint for chat completions from OpenRouter AI. The API endpoint below worked well on my local, but when I wanted to deploy my app on Cloudflare, the Internal Server Error 500 keeps showing up. ``` // app/api/ai/route.ts import { NextResponse } from “next/server”; // Specify Edge runtime export const runtime = “edge”; export async function POST(req: Request) { try { const { message } = await req.json(); const response = await fetch(“https://openrouter.ai/api/v1/chat/completions”, { method: “POST”, headers: { “Authorization”: Bearer ${process.env.NEXT_PUBLIC_OPENROUTER_API_KEY}, “Content-Type”: “application/json”, }, body: JSON.stringify({ model: “meta-llama/llama-3.3-70b-instruct:free”, messages: [ { role: “user”, content: systemPrompt, // I have a custom prompt here }, ], }), }); if (!re

A post was merged into an existing topic: API endpoint for AI chat completions worked on local but 500 on Cloudflare producti