Dalle3 request in Next.js 14 server actions leading to FUNCTION_INVOCATION_TIMEOUT on vercel

44 Views Asked by At

I am hosting my next 14 app on Vercel. My app generates images using the dalle3 api and stores them into a firebase firestore. It all works correctly on my dev server but gets a FUNCTION_INVOCATION_TIMEOUT on my vercel-hosted production app.

Let me first explain more what I am trying to do. Upon a button click, a user can create a movie character with some info they specify. This all gets put into a firebase DB. A picture is then automatically generated for that character using Dalle. Here is some basic code to demonstrate that onClick handler:

async function handleCreateCharacter() {
    await addNewCharacterToFirestore(movieId, newCharacterInfo);
    // generate picture in background - since dalle takes ~15 seconds to generate image
    generatePictureForCharacter(movieId, newCharacterInfo);
  }

I generate the picture using dalle in the background instead of awaiting it since it takes a while and I want the user to be able to view other parts of the website while the character is being generated. generatePictureForCharacter is a function defined in a file with the "use server" directive since open AI only allows you to use its api on the server. generatePictureForCharacter simply creates the image and then updates the firestore document for that character with the generated image.

I've tried to move this generatePictureForCharacter logic into an api POST route at /api/generate_character_image/route.ts that uses the edge runtime to try to get around the FUNCTION_INVOCATION_TIMEOUT, but the problem is that the firebase sdk uses some require statements which the edge runtime can't handle. So, I tried to then make an /api/generate_image/route.ts api POST route in which I only generate the image and return it in the response and fetch that inside my original generatePictureForCharacter server action method, but then I got a Error: An error occurred in the Server Components render but no message was provided

0

There are 0 best solutions below