Feature Flags
Define product-level Keymint feature flags, assign them to license keys, and read enabled capabilities from activation and floating checkout metadata.
Feature Flags allow you to control access to granular features of your application on a per-license basis. Instead of manually entering feature names when generating a license, you can predefine them on the product itself. This prevents typos and keeps the values your client-side integration receives consistent.
Core Concepts
- Predefined Features: Standard features defined at the product level (e.g.,
Pro Mode,API Access,Advanced Analytics). - Key Toggles: When generating or updating a license key, predefined features are presented as checklist toggles.
- Ad-hoc Custom Features: Any unique, one-off features can still be typed and added manually to individual keys.
- Client-Side Validation: Predefined and custom features are returned as a boolean map inside the metadata payload of license activation and checkout calls.
1. Defining Product Features
To set up standard feature flags for a product:
- Navigate to the Products section of your Keymint dashboard.
- Create a product, or open an existing product and choose Edit product from its … menu.
- Find the Product features field.
- Enter a feature name (e.g.,
Pro Mode) and press Enter or click Add. - Save the product. Predefined features now appear as badges on the product page.
2. Allocating Features to Licenses
When creating or modifying a license key:
- Open Generate license keys (from the product page) or select keys under Licenses and choose Edit.
- When generating, click More options. When editing, the options are below the basics.
- Open Feature flags. The product's features are listed with toggle switches.
- To add a custom, one-off feature for these keys, use Add a flag.
- Generate or save. The enabled features are stored in each license's metadata.
3. Validating Features in Client Applications
When your application activates a license key via the POST /key/activate endpoint (or checks out a seat via POST /key/checkout), the Keymint API returns the license's metadata, including the enabled features in metadata.features. Activation also adds the recorded hostId to metadata.
Activation Response Example
{
"code": 0,
"message": "License valid",
"metadata": {
"hostId": "mac-studio-m2",
"is_trial": false,
"features": {
"Pro Mode": true,
"API Access": false,
"Custom Plugin": true
}
}
}Checking Features in Code
You can conditionally execute code based on the toggles returned:
// Activate the key
const result = await client.activateKey({
productId: 'YOUR_PRODUCT_ID',
licenseKey: 'A8E2K-9F1BC-3D4GH-7J2KM'
});
const features = result.metadata?.features || {};
if (features['Pro Mode']) {
console.log("Welcome to Pro Mode!");
enableProFeatures();
} else {
restrictToBasicFeatures();
}