ClocknextClocknextHelp
DocumentationAPI ReferenceMCP Tools
Dashboard

Get started

OverviewQuickstart

Good to know

Response formatHandling errorsPaginating resultsSending data reliablyYour own customer idsWebhooks

API reference

Signals

Record credit POSTRecord outcome POSTComplete outcome POSTRecord wallet POSTRecord unit POSTComplete composite POSTList raw signals GETRetry signals POSTList Customer Usage Log GETLook Up Usage Logs by ID GET

Deprecated

Record credit POSTRecord outcome POSTComplete outcome POSTRecord wallet POSTRecord unit POSTComplete composite POSTList raw signals GETRetry signals POST

Customers

List customers GETCreate a customer POSTGet a customer GETUpdate a customer PATCHDelete a customer DELETEGet a customer's balances GETGet a customer's wallet ledger GETSet a customer's low-balance alert for wallet PUTGet a customer's current plan GETChange a recurring grant PUTUpdate a customer's card POSTGet a customer's invoice balance GETAdjust a customer's invoice balance POST

Deprecated

List Customer Usage Log GETLook Up Usage Logs by ID GET

Manage

Manage a customer's credit balance POSTManage a customer's outcome balance POSTManage a customer's unit balance POSTManage a customer's composite balance POSTManage a customer's wallet balance POST

Members

List a customer's members GETAdd a member POSTUpdate a member PATCHRemove a member DELETE

Plans and Entitlements

PlansPackagesCreditsOutcomesUnitsComposites

Taxes

List taxes GETCreate a tax POSTGet a tax GETUpdate a tax PATCH

Purchases

List purchases GETCreate a purchase POSTGet a purchase GETUpdate a purchase's auto-payment setting PATCHCancel a purchase POST

Checkout

Create a checkout POST

Subscriptions

List subscriptions GETGet a subscription GETCancel a subscription POSTAdd packages to a subscription POSTRemove a package from a subscription POST

Plan changes

List plan changes GETPreview a plan change POSTChange a customer's plan POSTGet a plan change GET

Invoices

List invoices GETGet an invoice GETMint a hosted pay link GETRecord a payment POST

Credit notes

List credit notes GETCreate a credit note POSTGet a credit note GETVoid a credit note POST

Refunds

List refunds GETRefund to the card POSTGet a refund GET

Payments

List payments GETGet a payment GET

Webhooks

Customer Portal

Mint a customer-portal access token POST

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/sdk

This 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.

Overview

The Clocknext Payments API and Node.js SDK — meter LLM usage, manage customers and plans.

Response format

Every endpoint — success or error — returns the same predictable envelope. Here's the contract.

On this page

Set your keyCreate a customerCreate an entitlementPackage it into a PlanPurchase the plan for the customerRecord a usage signalRead it backWhat just happenedNext steps