SDK options

Every option for createFlaggish, FlaggishProvider and FlaggishServerProvider, with its default and the environment variable that sets it.

Pass these to createFlaggish(options), or as props on FlaggishProvider and FlaggishServerProvider. An option you pass always wins over environment variables.

flags.ts
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

OptionDefaultWhat it does
clientKeyFLAGGISH_CLIENT_KEY, then NEXT_PUBLIC_FLAGGISH_CLIENT_KEYYour project’s client key, from Settings › API keys.
secretKeyFLAGGISH_SECRET_KEY (never a NEXT_PUBLIC_ variable)Server only. Lets the SDK check list groups. An empty value counts as not set.
envFLAGGISH_ENV, then NEXT_PUBLIC_FLAGGISH_ENV, then the NODE_ENV ruleWhich environment’s flags to read: 'production' or 'development'.
apiUrlFLAGGISH_API_URL, then NEXT_PUBLIC_FLAGGISH_API_URL, then the Flaggish APIThe 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.
cacheTtlMs30000 (30 seconds)How long the fetched flags are cached in memory.
timeoutMs2000 (2 seconds)How long to wait for the API before giving up and using fallbacks.
reachFLAGGISH_REACH, then NEXT_PUBLIC_FLAGGISH_REACH, then trueReport 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:

App.tsx
<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:

PropDefaultWhat it does
userIdnullThe signed-in user’s ID. Used in place of the anonymous ID for rollouts and reach, and to match list groups.
emailnullThe 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.
initialConfignullFlags fetched on the server, for example with getFlaggishConfig(). With it, there’s no loading state.
anonymousIdread from the cookieThe 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:

flags.ts
const flaggish = createFlaggish<'new-checkout' | 'new-banner'>();
Was this page helpful?

Request early access

Become a beta user, or stay up to date with the project.