Vercel MIDDLEWARE_INVOCATION_TIMEOUT

Vercel returns MIDDLEWARE_INVOCATION_TIMEOUT and Gateway Timeout? Routing Middleware ran past its limit, or sent no response chunk for a while.

Reviewed October 22, 2026

What it means in plain English

Vercel documents MIDDLEWARE_INVOCATION_TIMEOUT as Routing Middleware that takes longer than the allowed execution time to complete, or that does not send a response chunk for a certain amount of time. The page says this can come from long-running work in the function, or from external dependencies that do not respond in time. The response it shows is Gateway Timeout.

If the backend API takes time to respond, Vercel recommends streaming the response to avoid the idle timeout.

A middleware crash, rather than a timeout, is MIDDLEWARE_INVOCATION_FAILED. See MIDDLEWARE_INVOCATION_FAILED. A function that is not middleware and hits its own limit is FUNCTION_INVOCATION_TIMEOUT.

Likely causes

  • Middleware waits on a slow API or database before it returns.
  • The function has a long-running operation or an infinite loop.
  • The function does not return a response within the time limit Vercel states for this error, which is 25 seconds.

How to fix it, step by step

  1. Open the application logs at the host URL under /_logs, and look for errors from Routing Middleware being invoked.
  2. Inspect the middleware for a long-running operation or an infinite loop.
  3. Return a response within the 25 second limit Vercel states for this error.
  4. If the function calls an external service, Vercel says to make that call respond quickly, and to consider a fetch timeout with AbortSignal.timeout.
  5. If the function is processing a large amount of data, use a streaming response. Vercel also says to stream when the backend API is slow, so the function does not hit the idle timeout.
  6. Add error handling in the function for timeouts and other exceptions.

How to check it worked

  • The route that returned Gateway Timeout now returns a response.
  • /_logs no longer records MIDDLEWARE_INVOCATION_TIMEOUT for that request.

Sources

More Vercel deploy and runtime fixes

Keep going on your own.

The guides stay free. A deep leak report is $15. Fix packs are $24, or $49 for all three. There is no done-for-you repair.

See products