Pass these to createFlaggish(options), or as props on FlaggishProvider and FlaggishServerProvider. An option you pass always wins over environment variables.
import { createFlaggish } from '@flaggish/sdk';
const flaggish = createFlaggish({
clientKey: process.env.FLAGGISH_CLIENT_KEY,
env: 'production',
defaults: { 'new-checkout': false },
cacheTtlMs: 30_000,
timeoutMs: 2_000,
reach: true,
});Options
| Option | Default | What it does |
|---|---|---|
| clientKey | FLAGGISH_CLIENT_KEY, then NEXT_PUBLIC_FLAGGISH_CLIENT_KEY | Your project’s client key, from Settings › API keys. |
| secretKey | FLAGGISH_SECRET_KEY (never a NEXT_PUBLIC_ variable) | Server only. Lets the SDK check list groups. An empty value counts as not set. |
| env | FLAGGISH_ENV, then NEXT_PUBLIC_FLAGGISH_ENV, then the NODE_ENV rule | Which environment’s flags to read: 'production' or 'development'. |
| apiUrl | FLAGGISH_API_URL, then NEXT_PUBLIC_FLAGGISH_API_URL, then the Flaggish API | The API base URL. Only change it for a self-hosted API. |
| defaults | {} | Values for flags that are missing, before the flags load, and when the API can’t be reached. |
| cacheTtlMs | 30000 (30 seconds) | How long the fetched flags are cached in memory. |
| timeoutMs | 2000 (2 seconds) | How long to wait for the API before giving up and using fallbacks. |
| reach | FLAGGISH_REACH, then NEXT_PUBLIC_FLAGGISH_REACH, then true | Report rollout reach on Full Mast projects. false turns it off for this client or provider. |
clientKey
Without a client key, every check returns its fallback, then its default, then false, and the SDK logs one console warning. The key is public: it can read flags, never change them.
secretKey
Your project’s secret key, from Settings › API keys. With it, a server downloads the people in the lists your flags target and checks them locally. Without it, list groups count as “not in the group” and the SDK logs one warning.
Only createFlaggish and the Next.js server helpers and FlaggishServerProvider read it. FlaggishProvider from @flaggish/sdk/react never takes or reads one. Never put it in a NEXT_PUBLIC_ variable: the SDK ignores those for the secret key, and the browser could read them.
env
The NODE_ENV rule is: Production if NODE_ENV is production, otherwise Development. The FLAGGISH_ENV variables take production or development in any case; other values are ignored. See Flags and environments.
apiUrl
The default is https://flaggishapi-production.up.railway.app.
defaults
An object of flag names to booleans:
<FlaggishProvider defaults={{ 'new-checkout': false, 'new-banner': true }}>A value from your flags always wins over a default. See If Flaggish is down for the full order.
cacheTtlMs and timeoutMs
A check uses the cached flags until they’re cacheTtlMs old. The next check then fetches fresh ones, waiting up to timeoutMs. If that fetch fails, the SDK keeps the last flags it had and waits another cacheTtlMs before trying again.
reach
Reach only runs when the project is on Full Mast and has Count reach on. reach: false turns it off for this client or provider only; it doesn’t affect the Next.js getFlag and getFlags, which take no options. To turn it off for those too, set FLAGGISH_REACH=false. See Reach.
Provider-only props
FlaggishProvider also takes:
| Prop | Default | What it does |
|---|---|---|
| userId | null | The signed-in user’s ID. Used in place of the anonymous ID for rollouts and reach, and to match list groups. |
| null | The signed-in user’s email. Used only for groups: never for rollouts, and it stays in your app. | |
| groupIds | [] | The IDs of the list groups this person is in, worked out on your server with getGroupIds(). FlaggishServerProvider fills it in; never pass the secret key to the browser. |
| initialConfig | null | Flags fetched on the server, for example with getFlaggishConfig(). With it, there’s no loading state. |
| anonymousId | read from the cookie | The visitor’s flaggish_id, read on the server with getAnonymousId(). With it, the first render is already in the right rollout bucket. |
FlaggishServerProvider takes the same props as FlaggishProvider, except initialConfig, anonymousId and groupIds, which it fills in itself, plus the server-only secretKey option, which it never passes to the browser.
The Next.js server helpers
getFlag, getFlags and getFlaggishConfig from @flaggish/sdk/next take no options. They read the client key, secret key, API URL, environment and reach setting from environment variables, and use the default cache time and timeout.
Typed flag names
createFlaggish takes your flag names as a type, so TypeScript checks the names you pass to isEnabled and defaults:
const flaggish = createFlaggish<'new-checkout' | 'new-banner'>();