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 guarantees that client-side integrations receive consistent values.
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.
- Click Create Product or choose Edit on an existing product.
- Scroll to the Feature Flags section.
- Enter a feature tag (e.g.,
Pro Mode) and click Add Feature. - Save the product. Predefined features will now appear as badges on the product overview page.
2. Allocating Features to Licenses
When creating or modifying a license key:
- Open the license generation or edit modal.
- Switch to the Advanced & Metadata tab.
- Under Feature Flags, predefined product features will be listed with toggle switches.
- If you need to add custom, one-off features for this key, use the Custom Feature Flags section.
- Save or generate the key. The enabled features will be compiled into the 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 state of all features inside metadata.features.
Activation Response Example
{
"code": 0,
"message": "License key activated successfully",
"metadata": {
"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: 'prod_Nx8K2mLpQ4rVtW9sBc',
licenseKey: 'A8E2K-9F1BC-3D4GH-7J2KM'
});
const features = result.metadata?.features || {};
if (features['Pro Mode']) {
console.log("Welcome to Pro Mode!");
enableProFeatures();
} else {
restrictToBasicFeatures();
}