npayload
npayload makes your systems autonomous, on one platform. This package is the
SDK and the CLI for the whole platform: np.events, np.pipes, np.primus
(AI agents), np.connect and np.feed.
npm install @npayload/sdk
The package ships the SDK, the npayload CLI (also callable as np) and its MCP server for coding agents.
Quickstart
npx @npayload/sdk init # provision credentials and scaffold a project (device flow)
# or, non-interactive:
npx @npayload/sdk login --org <org> --app <app> --env sandbox
import { NPayload } from "@npayload/sdk";
// The credentials `npx @npayload/sdk init` wrote into your project's .env, on npayload's production API
// (on another npayload deployment, pass its API as `baseUrl`: see Transports below)
const np = await NPayload.connect({ clientId: process.env.NPAYLOAD_CLIENT_ID! });
// Publish an event to a channel, by the channel's slug
await np.events.publish("orders", { orderId: "ord_123", total: 4200 }, { routingKey: "order.confirmed" });
// Manage channels, subscriptions, pipes and agents the same way
const channels = await np.events.channels.list();
Transports
The live connection (NPP), npayload's own signed protocol, is the default
transport for publish, subscribe and delivery. Every frame is signed (Ed25519)
with your app's key. HTTP/JSON is a permanent opt-in:
import { NPayload } from "@npayload/sdk";
const np = await NPayload.connect({ clientId: process.env.NPAYLOAD_CLIENT_ID!, transport: "http" }); // explicit opt-in
// or NPAYLOAD_TRANSPORT=http, or `npx @npayload/sdk --transport http` on the CLI
By default the SDK and the CLI reach npayload's hosted service: its API at
api.npayload.com, which also serves sign-in, and the live connection at
npp.npayload.com. Nothing writes those defaults into your .env.
To use another npayload deployment, a private one or a local one while you
develop, name its API, its sign-in host and its live connection together:
- In code, with the
baseUrl, authUrl and edgeUrl options of
NPayload.connect and new NPayload.
- In the shell that runs the CLI (
npx @npayload/sdk init, npx @npayload/sdk login or any other command), with
NPAYLOAD_API_URL, NPAYLOAD_AUTH_URL and NPAYLOAD_EDGE_URL. The CLI reads
your project's .env to see which deployment you are on, but dials only what
the shell exports, so export them.
On npayload's production estate, with no auth host named, every np
command gets its token from the production API's own token door,
https://api.npayload.com/oauth/token; with another API and no auth
host named, from that API.
- For a new project,
npx @npayload/sdk init --edge-url <url> writes that live
connection into its .env; a .env that already holds your credentials is
kept as it is.
One run, one deployment. As soon as any address you set is outside
npayload.com (a look-alike such as evilnpayload.com or
api.npayload.com.evil.test is outside), nothing the run sends goes to the
hosted service: no token request, sign-in, publish, subscribe or management
call, and no redirect there is followed. Anything that would go there is
refused before a request is sent, with a TransportUnavailableError in code
and the code TRANSPORT_UNAVAILABLE printed by np; the error names what to
set, and nothing is retried after it.
There is no silent fallback between transports: if the live connection is
selected (or defaulted) and unavailable, calls fail with a typed
TransportUnavailableError. The details are in the docs:
https://docs.npayload.com/docs/concepts/transports.
Webhooks
import { WebhookHandler } from "@npayload/sdk";
const webhooks = new WebhookHandler();
// The raw request body, the request's headers and your endpoint's signing secret
const event = await webhooks.constructEvent(rawBody, req.headers, endpointSecret);
During development, pair a local listener with a synthetic trigger:
npx @npayload/sdk listen --forward http://localhost:3000/api/webhooks # temporary subscription, forwarded to your handler
npx @npayload/sdk trigger order.confirmed # fire a sample event at it
Networks and fingerprints
npayload serves a machine call only when it comes from a network its app
environment declares, and, once your API key's instances are enrolled, only
when it presents an enrolled key fingerprint. An administrator declares the
networks in the dashboard under Settings > Security > Networks.
An instance's fingerprint is the RFC 7638 thumbprint of its DPoP public key.
Keep the key to keep the fingerprint: NPayload.connect() uses the key you pass
as dpopPrivateJwk, else the one in NPAYLOAD_DPOP_PRIVATE_JWK (which
npx @npayload/sdk init writes into your .env), else a new one on every start.
import { NPayload, NPayloadSourceNotAllowedError, NPayloadFingerprintNotEnrolledError } from "@npayload/sdk";
const np = await NPayload.connect({ clientId: process.env.NPAYLOAD_CLIENT_ID! });
const fingerprint = await np.fingerprint(); // the value the dashboard lists under the API key
try {
await np.enroll(); // the first connection, made now, while the key's enrollment window is open
} catch (err) {
if (err instanceof NPayloadSourceNotAllowedError) {
// this machine's network is not declared for the environment (err.reason: "not_allowed" | "not_declared")
} else if (err instanceof NPayloadFingerprintNotEnrolledError) {
// the window is closed and err.fingerprint is not enrolled for this API key
} else {
throw err;
}
}
A call refused for its network is tried once more on a fresh token, then
rejects with NPayloadSourceNotAllowedError; a call refused for its fingerprint
rejects with NPayloadFingerprintNotEnrolledError at once. Neither error
carries your address. The np CLI prints the address this machine reaches
npayload from, read on your machine and sent nowhere, with the entry to add.
CLI highlights
| Command |
What it does |
npx @npayload/sdk init / npx @npayload/sdk login |
Provision credentials (device flow or flags); stored in the OS keychain |
npx @npayload/sdk pull / npx @npayload/sdk deploy |
Config as code: secrets always become {{ secrets.… }} references, never literals |
npx @npayload/sdk validate |
Fails on raw secret values in config |
npx @npayload/sdk listen |
Forward live webhooks to localhost with signature headers intact |
npx @npayload/sdk trigger <event-type> |
Fire a sample event (catalogue example or --payload-file) |
npx @npayload/sdk tail <channel> |
Watch events arrive on a channel, live |
npx @npayload/sdk doctor |
Environment, network and auth diagnostics |
Requirements
Node.js 22.23.4 or later on the 22 line, 24.22.1 or later on the 24 line, or 26.12.1 and later. These are the
first releases with the fixes of the Node.js security release of October 2026.
Node.js 20 and older are end-of-life and are not supported. Check with node --version.
Documentation
License
MIT, see LICENSE.