How to Use the Netlify Plugin for Serverless Deployments: Complete Setup Guide

The Netlify plugin provides a complete stack for building, testing, and deploying serverless applications on Netlify through automatic function discovery, CLI tooling, and integrated SDK support.

The openai/plugins repository includes a dedicated Netlify plugin that streamlines the creation and deployment of serverless functions. This plugin implements the same architecture that Netlify uses internally, offering a structured approach to building serverless applications with TypeScript and JavaScript. By following the patterns defined in plugins/netlify/skills/netlify-functions/SKILL.md, you can deploy production-ready endpoints without managing infrastructure.

Understanding the Netlify Plugin Architecture

The plugin organizes serverless deployments into three core components: Netlify Functions, configuration files, and CLI tooling. According to the source code in plugins/netlify/skills/netlify-functions/SKILL.md, functions are automatically discovered when placed in the netlify/functions/ directory and exposed at the /.netlify/functions/<function-name> endpoint.

Function Structure and Discovery

Each TypeScript or JavaScript file placed under netlify/functions/ becomes a standalone serverless endpoint. The plugin expects functions to follow the standard Netlify signature using types from @netlify/functions.

Configuration Management

The netlify.toml file, documented in plugins/netlify/skills/netlify-deploy/SKILL.md, controls build settings, redirect rules, and edge-function routing. Netlify reads this configuration during the build process to generate final deployment assets.

Setting Up Your First Serverless Function

To create a serverless function, add a TypeScript file to the netlify/functions/ directory. As specified in plugins/netlify/skills/netlify-functions/SKILL.md, each function receives a Context and optional Config type from the @netlify/functions package.

// netlify/functions/hello.ts
import type { Handler, Context } from "@netlify/functions";

export const handler: Handler = async (event, context: Context) => {
  return {
    statusCode: 200,
    body: JSON.stringify({ message: "👋 Hello from Netlify Functions!" }),
  };
};

This code automatically becomes available at /.netlify/functions/hello once deployed.

Configuring Routing with netlify.toml

The netlify.toml file defines how requests route to your functions and static assets. Based on the documentation in plugins/netlify/skills/netlify-deploy/SKILL.md, you can configure redirects to map custom paths to function endpoints.


# netlify.toml (project root)

[build]
  functions = "netlify/functions"
  publish = "dist"

[[redirects]]
  from = "/api/*"
  to = "/.netlify/functions/:splat"
  status = 200

This configuration redirects all /api/* requests to the corresponding function, hiding the internal /.netlify/functions/ path from end users.

Deploying with the Netlify CLI

The deployment process uses the Netlify CLI to package your site, upload functions, and generate preview URLs. According to plugins/netlify/skills/netlify-cli-and-deploy/SKILL.md, the plugin supports both preview and production deployments.

First, install the CLI globally:

npm install -g netlify-cli

Then deploy a preview build:

netlify deploy --build

This command runs the build process, uploads your functions, and returns a unique preview URL. Once verified, deploy to production:

netlify deploy --prod

Accessing Runtime Primitives and Storage

The plugin bundles official Netlify SDKs including @netlify/functions, @netlify/blobs, and @netlify/identity, enabling direct access to platform primitives from within your code.

Environment Variables

Environment variables are automatically injected at build time and accessible via process.env without additional tooling. This works out of the box for both local development and deployed functions.

Blob Storage for Binary Data

For large binary payloads such as image uploads, the plugin includes blob storage support documented in plugins/netlify/skills/netlify-blobs/SKILL.md. Use the @netlify/blobs package to read and write persistent data.

import { getStore } from "@netlify/blobs";

export const handler = async () => {
  const store = getStore("my-store");
  await store.set("image.png", "binary-data-here");
  
  return {
    statusCode: 200,
    body: "Blob stored successfully"
  };
};

Summary

  • Place serverless functions in netlify/functions/ to automatically expose them at /.netlify/functions/<name>
  • Configure routing, builds, and redirects in netlify.toml as documented in plugins/netlify/skills/netlify-deploy/SKILL.md
  • Use the Netlify CLI (netlify deploy --build) to create preview deployments before pushing to production
  • Access environment variables through process.env and binary storage through @netlify/blobs without additional configuration
  • Reference the skill files in plugins/netlify/skills/ for detailed implementation patterns and best practices

Frequently Asked Questions

How do I install the Netlify plugin from the openai/plugins repository?

The Netlify plugin is included in the openai/plugins repository under plugins/netlify/.codex-plugin/plugin.json. You do not need to install the plugin itself separately; instead, install the Netlify CLI and the required SDKs (npm i @netlify/functions) in your project to begin using the patterns documented in the skill files.

What is the correct file structure for Netlify Functions?

Place all serverless function files in the netlify/functions/ directory at your project root. Each file (such as hello.ts) automatically becomes an endpoint at /.netlify/functions/<filename>. The build configuration in netlify.toml can customize this directory, but netlify/functions/ is the default convention used by the plugin.

How do I access environment variables in Netlify Functions?

Environment variables are automatically injected at build time and runtime. Access them directly through process.env.VARIABLE_NAME within your function code. The plugin handles the injection automatically, so no additional import or configuration is required beyond setting the variables in your Netlify dashboard or local .env file.

Can I test Netlify Functions locally before deploying?

Yes. Use the netlify dev command to run a local development server that emulates the Netlify Functions environment. This allows you to test endpoints at http://localhost:8888/.netlify/functions/<function-name> before running netlify deploy --build to create a preview deployment.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →