Create a Lumail client once in server-side code and reuse it wherever you call the API.

```typescript
import { Lumail } from "lumail";

export const lumail = new Lumail({
  apiKey: process.env.LUMAIL_API_KEY!,
});
```

## API Key

Create an API token in **Settings > API Tokens** in your Lumail dashboard. Store it as a server-side environment variable.

```bash
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.

## Base URL

The SDK defaults to the production API. Set `baseUrl` only when you are targeting another Lumail environment.

```typescript
const lumail = new Lumail({
  apiKey: process.env.LUMAIL_API_KEY!,
  baseUrl: "https://lumail.io/api",
});
```

## Runtime Placement

Use the SDK in trusted server-side code:

```typescript
// 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.

## Related

- [API Tokens](/docs/api-reference/api-tokens)
- [SDK Introduction](/docs/sdk/introduction)
- [Errors and Retries](/docs/sdk/errors-retries)
