Configure the Lumail TypeScript SDK client, API key, base URL, and runtime environment.
Create a Lumail client once in server-side code and reuse it wherever you call the API.
import { Lumail } from "lumail";
export const lumail = new Lumail({
apiKey: process.env.LUMAIL_API_KEY!,
});
Create an API token in Settings > API Tokens in your Lumail dashboard. Store it as a server-side environment variable.
LUMAIL_API_KEY=lum_your_api_token_here
Never expose this token in browser code. Call Lumail from a server component, route handler, server action, serverless function, job worker, or backend service.
The SDK defaults to the production API. Set baseUrl only when you are targeting another Lumail environment.
const lumail = new Lumail({
apiKey: process.env.LUMAIL_API_KEY!,
baseUrl: "https://lumail.io/api",
});
Use the SDK in trusted server-side code:
// app/api/signup/route.ts
import { lumail } from "@/lib/lumail";
export async function POST(request: Request) {
const body = await request.json();
const { subscriber } = await lumail.subscribers.create({
email: body.email,
tags: ["signup"],
triggerWorkflows: true,
});
return Response.json({ subscriber });
If you are adding a route to this codebase, follow the project API route conventions and use the existing route validation helpers.