Skip to main content

Quickstart

1. Install the SDK​

pnpm add @kazuni/sdk
npm i @kazuni/sdk
# or
yarn add @kazuni/sdk

2. Verify a sending domain​

Before you can send, the from address must be on a domain you've verified with Kazuni. Do this once, in the dashboard - see Sending Domains for the full walk through, including what the DNS records look like and how long they take to propagate.

3. Create an API key​

In the Kazuni dashboard, go to Settings > API Keys and create a key with the Send email permission. The full key is shown once, at creation - copy it somewhere safe. See Authentication for the difference between live and test keys.

4. Send an email​

import { Kazuni } from "@kazuni/sdk";

const kazuni = new Kazuni(process.env.KAZUNI_API_KEY!);

const result = await kazuni.send.email({
from: "Acme <hello@acme.example>",
to: "customer@example.com",
subject: "Welcome to Acme",
html: "<p>Thanks for signing up.</p>",
text: "Thanks for signing up.",
});

console.log(result.id, result.status); // "email_...", "queued"

to accepts exactly one recipient address per call. A 202 from the API, or a resolved promise from the SDK, means Kazuni accepted the email for delivery, not that it has been delivered - see Sending Email for what status: "queued" does and doesn't mean.

5. Handle failures​

Every failed request throws a KazuniError:

import { Kazuni, KazuniError } from "@kazuni/sdk";

try {
await kazuni.send.email({
from: "hello@acme.example",
to: "not-an-email",
subject: "Hi",
html: "<p>Hi</p>",
});
} catch (error) {
if (error instanceof KazuniError) {
console.error(error.message, error.status, error.code, error.requestId);
}
}

See Errors for the full field reference and what triggers each status code.

Next steps​