Confirm Vercel is the one ending the request
Look for FUNCTION_INVOCATION_TIMEOUT on the failing requests and note how long each ran. Then read the application logs at the host URL under the /_logs path for exceptions.
Docs: vercel.com →
Find which runtime and duration apply to the route
Search the route for an Edge runtime setting and for maxDuration. For Next.js App Router the duration is a named maxDuration export. Pages router and /api routes use an exported config object.
grep -rnE "runtime = 'edge'|runtime: 'edge'|maxDuration|timeout:" app api pages
Docs: vercel.com →
Log the region on every failure
Print the region next to the outcome of each OpenAI call. If failures cluster in some regions, treat it as a region problem before changing any limits.
console.log("region", process.env.VERCEL_REGION);
Docs: vercel.com →
Put a deadline on the OpenAI call and cap retries
Set the client timeout below the function's maximum duration and lower maxRetries, so one slow call plus its retries fits inside the function limit. On timeout the client throws APIConnectionTimeoutError. Catch it and return a response, because a function that returns none will time out.
const client = new OpenAI({ timeout: 20 * 1000, maxRetries: 0 }); // defaults: 10 minutes, 2 retries
Docs: github.com →
Set a maximum duration that fits the call
Export maxDuration from the route, within the limit for your plan. On the Edge runtime, send the first bytes of the response within 25 seconds and keep streaming, or move the route to Node.js, which Vercel recommends.
export const maxDuration = 60; // seconds, App Router route file
Docs: vercel.com →
Run the function close to the API it calls
Set regions in vercel.json, or per function under functions when different functions call different services. Pinning one region also makes a region-dependent failure easier to reproduce.
{
"regions": ["iad1"]
}
Docs: vercel.com →
Check the function's memory size before raising limits elsewhere
Open the deployment's Resources tab, select the function and hover the information icon in Observability to see its memory size. If the function does heavy work itself, raise the size in the project's Function CPU setting and redeploy.
Docs: vercel.com →