Skip to main content

Overview

The Feature Flags API enables you to control feature rollouts, manage feature targeting, and toggle features on or off for your users and organizations.

Methods

listFeatureFlags

Retrieves a paginated list of all feature flags.
options
ListFeatureFlagsOptions
Optional pagination and filtering parameters
AutoPaginatable<FeatureFlag>
object
An auto-paginatable collection of feature flags

Example

import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

const featureFlags = await workos.featureFlags.listFeatureFlags({
  limit: 10,
});

for await (const flag of featureFlags) {
  console.log(flag.name, flag.enabled);
}

getFeatureFlag

Retrieves a specific feature flag by its slug.
slug
string
required
The unique slug identifier for the feature flag
FeatureFlag
object
The feature flag object

Example

const flag = await workos.featureFlags.getFeatureFlag('new-dashboard');

console.log(flag.enabled); // true or false

enableFeatureFlag

Enables a feature flag globally.
slug
string
required
The unique slug identifier for the feature flag
FeatureFlag
object
The updated feature flag object with enabled set to true

Example

const flag = await workos.featureFlags.enableFeatureFlag('new-dashboard');

console.log(flag.enabled); // true

disableFeatureFlag

Disables a feature flag globally.
slug
string
required
The unique slug identifier for the feature flag
FeatureFlag
object
The updated feature flag object with enabled set to false

Example

const flag = await workos.featureFlags.disableFeatureFlag('new-dashboard');

console.log(flag.enabled); // false

addFlagTarget

Adds a specific target (user or organization) to a feature flag, enabling the feature for that target.
options
AddFlagTargetOptions
required
Options for adding a flag target

Example

await workos.featureFlags.addFlagTarget({
  slug: 'new-dashboard',
  targetId: 'user_01H8Z9Q2Z3Y4X5W6V7U8T9S0R1',
});

removeFlagTarget

Removes a specific target from a feature flag.
options
RemoveFlagTargetOptions
required
Options for removing a flag target

Example

await workos.featureFlags.removeFlagTarget({
  slug: 'new-dashboard',
  targetId: 'user_01H8Z9Q2Z3Y4X5W6V7U8T9S0R1',
});

Use Cases

Gradual Rollouts

Roll out new features gradually to a subset of users before a full release

A/B Testing

Test different features or variations with specific user segments

Kill Switches

Quickly disable problematic features without deploying new code

Beta Programs

Grant early access to features for beta testers and early adopters

Build docs developers (and LLMs) love