Next.js Discord

Discord Forum

Serverless function execute time and upgrade

Answered
Nebelung posted this in #help-forum
Open in Discord
NebelungOP
Hello All.

I want a open ai api call that keeps getting timeouted. So looked around and saw that the hoppy plan only allows for 10 seconds. So i upgrade, but for some reason i still get the same execute time for my serverless functions. For some reason i can't see my upgraded account
Answered by Ray
export const config = {
  maxDuration: 300,
}

you should set the maxDuration like this for page router
View full answer

13 Replies

NebelungOP
Look at my invocides i don't see the paymne
This is my very simple api call: export const maxDuration = 300;

export default async function handler(req, res) {
if (req.method === "POST") {
const systemPrompt = req.body.system;
const prompt = req.body.prompt;
const model = req.body.model;
const apiKey = process.env.OPENAI_API_KEY;
const url = "https://api.openai.com/v1/chat/completions";

const body = JSON.stringify({
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: prompt },
],
model: model,
temperature: 0,
stream: false,
});

try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: Bearer ${apiKey},
},
body,
});

const data = await response.json();
console.log("GOT DATA FROM SERVER");
res.status(200).json({ data });
} catch (error) {
res.status(500).json({ error: error.message });
}
} else {
res.setHeader("Allow", ["POST"]);
res.status(405).end(Method ${req.method} Not Allowed);
}
}
The maxDuration doesn't work
Answer
export const maxDuration = 300; only work for app router
NebelungOP
Oh i see
@Ray Thank you so much that worked. What about the pro user how do i see that?
How do i see if i upgraded or not
there should be a badge showing Hobby or Pro
or vercel.app > settings > billing
NebelungOP
Thank you