#Vercel Astro functions durations on specific routes

9 messages · Page 1 of 1 (latest)

vagrant moth
#

Hi everyone,

I’m working on an Astro project deployed on Vercel and I’d like to set different function durations for specific routes (not just globally at the project level).

I’ve tried adding patterns under functions in vercel.json, for example:

{
"functions": {
"api/aps/models/**/report": {
"maxDuration": 60
}
}
}

But during the build I get errors like:

Error: The pattern "api/aps/models/**/report" defined in functions doesn't match any Serverless Functions inside the api directory.
Learn More: https://vercel.link/unmatched-function-pattern

I can set maxDuration at the project level without problems, but I haven’t figured out how to apply it per route in Astro.

Is there a way to configure per-route function durations in an Astro project, or is this currently unsupported?

Thanks in advance 🙏

You may encounter a variety of errors when you interact with the Vercel platform. This section focuses on errors that can happen when you interact with the Vercel Dashboard.

languid tigerBOT
#

Hi @vagrant moth. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the available Astro documentation, setting the maxDuration for Vercel Serverless Functions can be done globally in your Astro project by configuring the Vercel adapter in your astro.config.mjs file:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';

export default defineConfig({
  // ...
  adapter: vercel({
    maxDuration: 60
  }),
});

This sets the maximum duration for all serverless functions in your project, but the documentation does not mention any way to set maxDuration on a per-route or per-function basis within Astro itself. The maxDuration option is only described as a global setting for the adapter, not as a route-specific configuration. There is no mention of support for per-route function duration in the Astro Vercel adapter documentation or in the official deployment guides Astro Vercel adapter configuration.

Additionally, the error you encountered with vercel.json suggests that Vercel’s per-function configuration is designed for functions in the /api directory, which is not how Astro generates its serverless functions—Astro’s routes are not placed in the /api directory by default, and the build output structure is managed by the adapter.

Conclusion:
There is currently no documented way to set per-route function durations for Astro projects deployed to Vercel. Only a global maxDuration can be set via the adapter configuration. If you need per-route control, this is not supported according to the current Astro documentation.

#

If this is a critical need, you may want to follow up with the Astro or Vercel teams for feature requests or possible workarounds as the documentation does not provide a solution for this scenario.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@vagrant moth Kapa.ai is still learning and improving, please let me know how I did by reacting below.

vagrant moth
#

@languid tiger how is the build output routes with Vercel and Astro ?

languid tigerBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

When deploying an Astro project to Vercel using the official adapter, the build output is structured so that each route in your Astro project (defined by files in src/pages/) is mapped to a corresponding serverless function or static file, depending on your configuration.

  • Static Output (default):
    If your Astro project is configured for static output, all routes are prerendered at build time and output as static HTML files. No serverless functions are created, and you can deploy without the Vercel adapter unless you need Vercel-specific features like image optimization or analytics Astro Vercel adapter guide.

  • Server Output (SSR):
    If you enable on-demand rendering (SSR) by installing the Vercel adapter and setting output: 'server' in your config, Astro generates serverless functions for your dynamic routes. Each route in src/pages/ that is not prerendered will be handled by a Vercel serverless function. The adapter takes care of mapping these routes to the correct function entrypoints for Vercel Deploy your Astro Site to Vercel.

  • Routing:
    Astro uses file-based routing, so the structure of your src/pages/ directory determines the routes. Static routes become static files, and dynamic routes (e.g., [id].astro) become serverless functions if not prerendered. There is no separate routing config; the adapter handles the mapping automatically Routing Guide.

#
  • vercel.json:
    You can use a vercel.json file to override some Vercel deployment behaviors, but the actual mapping of Astro routes to Vercel functions is managed by the adapter, not by custom patterns in vercel.json How to deploy.

Summary:
Astro’s Vercel adapter automatically maps your src/pages/ routes to static files or serverless functions in the Vercel build output, depending on your configuration. You do not manually control the function output structure; the adapter handles this for you.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: