Skip to main content

License a VS Code or productivity extension

Written for developers

This is a step-by-step technical guide to adding a license screen to your product: it has code to copy and API calls to make. If you sell the product but don't write its code, read Not a developer? Start here and send this page to your developer.

This covers VS Code (and forks such as Cursor) extensions, plus plugins for tools like Obsidian, Raycast, and the JetBrains IDEs. A license is per computer: the customer enters the key once through a command, the extension activates that machine, and it re-checks in the background.

Licensr does not host your extension. You publish it on the marketplace (or your own site) and link your buy page from the listing.

Product settings​

SettingValue
Activation modeSeat: one activation per computer.
Client typeNative app. The extension host runs on the computer and sends no browser Origin.
IdentifierVS Code: vscode.env.machineId, already stable per computer.

Create a plan​

In the admin panel, open your product and add a plan: one price with a limit on how many devices or websites one key can be used on. Keep the defaults if you are unsure. You can add more plans later. See the Quick start.

Also create a Client API key on the product (shown once, starts with pk_test_ or pk_live_). This is the key you put in your product.

Get a test license​

You do not have to pay to try your integration. In the admin panel go to Customers → Issue license, enter your own email, pick the product and plan, and issue it. The key (starts with lic_) arrives by email and is shown once on screen. The dashboard checklist has a shortcut for this.

Use your pk_test_ key against https://api.staging.licensr.app while you build, then switch to pk_live_ and https://api.licensr.app when you release.

What your license screen must do​

Your product needs one small screen: a text box for the key, an Activate button, and a Deactivate button. It follows these rules, whatever the platform:

  1. Activate, then validate. When the customer clicks Activate, call activate (this registers the device or website against the plan's limit), then validate. Unlock only if the validate response has valid: true. Save the key and the activation_id from the activate response.
  2. Check again in the background. Call validate at every launch and about once a day while the product runs. A refund, a cancelled subscription, or an expired license happens after the sale, and this daily check is how your product finds out. Without it, a refunded key keeps working forever.
  3. Lock immediately on valid: false. If Licensr cannot be reached, stay unlocked (optionally lock after a few days with no answer). Try again later.
  4. Offer a Deactivate button. It calls deactivate with the saved activation_id, forgets the key, and locks the product. This lets a customer move to a new computer without asking you for help.

Messages to show when activate fails (read detail.error in the response):

CodeSay
license_not_found"We could not find that key. Check for typos."
activation_cap_exceeded"This key is already in use on the maximum number of devices. Deactivate it on another device first."
license_inactive"This license is no longer active. Contact the seller."
no response at all"Could not reach the license server. Try again."
any other code"Something went wrong (code)." Show the code so the customer can send it to you.

The full list is in Errors.

VS Code​

Use the JavaScript SDK (npm install @licensr/sdk) or plain fetch. Store the key in VS Code's secret storage.

import * as vscode from 'vscode';
import {LicensrClient, LicensrApiError} from '@licensr/sdk';

const client = new LicensrClient({
apiKey: 'pk_live_...', // Client key, safe to ship in the extension
pluginSlug: 'my-extension',
deviceId: vscode.env.machineId,
});

export function activate(context: vscode.ExtensionContext) {
// Customer runs "My Extension: Activate License".
context.subscriptions.push(
vscode.commands.registerCommand('myExtension.activate', async () => {
const licenseKey = await vscode.window.showInputBox({prompt: 'Paste your license key', ignoreFocusOut: true});
if (!licenseKey) return;
try {
const activation = await client.activate({
licenseKey,
activationType: 'seat',
identifier: vscode.env.machineId,
label: vscode.env.appName,
});
const check = await client.validate({licenseKey});
if (!check.valid) return vscode.window.showErrorMessage('This license is not active.');
await context.secrets.store('licenseKey', licenseKey);
await context.globalState.update('activationId', activation.activationId);
vscode.window.showInformationMessage('License activated.');
} catch (err) {
const full = err instanceof LicensrApiError && err.code === 'activation_cap_exceeded';
vscode.window.showErrorMessage(
full ? 'This key is already used on the maximum number of computers.' : 'We could not activate that key.'
);
}
})
);

// Customer runs "My Extension: Deactivate License".
context.subscriptions.push(
vscode.commands.registerCommand('myExtension.deactivate', async () => {
const licenseKey = await context.secrets.get('licenseKey');
const activationId = context.globalState.get<string>('activationId');
if (licenseKey && activationId) await client.deactivate({licenseKey, activationId}).catch(() => {});
await context.secrets.delete('licenseKey');
await context.globalState.update('activationId', undefined);
})
);

// At startup, and again every 24 hours while the editor stays open.
const check = async () => {
const licenseKey = await context.secrets.get('licenseKey');
if (!licenseKey) return;
try {
const result = await client.validate({licenseKey});
await context.globalState.update('licensed', result.valid);
} catch {
// offline or server trouble: keep the previous state
}
};
check();
const timer = setInterval(check, 24 * 60 * 60 * 1000);
context.subscriptions.push({dispose: () => clearInterval(timer)});
}

export const isLicensed = (context: vscode.ExtensionContext) => context.globalState.get<boolean>('licensed') === true;

Register both commands in package.json under contributes.commands so they appear in the command palette, and call isLicensed(context) wherever you unlock a feature.

Obsidian, Raycast, JetBrains and similar​

The flow is identical. Use the tool's own storage for the key and activation ID, a stored random ID as the identifier, and the tool's timer for the daily check. If the tool runs JavaScript, reuse the code above. For Kotlin or Java (JetBrains), follow the any-language guide. Obsidian plugins run in a web view and send a browser Origin: set the client type to Browser and leave Allowed websites empty.

Licensr does not host your download. Host the file on your own website or store, then add a Buy button that links to your Licensr buy page (the dashboard shows the full link, which looks like /buy/your-slug). Customers pay there and get their key by email, then paste it into your license screen.

Go live​

  1. Swap your pk_test_ key for the pk_live_ key and use https://api.licensr.app in the release build.
  2. Buy your own product once, using the buy page, to see the whole flow.
  3. Check the dashboard: the Get started checklist shows You're live! when payments, a product, a plan, a test license, and a first check from your product are all done.

Stuck? The license calls guide lists every field and error.