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

# Authentication

> Secure your API requests with API key authentication

The LeadMagic API uses **API key authentication** to secure all requests. Your API key must be included in the header of every request.

## Getting Your API Key

**1. Log in to LeadMagic**

Visit [app.leadmagic.io](https://app.leadmagic.io/sign-in) and sign in to
your account.

**2. Navigate to Account Settings**

Click on your profile icon and select "Account Profile" or "API Keys".

**3. Copy your API Key**

Your API key will be displayed. Click to copy it to your clipboard.

> [!WARNING]
>
> Treat your API key like a password. Never share it publicly.

## Using Your API Key

Include your API key in the `X-API-Key` header of every request:

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST 'https://api.leadmagic.io/v1/people/email-validation' \
  -H 'Content-Type: application/json' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -d '{"email": "test@example.com"}'
```

```javascript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
const response = await fetch(
  "https://api.leadmagic.io/v1/people/email-validation",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": process.env.LEADMAGIC_API_KEY,
    },
    body: JSON.stringify({ email: "test@example.com" }),
  },
);
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
import requests

response = requests.post(
    'https://api.leadmagic.io/v1/people/email-validation',
    headers={
        'Content-Type': 'application/json',
        'X-API-Key': os.environ['LEADMAGIC_API_KEY']
    },
    json={'email': 'test@example.com'}
)
```

## Authentication Errors

If your API key is missing or invalid, you'll receive a `401 Unauthorized` response:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errors": [
    {
      "type": "https://api.leadmagic.io/errors/invalid_api_key",
      "title": "Invalid API key. The key does not exist or is incorrect.",
      "status": 401,
      "code": "invalid_api_key"
    }
  ],
  "meta": {
    "request_id": "req_abc123",
    "timestamp": "2026-03-05T12:00:00.000Z"
  }
}
```

> [accordion] Common authentication issues
>
> | Issue | Solution |
> | - | - |
> | Missing header | Ensure `X-API-Key` header is included |
> | Header name variation | Header names are case-insensitive; use `X-API-Key` as canonical |
> | Invalid key | Verify your key in the dashboard |
> | Expired key | Regenerate your API key |

## Security Best Practices

> [card] Use Environment Variables
>
> Store your API key in environment variables, not in your code.
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> export LEADMAGIC_API_KEY="your_key_here"
> ```

> [card] Server-Side Only
>
> Never expose your API key in client-side JavaScript or mobile apps.

> [card] Use Secrets Managers
>
> For production, use AWS Secrets Manager, HashiCorp Vault, or similar.

> [card] Rotate Regularly
>
> Regenerate your API key periodically and if you suspect compromise.

> [!WARNING]
>
> **When team members leave:** Always regenerate your API key when employees with access leave your organization. This prevents unauthorized access.

## Checking Your Credits

> [!TIP]
>
> See the [Credits & Pricing](https://leadmagic.io/docs/v1/credits.md) page for details on monitoring your balance, the [Check Credits endpoint](https://leadmagic.io/docs/v1/reference/check-credits.md), and subscription plans.

## Regenerating Your API Key

If you need to regenerate your API key:

**1. Go to Account Settings**

Navigate to your Account Profile in the LeadMagic dashboard.

**2. Click Regenerate**

Find the API Key section and click "Regenerate Key".

**3. Update your applications**

Replace the old key in all your applications with the new one.

> [!WARNING]
>
> The old key will stop working immediately after regeneration.

## Next Steps

> [card] [Making API Calls](https://leadmagic.io/docs/v1/making-api-calls.md)
>
> Learn the basics of making requests to our API.

> [card] [Email Validation](https://leadmagic.io/docs/v1/reference/email-validation.md)
>
> Try our most popular endpoint.


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