> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailglyph.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Install and initialize the MailGlyph Node.js SDK.

Use the official Node.js SDK to call the MailGlyph API from server-side apps.

* npm package: [mailglyph](https://www.npmjs.com/package/mailglyph)
* GitHub repository: [MailGlyph Node SDK](https://github.com/MailGlyph/mailglyph-node)

## Prerequisites

Before you start, make sure you have:

* A MailGlyph **secret API key** (`sk_...`) for server-side API requests
* A MailGlyph **public API key** (`pk_...`) for event tracking (`/v1/track`)
* At least one **verified sending domain** for email sending

Setup links:

* [MailGlyph API keys dashboard](https://app.mailglyph.com/api-keys)
* [MailGlyph domains dashboard](https://app.mailglyph.com/domains)
* [API keys guide](https://docs.mailglyph.com/guides/api-keys.md)
* [Domain verification guide](https://docs.mailglyph.com/guides/verifying-domains.md)

## Install

```bash theme={null}
npm install mailglyph
```

```bash theme={null}
yarn add mailglyph
```

## Initialize clients

Create one SDK client for your secret key and one for your public key:

```ts theme={null}
import MailGlyph from 'mailglyph';

const secretClient = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);
const publicClient = new MailGlyph(process.env.MAILGLYPH_PUBLIC_KEY as string);
```

Set the environment variables:

```bash theme={null}
export MAILGLYPH_SECRET_KEY="sk_your_secret_key"
export MAILGLYPH_PUBLIC_KEY="pk_your_public_key"
```

## Configure base URL and timeout

Use this when testing against staging or local environments:

```ts theme={null}
import MailGlyph from 'mailglyph';

const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string, {
  baseUrl: 'https://api.mailglyph.com',
  timeout: 30_000
});
```

## Check key type at runtime

The SDK exposes `keyType` so you can enforce usage in your app:

```ts theme={null}
if (secretClient.keyType !== 'secret') {
  throw new Error('Expected a secret key client.');
}

if (publicClient.keyType !== 'public') {
  throw new Error('Expected a public key client.');
}
```

## Next pages

* [Emails examples](https://docs.mailglyph.com/sdks/nodejs/emails.md)
* [Email Validation examples](https://docs.mailglyph.com/sdks/nodejs/email-validation.md)
* [Events examples](https://docs.mailglyph.com/sdks/nodejs/events.md)
* [Contacts examples](https://docs.mailglyph.com/sdks/nodejs/contacts.md)
* [Segments examples](https://docs.mailglyph.com/sdks/nodejs/segments.md)
* [Campaigns examples](https://docs.mailglyph.com/sdks/nodejs/campaigns.md)
* [Error handling](https://docs.mailglyph.com/sdks/nodejs/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.