@kerne/server runs on your backend. It holds your secret key, so it can check access, record usage and start billing flows for any customer.
Install
Your secret key. Omit it only to call public routes, such as
billing.plans() or auth.config().Methods
Products, plans and prices are managed in the dashboard. The SDK reads your public pricing but never creates or edits it.Customers
A customer is who a subscription, a usage counter or an override belongs to. Every access and billing call names one withcustomer, the id you bill: a Kerne user id, or any id you choose if you run your own auth.
Anyone who signs up through Kerne already has a customer, with their user id as externalId. If you run your own auth, or bill a company rather than a person, register it yourself:
upsert() creates the customer if externalId is new, and otherwise fills in the fields it’s missing. Renaming externalId to one another customer already uses fails with a 409.
Calls that take an email, such as checkout(), also create the customer on first use, and so does a granted override. consume() and reportUsage() never do: they reject an unknown id. Register your own customers before you meter them.
provider_accounts lists the customer’s id at each payment provider ([{ provider, provider_customer_id }]). It stays empty until their first checkout.
kerne.customers requires your secret key.
Acting as a user
A secret key isn’t tied to anyone, so each call names itscustomer. To make calls as one signed-in user instead, scope a client to their access token. It can then reach only that user’s own data:
Next.js
Import from@kerne/server/next. It’s the same client plus a server-only guard: the build fails if a Client Component imports it, instead of shipping your secret key to the browser.
Errors
A failed call throws aKerneError with type, code, message and statusCode, plus requestId when the API returned the error.
Branch on the class, not on
code. The API’s codes are listed in Errors.
Direct requests
For a route without a typed method,kerne.request() sends it with the same base URL and credentials:

