Search code examples
typescriptnext.jsserverlessvercel

MaxDuration 5 minutes is not working | Serverless | Pro Plan | 504 ERROR | VERCEL


I am using Next.js@latest with App Directory

My app is hosted on Vercel

Do you have any ideas about why Vercel is returning a 504 error? I'm on the pro plan, and my serverless functions are configured to run for a maximum of 5 minutes. Typically, my functions take about 2-3 minutes to execute.

In the logs, I can see that the serverless function is returning a 200 status code, and it's executing correctly. However, when I access it through the browser or postman, after about 1 minute, it returns a 504 error.

Everything works fine locally. What could be the issue?

app/api/generators/article/refine/route.ts

import { type NextRequest } from "next/server";

import { type GetArticle } from "@/types/types";
import GeneratorsAPI from "@/lib/GeneratorsApi/GeneratorsAPI";

export const maxDuration = 300;

export async function POST(request: NextRequest) {
  const payload = (await request.json()) as GetArticle;

  return await GeneratorsAPI.getInstance().getRefinedArticle(payload);
}

lib/GeneratorsAPI

async getRefinedArticle(payload: GetArticle) {
    try {
      this.validatePayloadWith(this.articleValidator, payload);

      const response = await axios.post(this.REFINED, payload, {
        headers: this.headers,
        timeout: 300000,
      });

      const data = response as ArticleAPIReturnType;
      return NextResponse.json({ data: data.data.data }, { status: 200 });
    } catch (err) {
      const error = handleError(err, "getRefinedArticle");

      return NextResponse.json(
        { message: error.message },
        { status: error.errorCode },
      );
    }
  }

This is data from VERCEL LOGS for /refine route

Status Code: 200
Execution duration/limit: 1m 45.76s / 250s
function: /api/generators/article/refine
Environment: production

Solution

  • They had issue on Vercel side and it's fixed already.