Menu

Programmatic Configuration with vercel.ts

Last updated

The file lets you configure and override the default behavior of Vercel from within your project. Unlike , which is static, executes at build time, which lets you dynamically generate configuration. For example, you can fetch content from APIs, use environment variables to conditionally set routes, or compute configuration values based on your project structure.

Use only one configuration file: or .

You can have any sort of code in your file, but the final set of rules and configuration properties must be in a struct export. Use the same property names as in your export. For rewrites, redirects, headers, and transforms, prefer the helper functions from :

To migrate from , copy its contents into your export, then add new capabilities as needed.

Install the NPM package to get access to types and helpers.

Create a in your project root and export a typed config. The example below shows how to configure build commands, framework settings, routing rules (rewrites and redirects), and headers:

You can also use , , , or to create this configuration file.

To migrate from an existing , paste its contents into a export in a new vercel.ts file:

Then install the package and enhance your configuration:

Via the types imported from the package, autocomplete for all config properties and helpers are automatically available in .

Type:

The property can be used to override the Build Command in the Project Settings dashboard, and the script from the file for a given deployment. For more information on the default behavior of the Build Command, visit the Configure a Build - Build Command section.

This value overrides the Build Command in Project Settings.

The Bun runtime is available in Beta on all plans

Type:

Value:

The property configures your project to use the Bun runtime instead of Node.js. When set, all Vercel Functions and Routing Middleware not using the Edge runtime will run using the specified Bun version.

Vercel manages the Bun minor and patch versions automatically. is the only valid value currently.

When using Next.js with ISR (Incremental Static Regeneration), you must also update your and commands in :

To learn more about using Bun with Vercel Functions, see the Bun runtime documentation.

Type: .

Default Value: .

When set to , all HTML files and Vercel functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.

For example, a static file named will be served when visiting the path. Visiting will redirect to .

Similarly, a Vercel Function named will be served when visiting . Visiting will redirect to .

If you are using Next.js and running , you will get a 404 error when visiting a route configured with locally. It does however work fine when deployed to Vercel. In the example above, visiting locally will give you a 404 with but will render correctly on Vercel.

Used to configure cron jobs for the production deployment of a project.

Type: of cron .

Limits:

  • A maximum of string length of 512 for the value.
  • A maximum of string length of 256 for the value.
  • - Required - The path to invoke when the cron job is triggered. Must start with .
  • - Required - The cron schedule expression to use for the cron job.

This value overrides the Development Command in Project Settings.

Type:

The property can be used to override the Development Command in the Project Settings dashboard. For more information on the default behavior of the Development Command, visit the Configure a Build - Development Command section.

This value allows you to enable Fluid compute programmatically.

Type:

The property allows you to test Fluid compute on a per-deployment or per custom environment basis when using branch tracking, without needing to enable Fluid in production.

As of April 23, 2025, Fluid compute is enabled by default for new projects.

This value overrides the Framework in Project Settings.

Type:

Available framework slugs:

The property can be used to override the Framework Preset in the Project Settings dashboard. The value must be a valid framework slug. For more information on the default behavior of the Framework Preset, visit the Configure a Build - Framework Preset section.

To select "Other" as the Framework Preset, use null.

Type: of key and value .

A glob pattern that matches the paths of the Vercel functions you would like to customize:

  • (matches one level e.g. but not )
  • (matches all levels and )
  • (matches all functions from )
  • (optional): The npm package name of a Runtime, including its version.
  • : Memory cannot be set in with Fluid compute enabled. Instead set it in the Functions tab of your project dashboard. See setting default function memory for more information.
  • (optional): An integer defining how long your Vercel Function should be allowed to run on every request in seconds (between and the maximum limit of your plan, as mentioned below).
  • (optional): A boolean defining whether your Vercel Function should support request cancellation. This is only available when you're using the Node.js runtime.
  • (optional): A glob pattern to match files that should be included in your Vercel Function. If you're using a Community Runtime, the behavior might vary. Please consult its documentation for more details. (Not supported in Next.js, instead use in )
  • (optional): A glob pattern to match files that should be excluded from your Vercel Function. If you're using a Community Runtime, the behavior might vary. Please consult its documentation for more details. (Not supported in Next.js, instead use in )

By default, no configuration is needed to deploy Vercel functions to Vercel.

