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

# Authentication

> The two credentials the API accepts, and which endpoints take which.

The API accepts two kinds of credential.

| Credential | How you get it | How you send it | Lifetime |
| - | - | - | - |
| Session token (JWT) | `POST /v1/auth/signup` or `POST /v1/auth/login` | `Authorization: Bearer <token>` | 7 days |
| API key | `POST /v1/keys` or the account page | `X-API-Key: <key>` | Until you revoke it |

## Which endpoints take which

| Endpoints | Session token | API key |
| - | - | - |
| `/v1/auth/me`, `/v1/keys` | Yes | No |
| `/v1/datasets` and below | Yes | Yes |

Account and key management need a session token, so a leaked API key cannot be used to create more keys.

## Session tokens

Log in with your email and password:

```bash
curl -X POST https://api.datachad.xyz/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "ada@lab.example", "password": "..."}'
```

```json
{
  "token": "eyJhbGciOiJIUzI1NiJ9...",
  "user": { "id": 1, "email": "ada@lab.example", "name": "Ada Lovelace", "organization": "Example Lab", "created_at": "2026-11-17 14:00:46" }
}
```

When a token expires, the API answers `401`. Log in again to get a new one.

## API keys

API keys start with `dc_live_`. Use them from servers, notebooks and training jobs:

```bash
curl https://api.datachad.xyz/v1/datasets -H "X-API-Key: dc_live_..."
```

`Authorization: Bearer dc_live_...` also works, for HTTP clients that only support bearer auth.

> [!WARNING]
>
> Do not put API keys in browser code or commit them to a repository. If a key leaks, revoke it and create a new one.
