Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.lettr.com/llms.txt

Use this file to discover all available pages before exploring further.

The official lettr package is a type-safe API client for Node.js and TypeScript. It covers sending, templates, domains, webhooks, audience, and campaigns — with no thrown exceptions: every method returns a Result you destructure into data and error.

Requirements

Install the Package

npm install lettr
# or: pnpm add lettr / yarn add lettr / bun add lettr

Create a Client

import { Lettr } from "lettr";

const client = new Lettr(process.env.LETTR_API_KEY!);
Store your API key in an environment variable, never in source. API keys use the lttr_ prefix followed by 64 hexadecimal characters.

The Result Pattern

Every SDK method returns a Result<T> — a discriminated union of { data, error }. The SDK never throws for API or network failures; you check error instead:
const { data, error } = await client.emails.send({
  from: "you@yourdomain.com",
  to: ["recipient@example.com"],
  subject: "Hello",
  html: "<p>Hi there</p>",
});

if (error) {
  // error.type is "validation" | "api" | "network"
  console.error(error.type, error.message);
  return;
}

console.log(data.request_id); // narrowed to non-null here
Because data and error are discriminated, TypeScript narrows data to non-null only after you’ve handled error. See Sending Emails → Error Handling for the full error model.

Verify Your Setup

const { data, error } = await client.authCheck();

if (error) {
  console.error("API key invalid:", error.message);
} else {
  console.log("Authenticated, team:", data.team_id);
}

Available Resources

client.emails;     // send, schedule, list, get
client.templates;  // manage Lettr templates
client.domains;    // manage sending domains
client.webhooks;   // manage webhook endpoints
client.audience;   // lists, contacts, topics, properties, segments
client.campaigns;  // list, send, and schedule campaigns
client.projects;   // list projects

What’s Next

Sending Emails

Send HTML, text, and template emails

Next.js

Use the SDK in Next.js