2

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();
}
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Floky99
  • 562
  • 2
  • 8
  • 17

1 Answers1

0

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

ChuckJHardy
  • 6,956
  • 6
  • 35
  • 39