Functions
Add real features to your app
Call an API, run an AI feature, take a payment, or kick off a background job. Write a function, deploy your app, and Netlify runs it.
-
Using the Netlify skills at netlify.ai, scaffold a Netlify Function with a typed config, a /api/hello path, and a JSON response.
-
Using the Netlify skills at netlify.ai, add a background function that generates a report and stores it in Netlify Blobs.
-
Using the Netlify skills at netlify.ai, add a scheduled function that emails a daily digest every morning.
What you can build
More than 700 million functions run on Netlify every day. Here’s the kind of work they power.
// Example: generate alt text with OpenAI
import OpenAI from "openai";
export default async (req: Request) => {
const { description } = await req.json();
const client = new OpenAI();
const res = await client.responses.create({
model: "gpt-5-mini",
input: [
{ role: "user", content: `Write concise alt text for: ${description}` },
],
});
return Response.json({ altText: res.output_text });
};
export const config = { path: "/api/alt-text" }; // Example: return products from an API
export default async (req: Request) => {
const url = new URL(req.url);
const category = url.searchParams.get("category");
const products = await getProducts({ category });
return Response.json({ products });
};
export const config = { path: "/api/products" }; // Example: generate a report in the background
export const config = { background: true };
export default async (req: Request) => {
const { reportId } = await req.json();
// runs well past a normal request — no one's waiting on the response
await buildAndStoreReport(reportId);
}; // Example: send a daily digest on a schedule
export const config = { schedule: "@daily" };
export default async () => {
// runs once a day on its own
await sendDailyDigest();
}; // Example: gate a dashboard behind auth
import { getContext } from "@netlify/functions";
export default async (req: Request) => {
const { account } = getContext();
if (!account) {
return new Response("Sign in to continue", { status: 401 });
}
const data = await getDashboardData(account.id);
return Response.json({ data });
};
export const config = { path: "/api/dashboard" }; // Example: handle a Stripe webhook
export default async (req: Request) => {
const event = await req.json();
if (event.type === "checkout.session.completed") {
const session = event.data.object;
// mark the order paid, grant access, send a receipt...
await fulfillOrder(session);
}
return Response.json({ received: true });
};
export const config = { path: "/api/stripe-webhook" }; Functions or Server?
Both run in your project and deploy with your app. Pick by how the work behaves.
-
Functions: work that starts, finishes, and is done
A request or event comes in, your code runs, and a response goes out. API endpoints, webhooks, scheduled jobs, and background tasks.
-
Server: work that stays connected or keeps going
Open WebSockets, live updates, agents that work for minutes or hours, or a Node app you already have.
Build with your agent, ship with confidence
Write a function, or let your agent write it, then deploy. It publishes with the rest of your app and goes live automatically. And you’re protected the whole way. Preview every change before it’s public, and roll back to any version in one click, so you can move fast without breaking what already works.
-
Ship it with your app
Your functions deploy in the same push as your frontend, in one build and one release. You don’t manage a separate pipeline or schedule a maintenance window.
-
Preview every change
Every change gets its own preview link, functions included, so you can try it against real requests before anyone else sees it.
-
Roll back in one click
If something’s off, return to any earlier version in a click. Your whole app rolls back together.
-
Catch problems early
Watch logs and metrics from every function in real time, and secret scanning blocks exposed keys before a deploy ships. Problems surface while you can still fix them.
-
Control how it runs, in code
Set where a function runs and how much power it gets in its config: a region, plus up to 4 GB of memory and 2 vCPUs.
-
Keep secrets server-side
API calls, secret keys, and the rules behind your app run in the function, never in the browser, so nothing sensitive reaches the client.
Functions works better with the rest of Netlify
Reach for these when a function needs to call a model, store a result, or check who’s signed in. They connect directly, with nothing extra to wire up.
-
AI Gateway
Combine the best open and proprietary models inside any function without managing API keys.
Learn about AI Gateway -
Database
Managed Postgres built into your project. Functions write results to a database that’s already there, branched with every preview and in sync when you ship.
Learn about Database -
Identity
User auth that connects directly to Functions. Run logic at signup or login to block access, set metadata, or trigger a workflow, with no separate auth service to maintain.
Learn about Identity -
Edge Functions
For logic that runs fast and close to the user: personalization, redirects, A/B routing, access checks. Edge Functions handles the lightweight decisions up front; Functions handles the heavier work behind it.
Learn about Edge Functions
Your app’s logic has a home
Write it and publish it without thinking about the infrastructure underneath.
Frequently asked questions
What is Netlify Functions?
Backend code that runs in your Netlify project without a server to manage: API endpoints, webhooks, background jobs, and scheduled tasks.
What’s the difference between a regular function, a background function, and a scheduled function?
Regular functions respond to a request and finish quickly. Background functions run for up to 15 minutes and respond immediately while the job continues. Scheduled functions run on a cron schedule. For longer than 15 minutes, or connections that stay open, use Server.
When should I use Netlify Server instead of Functions?
Use Server for open connections like WebSockets, work that runs for minutes or hours, or an existing Node app. Use Functions for work that starts, finishes, and is done. They run in the same project, so you can use both.
Can my AI coding agent configure Functions?
Yes. Region, memory, and event handlers are all set in code, so your agent can read and change them like the rest of your project.
How does pricing work?
Functions is available on all Netlify plans. Memory and vCPU configuration (up to 4 GB / 2 vCPUs) is available on credit-based plans. See pricing →
