Clavem

Selling and licensing an AI app with Stripe

An AI app that calls a paid model API has a cost on every request, so the license has to be checked where the cost is: on your server. Have the app send Clavem's signed token, verify it on your backend with no extra call, and keep usage quotas in your own database.

Where the cost sits decides where the check goes

There are two ways an AI app reaches a model, and they license differently.

Model Who pays the provider Where to check the license Fits
The user brings their own API key The user In the app, as for any desktop app A tool for people who already have provider accounts
Your backend holds the provider key You On your backend, for every request A product with a monthly price and a quota

In the first case, the app is an ordinary app: activate, store a token, validate at launch. See desktop apps. In the second, the license check is what stops a leaked key from running up your bill, and an in-app check is not enough, because the request that costs you money reaches your server whether or not the app checked anything.

Never ship your provider’s API key inside the app. Anyone can read it out of the binary or the network traffic.

The token is your API credential

Clavem’s activate and validate responses include a token: a JSON payload signed with the product’s Ed25519 key. It carries lid (the license id), pid (the product id), valid, exp if the license expires, iid (the device), and refresh_by. Your backend can verify it with the product’s public key and call nobody.

The flow:

  1. The app activates with the key and stores the token.
  2. On each request to your backend, the app sends the token in an Authorization header.
  3. Your backend verifies the signature, then pid, valid, exp and refresh_by, and looks up usage by lid.
  4. The app re-validates with Clavem at launch and about daily, and gets a fresh token, which restarts the 14-day window.

Here is the verification in Node, using node:crypto. It was run against a token signed with a freshly generated key: it accepted the good token, and rejected a token for another product and a tampered payload.

import { createPublicKey, verify } from 'node:crypto';

// DER prefix that wraps a raw 32-byte Ed25519 public key as SPKI.
const SPKI_PREFIX = Buffer.from('302a300506032b6570032100', 'hex');

export function verifyToken(token, publicKey, productId, now = Date.now() / 1000) {
  const parts = token.split('.');
  if (parts.length !== 3 || parts[0] !== 'sgt1') return null;

  const key = createPublicKey({
    key: Buffer.concat([SPKI_PREFIX, Buffer.from(publicKey, 'base64url')]),
    format: 'der',
    type: 'spki',
  });
  const signed = Buffer.from(`${parts[0]}.${parts[1]}`);
  if (!verify(null, signed, key, Buffer.from(parts[2], 'base64url'))) return null;

  const claims = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
  if (claims.v !== 1 || claims.pid !== productId || !claims.valid) return null;
  if (claims.exp && claims.exp < now) return null;
  if (claims.refresh_by < now) return null; // the app must validate again
  return claims;
}

publicKey and productId come from your product page in the dashboard. The public key is not a secret. A token that fails any check should get a 401 with a message that tells the app to re-validate, not a blank error.

Two cautions. The payload is signed but not encrypted, so it includes the buyer’s email address; do not log whole tokens. And a token says what the license looked like when it was issued: a refunded license stays accepted by your backend until refresh_by. If an abusive key matters sooner, keep a deny list of lid values on your side, or shorten the window by rejecting tokens older than a limit you choose from iat.

Quotas and credits are yours to build

Clavem does not meter usage. Your backend needs to count requests or tokens per lid, store them, and refuse when a quota is reached. A reasonable design:

  • A table keyed by lid and billing period with the usage so far.
  • A monthly quota set by plan. The plan can come from which Clavem product or Stripe price the license belongs to; Clavem labels a mapping with a variant name you set.
  • For credit packs, a Stripe one-time price per pack and a webhook or script of your own that adds credits to the balance. Clavem issues the license; the balance is your data.

Because the backend sees every request, you can also rate limit per license, which protects you from a leaked key far better than any check in the client.

What happens when Clavem is unreachable

Your backend does not need Clavem to answer a request, because the token verifies locally. The app is the one that needs Clavem, once a day. If it cannot reach it, it keeps sending the stored token until refresh_by. After that, your backend rejects the token and the app asks the user to connect once. That behavior is the same as for any offline check.

Setting Suggested value Why
License type Subscription, following the Stripe subscription Your cost recurs, so the price should too
Device limit 3 A subscription used on a few of the user’s machines
Trial A small free quota on your backend, tied to an anonymous id Keeps provider spend bounded before purchase
Quota Per lid, in your database Clavem does not count usage

A subscription license in Clavem stays valid through the paid period plus three days, and during Stripe’s payment retries when a subscription is past due. A canceled or unpaid subscription expires it.

Doing this with Clavem

Create a product, connect Stripe, map the subscription price. The app follows the Node.js, Swift or Electron flow to activate and store the token, and your backend uses the verifier above or the offline page in another language. For on-device models, see local LLM apps.

Guides to follow

Questions

Does Clavem meter AI usage or credits?

No. Clavem issues license keys, tracks devices and verifies status. Usage metering is not part of it. Count requests or tokens per license in your own database, keyed by the license id in the signed token.

Should my backend call Clavem on every AI request?

No. The License API allows 60 requests a minute per key. Verify the signed token with the product's public key instead, which needs no network call, or cache validate answers for a few minutes.