# Authentication

> Authenticate every request with a secret API key sent as a bearer token.

Send your API key in the `Authorization` header of every request, as a bearer token:

**cURL**

```bash
curl https://api.camelpayment.com/v1/payments/pay_01JBX7Q2M4N8K5R6T9V3W1Y0ZA \
  -H "Authorization: Bearer $CAMEL_API_KEY"
```

**Node.js**

```javascript
const response = await fetch('https://api.camelpayment.com/v1/payments/pay_01JBX7Q2M4N8K5R6T9V3W1Y0ZA', {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${process.env.CAMEL_API_KEY}`
  }
});
const data = await response.json();
```

**Python**

```python
import os
import requests

response = requests.get(
    "https://api.camelpayment.com/v1/payments/pay_01JBX7Q2M4N8K5R6T9V3W1Y0ZA",
    headers={
        "Authorization": f"Bearer {os.environ['CAMEL_API_KEY']}",
    },
)
data = response.json()
```

## API keys

Create and revoke keys under **Developers** in the dashboard. Each key belongs to one project and one environment:

| Prefix | Environment |
| --- | --- |
| `pay_test_` | Sandbox |
| `pay_live_` | Production |

The key alone decides the environment; there is no header or parameter for it. See [Sandbox and production](https://camelpayment.com/docs/environments.md).

## Keep keys secret

- The full key is shown once, when you create it. Camel stores only a keyed hash.
- Use keys only from your server. Never put them in a browser, a mobile app, or a public repository.
- If a key leaks, create a new one, deploy it, and revoke the old one. Revoked keys stop working at once.

## Errors

A missing, malformed, or revoked key returns `401`:

**401 Unauthorized**

```json
{
  "detail": "Invalid API key"
}
```

> **Note**
>
> The **Request log** in the dashboard shows the requests made with each key, for 30 days.
