Developers
The Soca SDK
The official @usesoca/sdk TypeScript client: zero dependencies, fully typed, one method per real endpoint: invoices, plans, payments, subscriptions, events, metering, credits, entitlements, and webhook verification.
@usesoca/sdk is the official TypeScript client for the Soca API. It is a thin, zero-dependency, fully-typed wrapper over the versioned REST surface. Every method maps 1:1 to a real /v1 endpoint, so anything you can do here you can also do with plain HTTP (see the API reference).
Install and initialize
The constructor takes your secret key (sk_test_... or sk_live_...) and optional { baseUrl, fetch } options. baseUrl defaults to https://soca.to. The key must stay server-side. See Authentication. Amounts everywhere are USDC base units (6 decimals): $9.00 = 9_000_000.
The SDK also lives in the Soca monorepo at packages/sdk. If you are working inside the repo, import it from there instead of npm.
Invoices
Plans
Plans are create-only over the API for now; there is no plans.list(). pricing_model also supports package, tiered (graduated/volume), and flat — see the SocaPricingModel type.
Payments, subscriptions, and events
Meters and meter events
Create a meter (or in the dashboard), then ingest usage against it. meters.create is idempotent by key, and event ingestion is idempotent per idempotency_key: retrying with the same key never double-counts.
Credits
Prepaid customer credits: grant a balance, debit it as usage happens, read it back. A debit only draws down what the credits cover and reports the rest as shortfall for you to bill separately, or pass allow_negative: true to let the balance go below zero instead.
Entitlements
Entitlements are the access-control layer tied to what a customer has paid for. Grant a feature, then check it from your backend before serving the feature. This is the pattern for gating anything behind a plan or a manual grant:
Error handling
Every non-2xx response throws a SocaError carrying the HTTP status and the machine-readable code from the error envelope:
Webhook verification
The SDK ships the same verification the platform uses: HMAC-SHA256 over timestamp.rawBody, timing-safe comparison, and a 5-minute replay window:
Pass the raw request body string, before any JSON parsing. Full details on headers, retries, and the event table are in Webhooks and events.
Was this page helpful?
A quick signal helps us improve the right pages.