Vercel Flags Lab
Evaluate platform-native Vercel Flags with entity targeting - local sticky simulator plus live flags-core.
Run this experiment yourself
Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.
Local development
cd apps/experiments/vercel-flags-lab pnpm install pnpm dev
Then open http://localhost:3010.
This is an experimental demo. Use it as a starting point for your own projects.
The Vercel Flags Lab covers platform-native Vercel Flags: define flags in the dashboard (or as code drafts), evaluate them with the Flags SDK / @vercel/flags-core, and target using entities such as user.plan. Pair it with the Global Config Lab when you need ultra-low-latency config reads alongside flags.
Features
- Flags SDK definition.
flags.tsexportsmarketingBannerwithvercelAdapter()so drafts can surface in the dashboard. - Local targeting simulator. Sticky FNV bucket + plan rules (
enterprise/beta) run entirely in the browser viaevaluateLocalFlag. - Live evaluation.
POST /api/flags/evaluatecallsflagsClient.evaluatefrom@vercel/flags-core. - Honest setup errors. Missing OIDC or missing dashboard flag returns
503with requirements.
UI Reference
| Control | Behavior |
|---|---|
| Flag key / User ID / plan | Entities for local + live evaluation |
| Rollout % / Flag enabled | Local simulator only (evaluateLocalFlag in logic.ts) |
| Local status | Updates as you edit - no network |
| Evaluate via Vercel Flags | Hits the live Route Handler |
Local mode never calls /api - the sticky simulator is pure client TypeScript.
API Reference
POST /api/flags/evaluate
Live Flags evaluation only. Local simulation stays in the UI.
Prop
Type
curl -X POST http://localhost:3010/api/flags/evaluate \
-H 'content-type: application/json' \
-d '{"key":"marketing-banner","userId":"user-7f3a","plan":"enterprise"}'| Status | Cause |
|---|---|
200 | Evaluated via @vercel/flags-core |
400 | Invalid body |
503 | Missing dashboard flag / OIDC - see requirements |
Implementation Details
Code-defined flag:
import { flag } from 'flags/next';
import { vercelAdapter } from '@flags-sdk/vercel';
export const marketingBanner = flag({
key: 'marketing-banner',
adapter: vercelAdapter(),
defaultValue: false,
});Live evaluation path:
const { flagsClient } = await import('@vercel/flags-core');
const result = await flagsClient.evaluate<boolean>(key, false, entities);evaluateLocalFlag in logic.ts mirrors sticky rollout and plan overrides without calling the network.
Use Cases
- Release features behind dashboard toggles without redeploying
- Target enterprise / beta cohorts with entity attributes
- Progressive percentage rollouts with sticky user assignment
Limitations
- Live mode needs a flag in the Vercel project Flags UI and OIDC locally.
- Local simulator is not the production evaluation engine - rules you configure in the dashboard are authoritative for live mode.
- Embedded definitions and Flags Explorer behaviour appear after a real Vercel deploy.
Use in your project
- Create a flag in the dashboard (or deploy a
flag({...})draft) pnpm add flags @flags-sdk/vercel(and/or@vercel/flags-core)- Evaluate in Server Components with
await myFlag()orflagsClient.evaluate
Deployment
After deploy, create marketing-banner under Flags, toggle environments, and hit Evaluate via Vercel Flags in the demo.
Local Development
cd apps/experiments/vercel-flags-lab
pnpm install
vercel link && vercel env pull
pnpm devUnit tests:
pnpm vitest run ../experiments/vercel-flags-labConfiguration
| Setup | Required | Notes |
|---|---|---|
Dashboard flag marketing-banner | Live mode | Boolean recommended for this demo |
OIDC (vercel env pull) | Local live eval | Automatic on Vercel |
Vercel / Next.js Features Used
- Vercel Flags
- Flags SDK (
flags/next) +@flags-sdk/vercel @vercel/flags-coreevaluation engine- Next.js Route Handlers and Server Components patterns