@nexsend/sdk
v0.2.0
Published
Isomorphic SDK for the nexSend transactional email API.
Maintainers
Readme
NexSend
The official SDK for NexSend — the Cloudflare-native transactional email
platform. Send transactional email from anywhere your code runs: Cloudflare
Workers, Node 18+, Deno, Bun, or the browser. Zero dependencies — it only needs
a fetch.
Before you start
The SDK talks to your NexSend account, so set that up first:
- Create an account → https://dev.nexb.me/ Sign up (passwordless magic link), then sign in to the dashboard.
- Verify a sending domain. In the dashboard, add the domain you'll send
fromand follow the DNS steps until it shows verified. You can only send from a domain your account has verified. - Create an API key. Generate a key in the dashboard — it's shown once,
so copy it. This is the
apiKeyyou pass to the SDK. - Read the docs. The full guides, request/response reference, and live examples live in the dashboard under Docs (https://dev.nexb.me/docs).
Once your domain is verified and you have an API key, install the SDK and send.
Install
npm install @nexsend/sdk
# or
pnpm add @nexsend/sdkQuick start
import { NexSend } from "@nexsend/sdk";
const ns = new NexSend({ apiKey: process.env.NEXSEND_API_KEY });
const { data, error } = await ns.emails.send({
from: "[email protected]", // must be a verified domain
to: "[email protected]",
subject: "Hello",
html: "<p>Hi there</p>",
});
if (error) {
console.error(error.code, error.message);
} else {
console.log("queued", data.id, data.status);
}Every method returns { data, error } — it never throws on an API error
(only on network/programmer errors). Inspect error for { code, message, status }.
Options
new NexSend({
apiKey: "cm_live_...", // required — created in the dashboard
baseUrl: "https://...", // default https://dev-api.nexb.me
maxRetries: 2, // 429/5xx retries for idempotent requests
fetch: globalThis.fetch, // custom fetch (e.g. undici)
});CLI (npx)
The same package ships a CLI, so you can send mail and inspect your account
without writing any code. Authenticate with the NEXSEND_API_KEY env var (or
pass --api-key):
# Send an email
NEXSEND_API_KEY=cm_live_... npx @nexsend/sdk send \
--from [email protected] \
--to [email protected] \
--subject "Hello" \
--text "Hi there"
# Inspect your account
npx @nexsend/sdk emails list --limit 5
npx @nexsend/sdk emails get cm_email_123
npx @nexsend/sdk domains list
npx @nexsend/sdk api-keys list
# Machine-readable output
npx @nexsend/sdk emails list --jsonRun npx @nexsend/sdk --help for the full command list. Every command exits
non-zero on error.
API surface
| Resource | Methods |
| ------------- | ---------------------------------------------------- |
| emails | send, get, list |
| domains | create, list, verify, setupDns, delete |
| apiKeys | create, list, revoke |
| suppressions| list, remove |
Idempotent sends
send only retries on 429/5xx when you pass an idempotency key:
await ns.emails.send(input, { idempotencyKey: crypto.randomUUID() });Links
- Dashboard & sign-up: https://dev.nexb.me/
- Docs: https://dev.nexb.me/docs
License
MIT
