You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Flags SDK (`flags` npm package) is a feature flags toolkit for Next.js and SvelteKit. It turns each feature flag into a callable function, works with any flag provider via adapters, and keeps pages static using the precompute pattern.
22
+
The Flags SDK (`flags` npm package) is a feature flags toolkit for Next.js and SvelteKit. It turns each feature flag into a callable function, works with any flag provider via adapters, and keeps pages static using the precompute pattern. Vercel Flags is the first-party provider, letting you manage flags from the Vercel dashboard or the `vercel flags` CLI.
19
23
20
24
- Docs: https://flags-sdk.dev
21
25
- Repo: https://github.com/vercel/flags
22
26
23
-
## Core Concepts
27
+
## Core concepts
24
28
25
-
### Flags as Code
29
+
### Flags as code
26
30
27
-
Each flag is declared as a function — no string keys at call sites:
31
+
Each flag is declared as a function. No string keys at call sites:
Evaluate flags server-side to avoid layout shift, keep pages static, and maintain confidentiality. Use routing middleware + precompute to serve static variants from CDN.
46
+
Flags evaluate server-side to avoid layout shift, keep pages static, and maintain confidentiality. Combine routing middleware with the precompute pattern to serve static variants from CDN.
44
47
45
-
### Adapter Pattern
48
+
### Adapter pattern
46
49
47
-
Adapters replace `decide` and `origin` on a flag declaration, enabling provider-agnostic flags:
50
+
Adapters replace `decide` and `origin` on a flag declaration, connecting your flags to a provider. Vercel Flags (`@flags-sdk/vercel`) is the first-party adapter. Third-party adapters are available for Statsig, LaunchDarkly, PostHog, and others.
Vercel Flags is Vercel's feature flags platform. You create and manage flags from the Vercel dashboard or the `vercel flags` CLI, then connect them to your code with the `@flags-sdk/vercel` adapter. When you create a flag in Vercel, the `FLAGS` and `FLAGS_SECRET` environment variables are configured automatically.
65
+
66
+
### Quickstart
67
+
68
+
Install the adapter:
69
+
70
+
```bash
71
+
pnpm i flags @flags-sdk/vercel
72
+
```
73
+
74
+
Create a flag in the Vercel dashboard, then pull environment variables:
75
+
76
+
```bash
77
+
vercel env pull
78
+
```
79
+
80
+
You may need to run `vercel link` first if your project isn't linked to Vercel yet.
81
+
82
+
Declare the flag in your code:
83
+
84
+
```ts
85
+
// flags.ts
86
+
import { flag } from'flags/next';
87
+
import { vercelAdapter } from'@flags-sdk/vercel';
88
+
89
+
exportconst exampleFlag =flag({
90
+
key: 'example-flag',
91
+
adapter: vercelAdapter(),
92
+
});
93
+
```
94
+
95
+
`vercelAdapter()` reads the `FLAGS` environment variable automatically. Call the flag as a function to resolve its value:
Configure which entity types are available for targeting in the Vercel Flags dashboard under your project's flags settings.
135
+
136
+
### `vercel flags` CLI
137
+
138
+
You can manage Vercel Flags from the terminal with `vercel flags`. The CLI supports creating, toggling, inspecting, archiving, and deleting flags, as well as managing SDK keys. It requires the [Vercel CLI](https://vercel.com/docs/cli) and a linked project (`vercel link`).
139
+
140
+
Available subcommands: `list`, `add`, `inspect`, `enable`, `disable`, `archive`, `rm`, `sdk-keys`.
141
+
142
+
For detailed examples and all subcommand options, see [references/providers.md](references/providers.md#vercel-flags-cli). For the full Vercel CLI reference (beyond flags), install the `vercel-cli` skill:
Store as `FLAGS_SECRET` env var. On Vercel: `vc env add FLAGS_SECRET` then `vc env pull`.
200
309
201
-
## Precompute Pattern (Overview)
310
+
## Precompute pattern
202
311
203
312
Use precompute to keep pages static while using feature flags. Middleware evaluates flags and encodes results into the URL via rewrite. The page reads precomputed values instead of re-evaluating.
204
313
@@ -212,7 +321,7 @@ For full implementation details, see framework-specific references:
212
321
-**Next.js**: See [references/nextjs.md](references/nextjs.md) — covers proxy middleware, precompute setup, ISR, generatePermutations, multiple groups
Manage Vercel Flags from the terminal with `vercel flags`. Requires the [Vercel CLI](https://vercel.com/docs/cli) (`pnpm i -g vercel`) and a linked project.
112
+
Manage Vercel Flags from the terminal. Requires the [Vercel CLI](https://vercel.com/docs/cli) (`pnpm i -g vercel`) and a linked project (`vercel link`).
113
113
114
-
Available subcommands: `list`, `add`, `inspect`, `enable`, `disable`, `archive`, `rm`, `sdk-keys`.
vercel flags add my-feature --kind boolean --description "New onboarding flow"
132
+
133
+
# Enable in development first
134
+
vercel flags enable my-feature --environment development
135
+
136
+
# Promote to production
118
137
vercel flags enable my-feature --environment production
138
+
139
+
# Disable in production
140
+
vercel flags disable my-feature --environment production
141
+
```
142
+
143
+
`enable` and `disable` only work with boolean flags. For other flag types, configure values in the Vercel dashboard.
144
+
145
+
#### Inspect and list flags
146
+
147
+
```bash
148
+
# Show details of a specific flag (status, environments, targeting rules)
149
+
vercel flags inspect my-feature
150
+
151
+
# List all flags in the project
119
152
vercel flags list
153
+
```
154
+
155
+
#### Archive and delete a flag
156
+
157
+
A flag must be archived before it can be deleted:
158
+
159
+
```bash
160
+
vercel flags archive my-feature
161
+
vercel flags rm my-feature
162
+
```
163
+
164
+
#### Manage SDK keys
165
+
166
+
SDK keys connect your application to Vercel Flags. The `FLAGS` environment variable contains an SDK key.
167
+
168
+
```bash
169
+
# List SDK keys for the project
120
170
vercel flags sdk-keys ls
171
+
172
+
# Create a new SDK key
173
+
vercel flags sdk-keys add
174
+
175
+
# Remove an SDK key
176
+
vercel flags sdk-keys rm <sdk-key-id>
121
177
```
122
178
123
-
`enable` / `disable` only work with boolean flags. A flag must be archived before it can be deleted.
179
+
These examples cover common flag operations, but the CLI supports additional commands and options not listed here. For the full `vercel flags` reference and other Vercel CLI commands, install the `vercel-cli` skill:
124
180
125
-
Full CLI reference: https://vercel.com/docs/cli/flags
0 commit comments