Vercel Deployment Edge Function error: EDGE_FUNCTION_INVOCATION_FAILED

4.1k Views Asked by At

when I'm trying to POST something to my Edge Function on Vercel Deployment I get the following error:

[POST] /api/openai reason=EDGE_FUNCTION_INVOCATION_FAILED, status=500, user_error=true

TypeError: Illegal invocation at app/api/openai/route.ts:12:36

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();
}
1

There are 1 best solutions below

0
On

This is a known issue that has been fixed in the latest 13.3.x. Workaround can be found here https://github.com/vercel/next.js/issues/46337#issuecomment-1478613133