For all officially supported runtimes, the only requirement is to create an directory at the root of your project directory, placing your Vercel functions inside.

The property cannot be used in combination with . Since the latter is a legacy configuration property, we recommend dropping it in favor of the new one.

Because Incremental Static Regeneration (ISR) uses Vercel functions, the same configurations apply. The ISR route can be defined using a glob pattern, and accepts the same properties as when using Vercel functions.

When deployed, each Vercel Function receives the following properties:

  • Memory: 1024 MB (1 GB) - (Optional)
  • Maximum Duration: 10s default - 60s / 1 minute (Hobby), 15s default - 300s / 5 minutes (Pro), or 15s default - 900s / 15 minutes (Enterprise). This can be configured up to the respective plan limit) - (Optional)

To configure them, you can add the property.

In order to use a runtime that is not officially supported, you can add a property to the definition:

In the example above, the Vercel Function does not use one of the officially supported runtimes. In turn, a property was added in order to invoke the vercel-php community runtime.

For more information on Runtimes, see the Runtimes documentation:

Type: of header .

Valid values: a list of header definitions.

This example configures custom response headers for static files, Vercel functions, and a wildcard that matches all routes.

PropertyDescription
A pattern that matches each incoming pathname (excluding querystring).
A non-empty array of key/value pairs representing each response header.
An optional array of objects with the , and properties. Used for conditional path matching based on the presence of specified properties.
An optional array of objects with the , and properties. Used for conditional path matching based on the absence of specified properties.
PropertyTypeDescription
Must be either , , , or . The property only applies to request headers sent by clients, not response headers sent by your functions or backends.
The key from the selected type to match against. For example, if the is and the is , we will match against the header key.
or or The value to check for, if any value will match. A regex like string can be used to capture a specific part of the value. For example, if the value is used for then will be usable in the destination with . If an object is provided, it will match when all conditions are met for its fields below.

If is an object, it has one or more of the following fields:

ConditionTypeDescription
(optional)Check for equality
(optional)Check for inequality
(optional)Check for inclusion in the array
(optional)Check for non-inclusion in the array
(optional)Check for prefix
(optional)Check for suffix
(optional)Check for a regex match
(optional)Check for greater than
(optional)Check for greater than or equal to
(optional)Check for less than
(optional)Check for less than or equal to

This example demonstrates using the expressive object to append the header if the request header's value is prefixed by and ends with .

Learn more about rewrites on Vercel and see limitations.

This value overrides the Ignored Build Step in Project Settings.

Type:

This property will override the Command for Ignoring the Build Step for a given deployment. When the command exits with code 1, the build will continue. When the command exits with 0, the build is ignored. For more information on the default behavior of the Ignore Command, visit the Ignored Build Step section.

This value overrides the Install Command in Project Settings.

Type:

The property can be used to override the Install Command in the Project Settings dashboard for a given deployment. This setting is useful for trying out a new package manager for the project. An empty string value will cause the Install Command to be skipped. For more information on the default behavior of the install command visit the Configure a Build - Install Command section.

The property defines the behavior of Vercel's native Image Optimization API, which allows on-demand optimization of images at runtime.

Type:

  • - Required - Array of allowed image widths. The Image Optimization API will return an error if the parameter is not defined in this list.
  • - Allow-list of local image paths which can be used with the Image Optimization API.
  • - Allow-list of external domains which can be used with the Image Optimization API.
  • - Cache duration (in seconds) for the optimized images.
  • - Array of allowed image qualities. The Image Optimization API will return an error if the parameter is not defined in this list.
  • - Supported output image formats. Allowed values are either and/or .
  • - Allow SVG input image URLs. This is disabled by default for security purposes.
  • - Specifies the Content Security Policy of the optimized images.
  • - Specifies the value of the response header. Allowed values are or .

This value overrides the Output Directory in Project Settings.

Type:

The property can be used to override the Output Directory in the Project Settings dashboard for a given deployment.

In the following example, the deployment will look for the directory rather than the default or root directory. For more information on the default behavior of the Output Directory see the Configure a Build - Output Directory section. The following example is a file that overrides the to :

Type: .

Default Value: .

When set to , both the source view and logs view will be publicly accessible.

Type: of redirect .

Valid values: a list of redirect definitions.

