API Reference
Quickstart
Create a customer, package a Plan, and record your first usage signal — start to finish.
Install the SDK first:
npm install @clocknext/sdkThis is optional — skip it if you call the API directly with cURL or your own HTTP client.
This guide takes you from an API key to a priced usage signal in seven steps — two of them in the dashboard, since entitlements and Plans aren't available over the API yet. Every other step shows both cURL and Node.js.
You'll need
An API key (cnk_…) from Settings → API Keys. Keep it in an environment
variable — the samples below read $CLOCKNEXT_API_KEY. The Node.js tabs use
the official @clocknext/sdk client (cnk).
Set your key
Export your key so every request can read it. Never hard-code it in source you commit.
export CLOCKNEXT_API_KEY="cnk_your_key_here"Create a customer
A customer is who you bill. Only name and email are required — everything
else is an optional profile field you can also fill in later. Here we send the
full profile so invoices render complete from day one.
curl https://payments.clocknext.com/api/v1/customers \
-H "Authorization: Bearer $CLOCKNEXT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Acme Inc",
"email": "ops@acme.com",
"description": "AI meeting-notes startup — growth tier",
"website": "https://acme.com",
"phone": "+1 415 555 0100",
"legalName": "Acme Incorporated",
"addressLine1": "500 Market Street",
"city": "San Francisco",
"state": "CA",
"country": "United States",
"pincode": "94105",
"taxId": "US-EIN 12-3456789",
"currencyCode": "USD"
}'Grab the new customer's id — you'll reference it as customerId everywhere
else. The SDK returns it directly; the raw response wraps it in the
envelope's result.
Create an entitlement
Define what the customer is allowed to consume. Entitlements aren't available over the API yet — create at least one in the dashboard:
- Credits for token-tracked features
- Outcomes for work billed by result, step by step
- Units for simple counted items
- Composite to combine entitlements into one meter
- Or skip this and bill straight against the customer's Wallet
Every type has a stable agentKey except Wallet. If you create a Credit,
Outcome, Unit, or Composite, note its agentKey — you'll pass it on your
usage signal. See
Decide what they can consume for the
full walkthrough.
Package it into a Plan
Bundle the entitlement(s) from the previous step into a Plan — the thing you
actually sell — in Plans → New Plan. For each component, choose whether
it's billed in advance or in arrears. Note the Plan's id (e.g.
plan_growth) for the next step. See
Package it as a Plan for the full
walkthrough.
Purchase the plan for the customer
Put the customer on the Plan you just created. Only customerId and
planId are required. The Plan itself must be active — purchasing an
inactive one returns 400.
curl https://payments.clocknext.com/api/v1/purchases \
-H "Authorization: Bearer $CLOCKNEXT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customerId": "cus_abc123",
"planId": "plan_growth"
}'The purchase starts PENDING, with its first invoice in invoice (when the
plan has something to pay up front). It starts once that invoice is paid:
send the customer invoice.payUrl, or record a payment you received another
way with Record a payment
(cnk.invoices.pay(invoice.id, { mode: "BANK_TRANSFER" })). The customer then
has an active Plan — the last prerequisite before a signal can be counted.
See Create a purchase for the
full parameter list.
Record a usage signal
Meter one LLM request against that customer, now that it's on an active Plan.
Signals go to the events API, https://events.clocknext.com (the SDK sends
them there by itself). Each meter type has its own route under /signal/* —
pick the one that matches the entitlement you created. The route decides the meter, so there is
no type field in the body. customerId is always required; everything else
depends on the type.
Debits the customer's USD wallet at the model's provider cost — no
agentKey needed.
curl -X POST https://events.clocknext.com/api/v1/signal/wallet \
-H "Authorization: Bearer $CLOCKNEXT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customerId": "cus_abc123",
"member": "dana@acme.com",
"usage": {
"model": "gpt-4o",
"inputTokens": 1200,
"outputTokens": 350,
"cacheTokens": 200,
"cacheWriteTokens": 0
},
"custom": { "feature": "chat", "region": "eu" }
}'The platform prices the request server-side from the model's (or unit's)
live rates. The answer is always 202 with the signal's signalId; the
signal is checked and priced a moment later. A signal that can't be counted
(an unknown agentKey, no active plan, …) is kept as PENDING: find it with
List raw signals and send it
again with Retry signals. See
Reliability for what that means for your
code.
Read it back
Confirm the signal landed on the Signals page in the dashboard — or read the customer's balances back over the API/SDK:
curl https://payments.clocknext.com/api/v1/customers/cus_abc123/balances \
-H "Authorization: Bearer $CLOCKNEXT_API_KEY"balances returns the customer's wallet, credit, outcome, and unit balances
under their current Plan. See
Get a customer's balances
for the full shape.
What just happened
You authenticated with a bearer key, created a billing identity, gave it something to consume and a Plan to buy it on, purchased that Plan, metered one request against it, and read the result back — with one API key and the same response envelope on both hosts.
Next steps
Meter by credit or outcome
Bill against a named credit balance or an outcome step instead of the wallet.
How Plans and entitlements work
The full conceptual walkthrough — entitlements, Plans, Purchases, and Signals.
Embed the customer portal
Mint a short-lived token so customers can see their own balances.