Function Handlers
A handler is a single endpoint within a Function. Each handler has its own path, price, allowed methods, and TypeScript code. A Function can contain multiple handlers, each serving a different purpose.
Creating a handler
From your Function detail page, click Add Handler and configure:
| Field | Description |
|---|---|
| Name | A human-readable label for the handler |
| Path | The URL path segment (e.g. /translate) |
| Price | Cost per request in USD |
| Methods | Allowed HTTP methods (GET, POST, etc.) |
Writing handler code
The built-in code editor provides a TypeScript environment. Your handler exports a default function that receives a Request and returns a Response:
export default async function handler(req: Request): Promise<Response> {
const body = await req.json();
const result = await fetch('https://api.example.com/process', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ input: body.text }),
});
const data = await result.json();
return Response.json({ output: data.result });
}Accessing request data
The Request object is a standard Web API Request. Use it to read headers, query parameters, and body:
export default async function handler(req: Request): Promise<Response> {
// Query params
const url = new URL(req.url);
const query = url.searchParams.get('q');
// Headers
const apiVersion = req.headers.get('x-api-version');
// JSON body (for POST/PUT)
const body = await req.json();
return Response.json({ query, apiVersion, received: body });
}Environment variables
Handlers can access secrets and configuration via process.env. See the Secrets section for how to manage encrypted environment variables.
export default async function handler(req: Request): Promise<Response> {
const apiKey = process.env.OPENAI_API_KEY;
// use apiKey to call external services
return Response.json({ status: 'ok' });
}Pricing per handler
Each handler has its own price, letting you charge differently for lightweight reads versus expensive computations. Prices are set in USD with a minimum of 0.0001.
PayWeave