# Tokens & Auth

> Create, list and revoke API tokens for remote clients and agents.

---

LLMS index: [llms.txt](/llms.txt)

---

API tokens authenticate clients that do not connect from the loopback address.
They are shown **once** at creation; only a SHA-256 hash is stored.

## The token object

```json
{
  "id": "3f6a1c9e",
  "name": "agent",
  "createdAt": 1764550000,
  "lastUsedAt": 1764553600
}
```

| Field | Description |
| --- | --- |
| `id` | Opaque string used to revoke the token |
| `name` | Label of 1–64 characters drawn from letters, digits, `-` and `_`, such as `agent` or `ci` |
| `createdAt` | Unix seconds |
| `lastUsedAt` | Unix seconds of the last successful authentication, `0` if never used |

Tokens themselves always start with `pigeon_` and are only returned by the
creation call.

## Create a token

```bash
pigeon token create --name agent   # token to stdout, id/name to stderr
```

`pigeon serve` also creates an `initial` token on first start and prints it in
the log exactly once. This only happens while the `tokens` table is empty —
later starts never re-create it. If every token is deleted, the next start
generates a fresh `initial` token.

The REST API is equivalent — `POST /api/tokens`:

```bash
curl -X POST http://127.0.0.1:8787/api/tokens \
  -H 'Content-Type: application/json' \
  -d '{"name": "agent"}'
```

```json
{
  "token": "pigeon_edf58beef210f1462bc3fcc35c8589acf4f7b555c4313017",
  "id": "3f6a1c9e",
  "name": "agent"
}
```

Store the `token` value now — it cannot be retrieved again. If it is lost,
revoke the token and create a new one.

## List tokens

```bash
pigeon token list
```

```
ID                NAME     CREATED           LAST USED
e7f7e83b68bd02a6  initial  2026-12-01 18:16  2026-12-02 15:48
97934e60b55cb9bf  e2e      2026-12-01 18:21  2026-12-03 09:42
```

The plaintext token is never shown: the database stores only its SHA-256
hash, so the secret cannot be recovered after creation. Use the `id` column
to revoke a token; if a secret is lost, delete the token and create a new
one.

`GET /api/tokens` returns the same metadata as an array of token objects
(never the secrets):

```bash
curl http://127.0.0.1:8787/api/tokens
```

## Revoke a token

```bash
pigeon token delete 3f6a1c9e   # by id
pigeon token delete agent      # by name: revokes every token named "agent"
```

The argument is matched against ids first; when no id matches it is treated
as a name and every token with that name is revoked.

`DELETE /api/tokens/{id}` returns `204`. Revocation is immediate; clients
using that token start receiving `401`.

```bash
curl -X DELETE http://127.0.0.1:8787/api/tokens/3f6a1c9e
```

## Using a token

Send it as a bearer token on every request:

```bash
curl -H "Authorization: Bearer pigeon_xxx" http://server:8787/api/accounts
```

The MCP HTTP endpoint uses the same header:

```json
{
  "mcpServers": {
    "pigeon": {
      "type": "http",
      "url": "http://server:8787/mcp",
      "headers": { "Authorization": "Bearer pigeon_xxx" }
    }
  }
}
```

## Authentication rules

| Source | Requirement |
| --- | --- |
| Loopback (`127.0.0.1`, `::1`) | No token needed |
| Any other address | Valid `Authorization: Bearer pigeon_…` header |
| `/api/health` | Always public |

The loopback exemption is based on the **TCP remote address**, not on
`X-Forwarded-For`. When Pigeon runs behind a reverse proxy on the same host,
the proxy's loopback connection is trusted — protect the site at the proxy
layer or run Pigeon in a network namespace/container where remote addresses
are not loopback. See [Security & Deployment](../security/).

---

Backlinks:

- [Documentation](/docs/)
- [REST API Basics](/docs/api/)
- [CLI](/docs/cli/)
