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

# Authentication

> Configure your Paubox API credentials for the Node.js SDK.

## Obtain your credentials

The Email API service requires two credentials:

* **API key**: a secret token that authenticates your requests
* **Username**: your Paubox API endpoint username (not your login email)

Both are available in the [Paubox dashboard](https://next.paubox.com) under **API Credentials**.

## Option 1: Environment variables (recommended)

Create a `.env` file in your project root:

```bash theme={null}
API_KEY=YOUR_API_KEY
API_USERNAME=YOUR_USERNAME
```

The SDK loads these automatically via `dotenv`. Call the factory with no arguments:

```javascript theme={null}
const pbMail  = require('paubox-node');
const service = pbMail.emailService();
```

## Option 2: Direct configuration

Pass credentials explicitly to the factory:

```javascript theme={null}
const service = pbMail.emailService({
  apiKey:      'YOUR_API_KEY',
  apiUsername: 'YOUR_USERNAME'
});
```

The service factory throws immediately if either credential is missing, so errors surface at startup rather than at send time.

The SDK sets the `Authorization` header automatically on every request:

```
Authorization: Token token=YOUR_API_KEY
```

## Forms service

`formService` requires no credentials:

```javascript theme={null}
const formsService = pbMail.formService();
```

## Security notes

* Add `.env` to your `.gitignore` — never commit credentials to source control.
* In production, prefer your platform's secret management (environment variables injected by your hosting provider) over `.env` files.
