Every time I attempt to send a POST request to my Edge Function on Vercel Deployment, I encounter the following error message:
[POST] /api/openai reason=EDGE_FUNCTION_INVOCATION_FAILED, status=500, user_error=true
TypeError: Illegal invocation at app/api/openai/route.ts:12:36
This is the content of my Edge Function file:
import { OpenAIStream, OpenAIStreamPayload } from "@/utils/OpenAIStream";
if (!process.env.OPENAI_API_KEY) {
throw new Error("Missing env var from OpenAI");
}
export const config = {
runtime: "edge",
};
export async function POST(request: Request) {
const { prompt } = (await request.json()) as {
prompt?: string;
};
if (!prompt) {
return new Response("No prompt in the request", { status: 400 });
}
//OpenAI logic....
return new Response();
}