VOOZH about

URL: https://vercel.com/docs/functions/configuring-functions/runtime

⇱ Configuring the Runtime for Vercel Functions


Skip to content

Configuring the Runtime for Vercel Functions

The runtime of your function determines the environment in which your function will execute. Vercel supports various runtimes including Node.js, Python, Ruby, and Go. You can also configure other runtimes using the vercel.json file. Here's how to set up each:

By default, a function with no additional configuration will be deployed as a Vercel Function on the Node.js runtime.

api/hello.ts
exportfunctionGET(request:Request) {
returnnewResponse('Hello from Vercel!');
}
api/hello.js
exportfunctionGET(request) {
returnnewResponse('Hello from Vercel!');
}
app/api/hello/route.ts
exportfunctionGET(request:Request) {
returnnewResponse('Hello from Vercel!');
}
app/api/hello/route.js
exportfunctionGET(request) {
returnnewResponse('Hello from Vercel!');
}

If you're not using a framework, you must either add "type": "module" to your package.json or change your JavaScript Functions' file extensions from .js to .mjs

For Go, write a server in main.go, cmd/api/main.go, or cmd/server/main.go. The server must listen on the PORT environment variable:

main.go
package main

import (
"fmt"
"log"
"net/http"
"os"
)

funcmain() {
 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 fmt.Fprintln(w, "Hello from Go on Vercel")
 })

 port := os.Getenv("PORT")
if port =="" {
 port ="3000"
 }

 log.Fatal(http.ListenAndServe(":"+port, nil))
}

Vercel also supports file-based Go functions under /api. For that model, export an http.HandlerFunc from a .go file. For more details, see Using the Go Runtime with Vercel Functions.

For Python, write an ASGI (Asynchronous Server Gateway Interface) or WSGI (Web Server Gateway Interface) application that exposes an app variable in app.py, index.py, server.py, or main.py. Here's a FastAPI example:

app.py
from fastapi import FastAPI

app =FastAPI()

@app.get("/")
defhome():
return{"message":"Hello from Python on Vercel"}

Vercel also supports file-based Python functions under /api. For that model, define a handler class or an app variable in a .py file. For more details, see Using the Python Runtime with Vercel Functions.

For Ruby, define an HTTP handler from .rb files within an /api directory at your project's root. Ruby files must have one of the following variables defined:

  • Handler proc that matches the do |request, response| signature
  • Handler class that inherits from the WEBrick::HTTPServlet::AbstractServlet class

For example:

api/index.rb
require'cowsay'

Handler=Proc.newdo|request, response|
 name = request.query['name'] ||'World'

 response.status =200
 response['Content-Type'] ='text/text; charset=utf-8'
 response.body =Cowsay.say("Hello #{name}",'cow')
end

Don't forget to define your dependencies inside a Gemfile:

Gemfile
source "https://rubygems.org"

gem "cowsay","~> 0.3.0"

You can configure other runtimes by using the functions property in your vercel.json file. For example:

vercel.json
{
"$schema":"https://openapi.vercel.sh/vercel.json",
"functions": {
"api/test.php": {
"runtime":"vercel-php@0.5.2"
 }
 }
}

In this case, the function at api/hello.ts would use the custom runtime specified.

For more information, see Community runtimes

Last updated March 17, 2026

Was this helpful?

Functions
Configuring Functions
Runtime