TypeScript SDK
A thin, fully typed client over the REST API. Request types are the same schemas the server validates against, so the SDK cannot describe a request the API would reject as malformed.
npm install @sreemail/sdkSending
import { Sreemail } from "@sreemail/sdk";
const sreemail = new Sreemail({ apiKey: process.env.SREEMAIL_API_KEY! });
const { id } = await sreemail.emails.send({
from: "hello@yourdomain.com",
to: "customer@example.com",
subject: "Your receipt",
text: "Thanks for your order.",
});Idempotency
Pass a key whenever a retry must not send twice. The key is remembered for 24 hours and replays the original response rather than sending again.
await sreemail.emails.send(message, { idempotencyKey: `order-${orderId}` });Errors
Every failure throws a SreemailError carrying the API’s machine-readable code, because the useful branches are per-code rather than per-message. Retryable failures — 429s, 5xx, connection resets — are retried automatically with backoff that honours Retry-After; by the time an error reaches you, retrying has already been tried.
import { SreemailError } from "@sreemail/sdk";
try {
await sreemail.emails.send(message);
} catch (error) {
if (error instanceof SreemailError) {
if (error.code === "domain_not_verified") await promptOwnerToFixDns();
if (error.code === "suppressed_recipient") await markUnreachable();
console.error(error.code, error.message, error.requestId);
}
}Options
baseUrl points the client at a different deployment. maxRetries (default 3) and timeout (default 30s) control the retry behaviour. fetch injects your own implementation — useful in tests, and required in runtimes with a non-standard global.