Some redirects and rewrites configurations can accidentally become gateways for semantic attacks. Learn how to check and protect your configurations with the Enhancing Security for Redirects and Rewrites guide.

This example redirects requests to the path from your site's root to the file relative to your site's root with a 307 Temporary Redirect:

This example redirects requests to the path from your site's root to the file relative to your site's root with a 308 Permanent Redirect:

This example redirects requests to the path from your site's root to the api route relative to your site's root with a 301 Moved Permanently:

This example redirects requests to the path from your site's root to the absolute path of an external site with a redirect status of 308:

This example redirects requests to all the paths (including all sub-directories and pages) from your site's root to the absolute path of an external site with a redirect status of 308:

This example uses wildcard path matching to redirect requests to any path (including subdirectories) under from your site's root to a corresponding path under relative to your site's root with a redirect status of 308:

This example uses regex path matching to redirect requests to any path under that only contain numerical digits from your site's root to a corresponding path under relative to your site's root with a redirect status of 308:

This example redirects requests to any path from your site's root that does not start with and has header value of to a corresponding path under relative to your site's root with a redirect status of 307:

Using has does not yet work locally while using vercel dev, but does work when deployed.

PropertyDescription
A pattern that matches each incoming pathname (excluding querystring).
A location destination defined as an absolute pathname or external URL.
An optional boolean to toggle between permanent and temporary redirect (default ). When , the status code is 308. When the status code is 307.
An optional integer to define the status code of the redirect. Used when you need a value other than 307/308 from , and therefore cannot be used with boolean.
An optional array of objects with the , and properties. Used for conditional redirects based on the presence of specified properties.
An optional array of objects with the , and properties. Used for conditional redirects based on the absence of specified properties.
PropertyTypeDescription
Must be either , , , or . The property only applies to request headers sent by clients, not response headers sent by your functions or backends.
The key from the selected type to match against. For example, if the is and the is , we will match against the header key.
or or The value to check for, if any value will match. A regex like string can be used to capture a specific part of the value. For example, if the value is used for then will be usable in the destination with . If an object is provided, it will match when all conditions are met for its fields below.

If is an object, it has one or more of the following fields:

ConditionTypeDescription
(optional)Check for equality
(optional)Check for inequality
(optional)Check for inclusion in the array
(optional)Check for non-inclusion in the array
(optional)Check for prefix
(optional)Check for suffix
(optional)Check for a regex match
(optional)Check for greater than
(optional)Check for greater than or equal to
(optional)Check for less than
(optional)Check for less than or equal to

This example uses the expressive object to define a route that redirects users with a redirect status of 308 to only if the header's value is prefixed by and ends with .

Learn more about redirects on Vercel and see limitations.

Learn more about bulk redirects on Vercel and see limits and pricing.

Type: path to a file or folder.

The property can be used to import many thousands of redirects per project. These redirects do not support wildcard or header matching.

CSV, JSON, and JSONL file formats are supported, and the redirect files can be generated at build time as long as they end up in the location specified by . This can point to either a single file or a folder containing multiple redirect files.

CSV headers must match the field names below, can be specific in any order, and optional fields can be ommitted.

Bulk redirects do not work locally while using vercel dev

FieldTypeRequiredDescription
YesAn absolute path that matches each incoming pathname (excluding querystring). Max 2048 characters.
YesA location destination defined as an absolute pathname or external URL. Max 2048 characters.
NoToggle between permanent (308) and temporary (307) redirect. Default: .
NoSpecify the exact status code. Can be 301, 302, 303, 307, or 308. Overrides permanent when set, otherwise defers to permanent value or default.
NoToggle whether source path matching is case sensitive. Default: .
NoToggle whether to preserve the query string on the redirect. Default: .

In order to improve space efficiency, all boolean values can be the single characters (true) or (false) while using the CSV format.

This value overrides the Vercel Function Region in Project Settings.

Type: of region identifier .

Valid values: List of regions, defaults to .

You can define the regions where your Vercel functions are executed. Users on Pro and Enterprise can deploy to multiple regions. Hobby plans can select any single region. To learn more, see Configuring Regions.

Function responses can be cached in the requested regions. Selecting a Vercel Function region does not impact static files, which are deployed to every region by default.

