Vercel Flags
Set up feature flags backed by the Vercel Flags dashboard
This guide walks you through setting up feature flags managed in the Vercel Flags dashboard. You'll create flags in the Vercel UI and evaluate them in your Next.js app.
Install dependencies
npm i @octopus-energy/flags flags @flags-sdk/vercelCreate a flag in the Vercel dashboard
Go to your project's
Feature Flags tab and create a
new flag (e.g. my-flag with type boolean).
When you create a flag, Vercel automatically configures two environment variables for your project:
FLAGS: SDK key connecting your app to Vercel FlagsFLAGS_SECRET: secret used by the Flags Explorer for secure overrides
Sync environment variables
Pull the environment variables to your local project using the Vercel CLI:
vercel env pullLink your project first
Run vercel link first if you haven't linked your project yet.
Declare the flag in code
Create a flags.ts file and declare your flag using the Vercel adapter:
// flags.ts
import { flag } from "flags/next";
import { vercelAdapter } from "@flags-sdk/vercel";
export const myFlag = flag({
key: "my-flag",
adapter: vercelAdapter,
});The vercelAdapter automatically uses the FLAGS environment variable to
connect to your Vercel Flags project. Use createVercelAdapter(key) if you
need a custom SDK key.
Generate typed declarations
Generate a TypeScript declaration file that augments flags/next with typed
overloads for your flags:
npm exec oe.flags generate -- --vercel --out generated/flags.d.tsCLI prerequisites
The --vercel source requires the vercel CLI to be installed and
authenticated (vercel link).
This gives you autocomplete and type checking for flag keys and values. Re-run the command whenever you add or change flags. See the generate docs for details.
Evaluate the flag
Call the flag function directly in a Server Component:
// app/page.tsx
import { myFlag } from "../flags";
export default async function Page() {
const enabled = await myFlag();
return <div>{enabled ? "Feature is on" : "Feature is off"}</div>;
}Toggle the flag in the Vercel dashboard for your development environment and reload the page to see the updated value.
Next steps
- Visitor identity: Add stable visitor IDs for A/B testing and progressive rollouts.
- User targeting:
Target specific users or groups with
identifyanddedupe. - Flags Explorer: Set up the discovery endpoint so the Vercel Toolbar can find and override your flags.
- Precompute: Evaluate flags at build time for statically generated pages.