@nozle-js/node requires Node.js 18 or later and uses the built-in Fetch API. It ships ESM and CommonJS (import and require both work).
Entity subscription APIs are introduced in 0.5.0.
Version
0.13.1 changes wrapOpenAI() and wrapAnthropic() to return a client view instead of patching the client you pass in; use the returned client. See Client wrappers. Version 0.13.0 adds NozleApiError on every failed call (with requestId and retryAfter), opt-in retries, the host option, an optional apiKey that reads NOZLE_SECRET_KEY, captureFetch() and recordUsage(), Core usage reads, the invoices, alerts and webhooks namespaces, and createBillingHandler() for the React billing hooks. Version 0.12.0 adds billingConfiguration to customers.upsert(). Version 0.11.0 sends Feature Events through the Go Engine endpoint. Version 0.10.0 adds NozleApiError with status, code and hasCode(), richer checkout result types, and no longer sends feature from checkAndDeduct(). Version 0.9.1 fixes Feature Event timestamp serialization, including events created by the OpenAI and Anthropic wrappers. Version 0.9.0 introduced subscription options, signed quotes, pending-change withdrawal, and scoped checkout recovery. See subscription self-service and the release notes.Create a client
Configuration
The client defaults to the public service bases under
https://api.nozle.app. For a local or self-hosted deployment behind one proxy, set host. Set baseUrl or eventsUrl only when the two services live at unrelated addresses; each one you set wins over host. If you set only one of them, the other service still uses host (by default production), so set host too. Trailing slashes are removed automatically.
Verify connectivity
API surface
API and billing
Namespaces
The package also exports
wrapOpenAI() and wrapAnthropic() for token usage capture; see LLM auto-capture. openai and @anthropic-ai/sdk are optional peer dependencies. From 0.13.0 it also exports createBillingHandler(), the backend route for the React billing hooks, and createWebhookHandler(), which verifies webhooks.
Key behavior
- Billing mutations and settlement transitions require an API key beginning with
sk_. - Entity mutations, credit transfers, and
usage.track()reject publishablepk_keys. - Mutation idempotency keys are caller-supplied and limited to 255 bytes.
- Product-credit amounts are exact decimal strings, not JavaScript numbers.
- Failed HTTP responses reject with a
NozleApiError(status,code,requestId,retryAfter), which extendsError. Its message contains the operation and HTTP status. See errors and retries. - Every attempt uses
AbortSignal.timeout(timeout). The SDK does not retry unless you setmaxRetries.
Production pattern
Create one client per process and reuse it:customerId, Entity IDs, plan codes, return origins, or idempotency keys blindly from a browser. Derive or validate them in your trusted backend.