TypeScript SDK
@veriticity/sdk is the official TypeScript client for the Veriticity API: typed purchase decisions, typed errors, webhook signature verification and discriminated event types, with zero runtime dependencies.
@veriticity/sdk is the official TypeScript client for the Veriticity API. It is a consumer of the same public API this site documents — every method maps to one endpoint, and nothing it returns has been reshaped on the way through.
It is optional. The API is plain HTTP with JSON, and every example on this site is also shown as raw curl. Use the SDK if you are writing TypeScript and would like typed decisions, typed errors and a webhook verifier you do not have to write yourself.
Install#
ESM only, with zero runtime dependencies. Installing it adds one package to your tree and nothing else.
Authenticate#
The SDK accepts the same two credentials the API does: an API key, or an OAuth access token from a connection somebody authorised.
An API key bound to an agent and an organisation-scoped key look identical — both begin cmp_live_, and the difference between them is an authority the server holds. The SDK cannot check it locally, so each method’s documentation says which it needs and the server returns api_key_not_bound_to_agent or api_key_not_organization_scoped when it is not met.
| Method | Credential | OAuth scope |
|---|---|---|
purchases.submit | API key bound to an agent | purchase:request |
purchases.get | API key bound to an agent | purchase:read |
simulations.currentPolicies | Either kind | purchase:check |
| Everything else | Organisation-scoped API key | — |
The SDK does not implement OAuth authorisation or refresh. It consumes an access token; obtaining one is your application’s job, for the reasons set out in Authentication.
Your first purchase#
A refusal is not an exception. Veriticity was asked a question and answered it, so a REJECTED decision resolves normally. Branch on decision.outcome, never on the HTTP status.
Money#
amountMinor accepts a string, a number or a bigint and is always sent as a decimal string. It is always a string coming back, and the SDK never converts it to a JavaScript number — JSON numbers lose precision above 253, and this is money.
Check before you buy#
A simulation records nothing, reserves nothing and costs nothing, so an agent that is unsure should ask before it acts. It is not a guarantee — policy can change between the two calls, and only the submission decides.
Verify a webhook#
Verification needs no API credential and no HTTP client, so it lives in its own entry point. A receiver deployed to an edge runtime can import it without the rest of the package.
During a rotation Veriticity signs each delivery with every live secret and sends both signatures, so a receiver holding either succeeds. Pass an array while you change over:
Errors#
Every failure the SDK throws extends VeriticityError. HTTP failures become a VeriticityApiError subclass chosen by status; transport failures become VeriticityConnectionError or VeriticityTimeoutError; a mistake the SDK can see without asking the server becomes VeriticityConfigError.
The classes are convenience. error.code is the same stable code documented under Errors, and the SDK invents none of its own. issues is always an array, so iterating it is always safe.
Errors carry status, code, message, issues, method, path and operationId — and deliberately carry no credential, no request headers, no request body and no full URL. An error object ends up in a log, and none of those belong there.
Retries and idempotency#
The SDK never retries. There are no rate limits, no 429 and no Retry-After to back off from, and a silently retried purchase submission would ask for a second decision, take a second budget hold and write a second row of permanent evidence.
Idempotency is available on purchase submission and nowhere else, which the types enforce: an idempotencyKey passed to any other method is a compile error. A key over 255 characters is refused before the request is made.
Policies and pagination#
The SDK preserves the API’s pagination rather than inventing one of its own, so what you get back is what the API reference describes. policies.listAll() is the single addition — an async generator that walks pages until the server reports the last one.
Webhook deliveries take a limit and nothing else, so there is no iterator for them; raise the limit to see more. There is no purchase-list method, because there is no purchase-list endpoint.
Runtimes#
| Runtime | Supported |
|---|---|
| Node.js 20.19 or newer | Yes — the primary target |
| Next.js, both the Node and Edge runtimes | Yes |
| Serverless functions | Yes |
| Cloudflare Workers | Yes |
| Deno, Bun | Yes |
| Browser | No, deliberately |
The SDK uses Web APIs only — fetch, URL, AbortSignal, TextEncoder and Web Crypto — so it runs unchanged everywhere above. A CommonJS project on a supported version of Node can require it.
What the SDK deliberately does not do#
- No automatic retries, backoff, jitter or circuit breaking. Retry deliberately, with your own stable idempotency key.
- No generated idempotency keys. A key has to be stable across your retries, which means only you can mint it.
- No OAuth flow. It consumes an access token; it does not obtain, refresh or store one.
- No payment execution. Veriticity decides. It does not hold funds and does not move money.
- No logging or telemetry. The SDK writes nothing to stdout or stderr. Supply your own
fetchto observe requests. - No browser support and no sandbox.
Where to go next#
- Quickstart — the same first purchase, in cURL and TypeScript.
- Purchases — decisions, reason codes and approval escalations in full.
- Webhooks — the event catalogue, signature scheme and delivery behaviour.
- Examples — complete integrations, with and without the SDK.
- API reference — every endpoint the SDK calls, and the authority on all of it.