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

# Generate your API key

> Learn how to create and manage Nuntly API keys. Use your key to authenticate REST API requests, SDK calls, and SMTP connections.

API keys authenticate your requests to the Nuntly API and SMTP server. Every key starts with `ntly_`.

## Create an API key

<Steps>
  <Step title="Go to API keys">
    In the dashboard, go to **API Keys**.

    <img src="https://mintcdn.com/nuntly/-QSvC6ZwmN9m-zHc/images/api-keys/api-keys-button.png?fit=max&auto=format&n=-QSvC6ZwmN9m-zHc&q=85&s=374f851ced12059cc1c0d1a46bffe996" alt="The API keys page showing a button to create a new key" className="rounded-lg w-full max-w-2xl mx-auto transition-transform duration-200 hover:scale-105" width="2624" height="442" data-path="images/api-keys/api-keys-button.png" />
  </Step>

  <Step title="Name your key and choose a permission">
    Enter a descriptive name for the key (for example, "Production" or "Development") and select a permission type.

    <img src="https://mintcdn.com/nuntly/-QSvC6ZwmN9m-zHc/images/api-keys/api-keys-dialog.png?fit=max&auto=format&n=-QSvC6ZwmN9m-zHc&q=85&s=6ec3dcfdbcc9efadcf5d8e1a2c15dea9" alt="The API keys dialog showing the name input field, permission selector, and the create button" className="rounded-lg w-full max-w-lg mx-auto transition-transform duration-200 hover:scale-105" width="984" height="672" data-path="images/api-keys/api-keys-dialog.png" />

    See [Permissions](#permissions) below for details on each permission type.
  </Step>

  <Step title="Create the key">
    Click **Create API Key**.

    <img src="https://mintcdn.com/nuntly/-QSvC6ZwmN9m-zHc/images/api-keys/api-keys-created.png?fit=max&auto=format&n=-QSvC6ZwmN9m-zHc&q=85&s=c0a3b098a4fe076ef55cdfe32962bb02" alt="The API key created dialog showing the API key value and a copy button" className="rounded-lg w-full max-w-lg mx-auto transition-transform duration-200 hover:scale-105" width="1086" height="1024" data-path="images/api-keys/api-keys-created.png" />

    The API key value is displayed once at creation. Copy it before closing. You will not be able to retrieve it again.

    <Warning>
      Store your API key in an environment variable or a secrets manager. Never hardcode it in your source code or commit it to version control.
    </Warning>
  </Step>
</Steps>

## Permissions

Each API key has a permission type that controls which endpoints it can access. You choose the permission when creating the key, and you can change it later from the edit panel.

### Full access

Grants read and write access to all API resources: emails, domains, webhooks, API keys, and organization (read only).

Use this for backend services that need complete API access.

### Sending only

Restricts the key to sending emails only. The key cannot read emails, manage domains, configure webhooks, or perform any other operation.

Use this for services that only need to send transactional emails, such as a notification service or a third-party integration.

### Domain restriction

When using the **Sending only** permission, you can optionally restrict the key to specific verified domains. The key can then only send emails from those domains.

If no domains are selected, the key can send from any verified domain in your organization.

### With the REST API

Set the `permission` field when creating an API key through the API:

```bash theme={null}
curl -X POST https://api.nuntly.com/api-keys \
  -H 'Authorization: Bearer ntly_your_api_key_here' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Notification service",
    "permission": "sendingAccess",
    "domainIds": ["dns_01kh9g8dnk2d6k81q28tvjtw02"]
  }'
```

Available values for `permission`:

* `fullAccess` - full read and write access to all resources
* `sendingAccess` - can only send emails

The `domainIds` field is optional and only applies to `sendingAccess` keys. Pass an array of domain IDs to restrict which domains the key can send from.

## Use your API key

### With the SDK

Pass your key when initializing the Nuntly client:

```typescript theme={null}
import { Nuntly } from '@nuntly/sdk';

const nuntly = new Nuntly({
  apiKey: process.env.NUNTLY_API_KEY,
});
```

See [SDK setup](/docs/guides/requirements) for full installation instructions.

### With the REST API

Include the key in the `Authorization` header of every request:

```bash theme={null}
curl -X POST https://api.nuntly.com/emails \
  -H 'Authorization: Bearer ntly_your_api_key_here' \
  -H 'Content-Type: application/json' \
  -d '{ ... }'
```

### With SMTP

Use your API key as the SMTP password. See [Send emails with SMTP](/docs/guides/send-emails-with-smtp) for the full configuration.

## Best practices

* Use a separate key for each environment (development, staging, production)
* Use **Sending only** keys for services that do not need to read data or manage configuration
* Restrict sending keys to specific domains when possible to limit the blast radius if a key is compromised
* Store keys in environment variables. Never put them in source code
* If a key is compromised, delete it immediately and create a new one

<CardGroup cols={2}>
  <Card title="Authentication" icon="lock" href="/docs/api-reference/authentication">
    How API authentication works
  </Card>

  <Card title="Send your first email" icon="paper-plane" href="/docs/guides/send-your-first-email">
    Get started with the Nuntly API
  </Card>

  <Card title="Idempotency keys" icon="rotate" href="/docs/guides/idempotency">
    Prevent duplicate email sends
  </Card>

  <Card title="Sending domains" icon="globe" href="/docs/guides/sending-domains">
    Set up and verify your sending domains
  </Card>
</CardGroup>
