# Add real features to your app

Call an API, run an AI feature, take a payment, or kick off a background job. Functions let you do it all. Deploy your app, and Netlify runs it.

[Get started for free](https://app.netlify.com/signup) [View docs](https://docs.netlify.com/build/functions/overview/)

![Netlify Functions connected to APIs, scheduled jobs, and integrations](/images/platform/netlify-functions.svg)

Or start with a prompt

Build on Netlify

Using the Netlify skills at netlify.ai, scaffold a Netlify Function with a typed config, a /api/hello path, and a JSON response.

## What you can build

More than 700 million functions run on Netlify every day. Here’s the kind of work they power.

     

### Ship AI without the plumbing

Call any model, handle the response, and send it back to your app, all from one function. AI Gateway manages the API keys and bills usage through your existing plan.

-   Connect to OpenAI, Anthropic, and Google via [AI Gateway](https://docs.netlify.com/build/ai-gateway/overview/)
-   Run inference in the background with [Background Functions](https://docs.netlify.com/build/functions/background-functions/)
-   Store and retrieve results with [Netlify Database](https://docs.netlify.com/build/data-and-storage/netlify-database/)

[Explore AI Gateway](https://docs.netlify.com/build/ai-gateway/overview/)

Example: generate alt text with OpenAI

```
// 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" };
```

### APIs that ship with your app

Stand up JSON endpoints that your frontend, or anyone else, can call. Set the path in config, return data, and it’s live with your site.

-   Define routes with a typed `config.path`
-   Read params, headers, and body from the standard `Request`
-   Same module shape as Deno, Bun, Hono, and Nitro, so existing code ports with little change
-   Same project, same deploy as your frontend

[Read the Functions docs](https://docs.netlify.com/build/functions/overview/)

Example: return products from an API

```
// 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" };
```

### Hand off the slow work

For work that takes a while, like generating with AI, processing a file, or crunching data, background functions run up to 15 minutes. They respond right away and keep working after, so your app stays responsive.

-   Declare it with `export const config = { background: true }`
-   Returns a 202 immediately, then finishes in the background
-   Write results to Netlify Database, Blobs, or a webhook

[Learn about Background Functions](https://docs.netlify.com/build/functions/background-functions/)

Example: generate a report in the background

```
// 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);
};
```

### Run jobs on a schedule

Set a schedule in config and Netlify runs the function on time for nightly syncs, digest emails, or cleanup. It fires on its own, with no scheduler to maintain.

-   Set a cron expression with `config.schedule`
-   No inbound request. Netlify invokes it on schedule
-   Pair with Database for reports, Blobs for cleanup

[Learn about Scheduled Functions](https://docs.netlify.com/build/functions/scheduled-functions/)

Example: send a daily digest on a schedule

```
// 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();
};
```

### Check who’s there before you respond

Verify identity and gate content on the server, before any data goes out. The browser can’t skip the check.

-   Read request and user context with `getContext`
-   Block, redirect, or set metadata at signup or login
-   Pairs with Netlify Identity

[Learn about Identity](https://docs.netlify.com/manage/security/secure-access-to-sites/identity/use-identity-in-functions/)

Example: gate a dashboard behind auth

```
// 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" };
```

### React to events from anywhere

Receive webhooks from the services your app depends on, or subscribe to platform events like signups and deploys, and act on them with a typed handler.

-   Handle Stripe, GitHub, and other provider webhooks
-   Subscribe to platform events: signup, form, deploy
-   Typed event handlers, colocated with your routes

[Read the Functions docs](https://docs.netlify.com/build/functions/overview/)

Example: handle a Stripe webhook

```
// 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" };
```

## 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

Call OpenAI, Anthropic, or Google models from any function without managing API keys. Netlify handles the keys, tracks usage in your dashboard, and bills it through your plan.

[Learn about AI Gateway

](https://docs.netlify.com/build/ai-gateway/overview/)

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

](https://docs.netlify.com/build/data-and-storage/netlify-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

](https://docs.netlify.com/manage/security/secure-access-to-sites/identity/use-identity-in-functions/)

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

](https://docs.netlify.com/build/edge-functions/overview/)

## Frequently asked questions

What is Netlify Functions?

It’s how you run code on a server as part of your Netlify project, for things like API endpoints, background jobs, scheduled tasks, and webhooks. Anything your app needs to do outside the browser.

What’s the difference between a regular function, a background function, and a scheduled function?

Regular functions respond to a request and return something, so they’re best for work that finishes quickly. Background functions handle longer-running work (up to 15 minutes) and respond immediately while the job keeps running, so reach for them with AI features, file processing, or anything where the result can come a little later. Scheduled functions run automatically on a cron schedule, which suits recurring tasks like nightly syncs, digest emails, or cleanup jobs that don’t start from a user request at all.

Can my AI coding agent configure Functions?

Yes. Region, memory, how it runs, event handlers — everything is set in code, so your agent can read it, write it, and change it the same way it handles 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 →](https://www.netlify.com/pricing/)

## Your app’s logic has a home

Write it and publish it without thinking about the infrastructure underneath.

[Get started for free](https://app.netlify.com/signup) [Talk to an expert](/contact/sales/)