- Words
- 400
- Reading time
- 2 min
- Last crawled
- 2026-11-25
- Cited by
- 3 of their pages
- Language
- EN
The Flags SDK is a free, open-source library that gives you the tools you need to use feature flags in Next.js and SvelteKit applications. It works with any flag provider, custom setups, or no provider at all.
This page provides an overview of key concepts and APIs. For complete API documentation, visit flags-sdk.dev, the official source of truth for the Flags SDK.
- Framework-native: Built specifically for Next.js (App Router, Pages Router, Middleware) and SvelteKit
- Provider-agnostic: Works with any flag provider or custom adapters
- Type-safe: Full TypeScript support with type inference
- Optimized for performance: Uses precompute pattern for static generation
- Integrated: Works seamlessly with Flags Explorer and Vercel observability features
Flags are defined using the flag() function. Each flag has a key and a decide function that returns the flag's value:
The decide function determines a flag's value. It can be sync or async, and can access request context:
Flags can have multiple options for A/B testing and experimentation:
The precompute pattern generates multiple versions of static pages with different flag values:
On Vercel, precompute works without a FLAGS_SECRET when you use flags version 4.5.0 or later. The Flags SDK signs each code with a key that Vercel provides for the deployment, so a code is only valid inside the deployment that created it. Set a FLAGS_SECRET for apps outside Vercel, for prebuilt deployments (vercel build and vercel deploy --prebuilt), or when a code must be valid in another deployment.
Learn more about precompute on flags-sdk.dev.
Call your flag functions to read their values:
Report flag values for observability (automatic with SDK):
Flags Explorer stores overrides in the vercel-flag-overrides cookie. Vercel signs them for your project. If your project has a FLAGS_SECRET, Vercel Toolbar encrypts them with the secret instead. The flag() function reads this cookie and applies overrides automatically: when an override is present, the decide function is not called and the override value is returned instead. No extra code is needed.
To read overrides manually in Next.js App Router, use the following example. On Vercel, or locally after vercel env pull, decryptOverrides verifies signed overrides without a FLAGS_SECRET. If your project has a FLAGS_SECRET, decryptOverrides uses it to decrypt the overrides:
Create a Flags API endpoint for Flags Explorer:
The Flags SDK works with many providers out of the box:
For the full API documentation, including all functions, types, and advanced patterns, visit:
