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.
Optional pagination and filtering parameters Maximum number of feature flags to return per page
Cursor for pagination to fetch the next page of results
Cursor for pagination to fetch the previous page of results
AutoPaginatable<FeatureFlag>
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.
The unique slug identifier for the feature flag
The feature flag object Unique identifier for the feature flag
Display name of the feature flag
URL-friendly identifier for the feature flag
Description of what the feature flag controls
Whether the feature flag is currently enabled
Default value for users not specifically targeted
Tags associated with the feature flag
ISO 8601 timestamp of when the flag was created
ISO 8601 timestamp of when the flag was last updated
Example
const flag = await workos . featureFlags . getFeatureFlag ( 'new-dashboard' );
console . log ( flag . enabled ); // true or false
enableFeatureFlag
Enables a feature flag globally.
The unique slug identifier for the feature flag
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.
The unique slug identifier for the feature flag
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 The unique slug identifier for the feature flag
The ID of the user or organization to 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 The unique slug identifier for the feature flag
The ID of the user or organization to remove from targeting
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