Overview
SolvaPay bills and meters on the server side. Your product keeps its own client (CLI, web app, mobile) and its own identity provider (Auth0, Cognito, a custom IdP, or a provider CLI likelogin / init). Your backend holds sk_* and links each signed-in user to a SolvaPay customer via a stable externalRef.
This is the canonical integration shape when you own the customer experience. SolvaPay does not need a credential in the CLI, a SolvaPay-hosted approval page, or IdP access tokens on SolvaPay APIs.
Quick start (any Node backend)
ensureCustomer is idempotent: repeated calls with the same externalRef return the same SolvaPay customerRef.
The externalRef contract
REST equivalent
The SDK wraps existing SDK customer endpoints:GET /v1/sdk/customers?externalRef=— find by linkagePOST /v1/sdk/customers— create with{ externalRef, email, name }PATCH /v1/sdk/customers/:reference— updateexternalRefon an existing customer
ensureCustomer implements find-or-create-by-externalRef so you do not need to manage that flow yourself.
Provider-owned CLI pattern
A provider that ships its own CLI (for exampleyour-cli login backed by Auth0) already has an authenticated user id after login. The CLI talks to your API; your API calls SolvaPay:
- CLI completes your IdP login and stores your session token (not
sk_*). - CLI calls your backend with that session.
- Backend resolves
externalReffrom the session (e.g. JWTsub). - Backend calls
ensureCustomer(externalRef)thentrackUsage/payable/checkLimits.
Web app pattern (Auth0 reference)
For Next.js + Auth0, the SDK ships a ready reference that forwardssession.user.sub as billing identity:
- Example: examples/nextjs-auth0
- Scaffold:
npm create solvapay -- --type mcp --auth auth0(or--auth auth0on the Next template) - Adapter details: Custom authentication adapters
externalRef contract applies with any IdP.
Protecting routes after linkage
Once you havecustomerRef, pass it into paywall helpers:
createAuth0AuthMiddleware (or your own adapter) so route handlers receive x-user-id / externalRef automatically. For Express and other frameworks, resolve externalRef in middleware, call ensureCustomer, then set x-customer-ref for payable.http().
What not to do
- Do not put
SOLVAPAY_SECRET_KEYin a customer CLI or browser. - Do not send Auth0 (or other IdP) access tokens to SolvaPay APIs.
- Do not rely on email alone as
externalRef— emails can change; subjects and internal ids should not. - Do not assume SolvaPay will host your customer login — use customer OAuth only when your OAuth clients need SolvaPay as the authorization server (e.g. MCP / third-party apps), which is separate from provider-owned CLI linkage.