Setting failover regions for Vercel functions are available on Enterprise plans

Set this property to specify the region to which a Vercel Function should fallback when the default region(s) are unavailable.

Type: of region identifier .

Valid values: List of regions.

These regions serve as a fallback to any regions specified in the configuration. The region Vercel selects to invoke your function depends on availability and ingress. For instance:

  • Vercel always attempts to invoke the function in the primary region. If you specify more than one primary region in the property, Vercel selects the region geographically closest to the request
  • If all primary regions are unavailable, Vercel automatically fails over to the regions specified in , selecting the region geographically closest to the request
  • The order of the regions in does not matter as Vercel automatically selects the region geographically closest to the request

To learn more about automatic failover for Vercel Functions, see Automatic failover. Vercel Functions using the Edge runtime will automatically failover with no configuration required.

Region failover is supported with Secure Compute, see Region Failover to learn more.

Type: of rewrite .

Valid values: a list of rewrite definitions.

If is set to in your project's , do not include the file extension in the source or destination path. For example, would be

Some redirects and rewrites configurations can accidentally become gateways for semantic attacks. Learn how to check and protect your configurations with the Enhancing Security for Redirects and Rewrites guide.
  • This example rewrites requests to the path from your site's root to the file relative to your site's root:

  • This example rewrites all requests to the root path which is often used for a Single Page Application (SPA).

  • This example rewrites requests to the paths under that with 2 paths levels (defined as variables and that can be used in the destination value) to the api route relative to your site's root:

  • This example uses wildcard path matching to rewrite requests to any path (including subdirectories) under from your site's root to a corresponding path under the root of an external site :

  • This example rewrites requests to any path from your site's root that does not start with /uk/ and has x-vercel-ip-country header value of GB to a corresponding path under /uk/ relative to your site's root:

  • This example rewrites requests to the path from your site's root that does not have a cookie with key to the path relative to your site's root:

PropertyDescription
A pattern that matches each incoming pathname (excluding querystring).
A location destination defined as an absolute pathname or external URL.
A boolean to toggle between permanent and temporary redirect (default true). When , the status code is 308. When the status code is 307.
An optional array of objects with the , and properties. Used for conditional rewrites based on the presence of specified properties.
An optional array of objects with the , and properties. Used for conditional rewrites based on the absence of specified properties.
PropertyTypeDescription
Must be either , , , or . The property only applies to request headers sent by clients, not response headers sent by your functions or backends.
The key from the selected type to match against. For example, if the is and the is , we will match against the header key.
or or The value to check for, if any value will match. A regex like string can be used to capture a specific part of the value. For example, if the value is used for then will be usable in the destination with . If an object is provided, it will match when all conditions are met for its fields below.

If is an object, it has one or more of the following fields:

ConditionTypeDescription
(optional)Check for equality
(optional)Check for inequality
(optional)Check for inclusion in the array
(optional)Check for non-inclusion in the array
(optional)Check for prefix
(optional)Check for suffix
(optional)Check for a regex match
(optional)Check for greater than
(optional)Check for greater than or equal to
(optional)Check for less than
(optional)Check for less than or equal to

This example demonstrates using the expressive object to define a route that rewrites users to only if the header's value is prefixed by and ends with .

The property should NOT be a file because precedence is given to the filesystem prior to rewrites being applied. Instead, you should rename your static file or Vercel Function.

Using has does not yet work locally while using vercel dev, but does work when deployed.

Learn more about rewrites on Vercel.

Type: .

Default Value: .

When , visiting a path that ends with a forward slash will respond with a 308 status code and redirect to the path without the trailing slash.

For example, the path will redirect to .

When , visiting a path that does not end with a forward slash will respond with a 308 status code and redirect to the path with a trailing slash.

For example, the path will redirect to .

However, paths with a file extension will not redirect to a trailing slash.

For example, the path will not redirect, but the path will redirect to .

When , visiting a path with or without a trailing slash will not redirect.

For example, both and will serve the same content without redirecting.

This is not recommended because it could lead to search engines indexing two different pages with duplicate content.

Legacy properties like and are still supported in for backwards compatibility, but are deprecated. We recommend using the helper-based options above (, , ) for type safety and better developer experience.

For details on legacy properties, see the legacy section of the static configuration reference.


Was this helpful?

supported.