Skip to main content
This guide takes an existing application from no billing to full integration. Each step builds on the one before, and each step has a check you can run before moving on.
Time: 1–2 hours for a typical server · You need: a sandbox workspace, a developer API key, and a server application (Node.js or Python).

How the pieces fit

Never put the API key in a browser or mobile app.

Step 1: Map your product to billing terms

Before writing code, decide what you charge for. Write down three things:
  1. The billable action, such as an API call, an image generated, or a seat used. This becomes an eventName.
  2. What you count, such as the number of calls, or the sum of tokens. This becomes a metric.
  3. How you charge, such as per unit, in tiers, or by credits. This becomes a price.
You can state your billable action in one sentence, for example: “Every successful search request is one search_request event.”

Step 2: Create the catalog

Create the metric, price, and plan in your sandbox workspace. The Meter your first API tutorial shows each call. You can also keep the catalog in a pricing.yaml file and deploy it with the CLI.
GET /v1/plans returns your plan, and the plan lists the price you created.

Step 3: Store your credentials

Create one API key per environment, with the smallest role that works. See API keys. Add the key to your secret manager, then expose it to your server as environment variables:
Never commit these values, and never log them.
Run curl -s -o /dev/null -w "%{http_code}" "$ORVLIN_API_URL/v1/health". It returns 200.

Step 4: Install the SDK

For a browser app, also install the React SDK with npm install @orvlin/react. It uses portal tokens, not API keys. See Step 9.

Step 5: Create one client per process

Create the client once at startup and reuse it. The client caches entitlement answers, so reusing it keeps checks fast.
Import the client in one route and call orvlin.check("cust_test", "search_requests"). It returns an answer without throwing. A source value of live shows the first call reached Orvlin.

Step 6: Connect customers

Each customer in your app needs a matching Orvlin customer. Use your own user or account ID as the Orvlin customer ID, so you never store a mapping.
Create the customer when they sign up, and subscribe them to a plan at the same time:
GET /v1/customers/acct_4821 returns the customer, and the subscription has "status": "active" or "trialing".

Step 7: Track usage

Record one event per billable action, after the action succeeds. Key each event to the request, so retries don’t count twice.
The eventName must match the event your metric counts. Check it against the metric definition in Step 2. A mismatch records usage that is never billed.
GET /v1/events?customer_id=acct_4821&event_name=search_request lists the event. Sending it again with the same idempotencyKey does not add a second one.

Step 8: Gate features and spend

Before doing paid work, check the entitlement. Return a clear response when the customer is out of allowance.
For prepaid credits, check the balance the same way with checkCredits (Node) or check_credits (Python), using creditType and quantity. See Prepaid credits.
A customer with allowance gets through. A customer without it gets 402. See the entitlements tutorial for the full middleware.

Step 9: Receive webhooks

Webhooks tell your app when an invoice is paid, a subscription changes, or an approval is decided. Register an HTTPS endpoint, then verify every delivery before you act on it. Register the endpoint with a signed-in user session (not an API key):
Save the secret (it starts with whsec_) in your secret manager. Verify each delivery as shown in Webhooks. Then handle each event once, keyed on its id. The Receive webhooks securely tutorial builds this end to end.
POST /v1/webhooks/:id/test delivers a test event, and your endpoint returns 200.

Step 10: Add a customer portal (optional)

If customers should see their usage, invoices, and plans in your app, create a portal session from your server, and use the React SDK in the browser. Your server creates the session for the signed-in user’s customer only:
The browser then uses the React SDK with that token. See Launch a customer portal.
The portal endpoint GET /v1/portal/me returns the customer when called with the portal token.

Go-live checklist

  • Sandbox tests pass for tracking, gating, and webhooks.
  • A test clock shows the expected first invoice (tutorial).
  • Production uses a live workspace and its own API key, stored in your secret manager.
  • Webhook endpoint uses HTTPS and verifies signatures.
  • Every event and grant uses an idempotency key.
  • Entitlement checks log the source field, so you can see fallbacks.
  • Your team knows where the audit log is and who can approve money-moving actions (approvals).

Troubleshooting

Next steps

Meter your first API

Build the catalog and first usage record end to end.

Reliability

What happens during failures, and what your systems should do.