Skip to main content
@getnexorai/sdk provides two separate surfaces:
  • a server-side JavaScript client for 16 public REST operations;
  • an advanced browser widget for Web Chat.
This reference is pinned to @getnexorai/sdk v0.1.44. It does not claim to wrap the complete REST API.
Keep the two key types separate. Server code uses a secret REST key loaded from an environment variable. Browser code may use only the browser-visible, non-secret Web Chat key that starts with nxr_pub_.

Install for server use

The SDK requires Node.js 18 or later.
The package exposes the default singleton and named exports from its root. It also exposes chat types and helpers through @getnexorai/sdk/chat.

Server quick start

Set NEXOR_API_KEY in your server’s secret store. Do not commit it.
createLead and createLeadsBulk always send skip_first_message: true. Creating a lead through these helpers does not, by itself, mean the Agent immediately sends its ordinary first cadence message. For dependency injection or multi-tenant server code, create independent clients instead of changing the singleton:

REST methods

All 16 methods below are available on the initialized default export and on NexorClient. Use the REST API reference for endpoints the SDK does not wrap.

HTTP behavior

Set maxRetries: 0 for a non-idempotent operation when repeating it could duplicate an effect. Passing idempotencyKey adds an Idempotency-Key header; it does not, on its own, guarantee that every endpoint deduplicates the request.

Handle errors

The SDK exports NexorError, NexorAPIError, NexorAuthError, NexorValidationError, and NexorNetworkError.
The v0.1.44 package currently sends nexor-sdk-js/0.1.0 in its Node.js User-Agent. Do not use that header value to determine the installed package version.

Browser widget

For most websites, use the smaller hosted Web Chat loader. It does not require npm and its snippet comes directly from the Agent’s Install section. Use the SDK widget when you need programmatic control through initChat, callbacks, or runtime configuration. The IIFE build exposes a global named Nexor.
Never place an nxr_live_ REST key in HTML, a browser bundle, a screenshot, or a public repository. A browser key must start with nxr_pub_. Configure the intended domains in the Agent’s Web Chat settings; that allowlist applies to the normal widget transport, not as an authorization guarantee for every optional SDK flow.

Callbacks and widget handle

Pass callbacks to initChat when the host page needs lifecycle or conversation events. initChat returns a handle with these methods:
send(text) resolves after the message is queued, not after Nexor returns or paints the reply. Use onMessage to observe the later bot message and onError to observe a failed turn.

Widget request flow

The widget’s current network flow is not the older /api/public/chat path documented in previous SDK notes.
In SDK v0.1.44, requestContact attempts POST /api/public/leads. Do not enable this optional flow on an untrusted public site until Nexor completes backend hardening for contact requests. Allowed domains cover the normal widget transport; they are not an authorization guarantee for requestContact. Use the capture form, which persists visitor details through POST /api/widget/v1/visitor, or create the lead from a trusted server integration.
The two configuration routes are alternatives: initChat chooses the public route at top level and the widget-scoped route in an iframe. Before visitor persistence or a chat turn, it requests a fresh proof-of-work challenge and, when one is available and solved, attaches the result. The configuration, proof-of-work, turn, pending, visitor, and telemetry routes are the normal widget transport and have route-specific request and session controls. Use the widget instead of calling them directly. The requestContact row is excluded from that assurance.

Reproduce the offline browser smoke

The repository smoke rebuilds dist/nexor.iife.js from the pinned SDK checkout, records its SHA-256 digest, and evaluates it in an empty JSDOM page. It replaces fetch with a closed mock that rejects every unrecognized origin or route, then verifies the global export, mounted DOM, top-level configuration request, proof of work when available, POST /api/widget/v1/turn, telemetry, and rendered reply. It also checks, without exercising the conditional flows, that both language pages list the embedded configuration, pending mailbox, visitor persistence, and public contact-request routes, and that the unsupported requestContact path carries the required warning. Prepare the pinned SDK worktree once, then run the smoke without Nexor credentials or network calls:
The final command rebuilds the pinned bundle and fails if the checkout, bundle digest, browser key prefix, routes, proof of work, reply, or documented snippets drift.
Last modified on September 8, 2026