This is the multi-page printable view of this section.
REST API Basics
Everything the web UI and the CLI can do is available over JSON HTTP. The API is designed to be called by scripts, terminal users and AI agents.
Base URL
pigeon serve listens on http://127.0.0.1:8787 by default. Change it with
--addr or the PIGEON_ADDR environment variable:
To call the API from other machines, bind an address they can reach:
Remote requests must then carry a bearer token; see Authentication below and Security & Deployment for the deployment trade-offs.
| Path | Purpose |
|---|---|
/api/* |
REST API (this guide) |
/mcp |
MCP over Streamable HTTP |
/ |
Embedded web UI (mailbox login and message reader) |
Conventions
- Request and response bodies are UTF-8 JSON. Send
Content-Type: application/json. - Timestamps are Unix seconds (integers), not strings.
- Addresses are objects:
{"name": "Ada", "address": "ada@example.com"}. - Resource IDs are integers except token IDs, which are opaque strings.
- List endpoints return arrays, never
null.
Authentication
Local requests from a loopback address (127.0.0.1, ::1) are allowed without
credentials — convenient for development and for agents running on the same
machine. Every other request must carry a bearer token:
Create tokens with the CLI or the API:
See Tokens & Auth for the token endpoints and Security & Deployment for reverse-proxy caveats.
Errors
Errors always use the same shape:
| Status | Meaning |
|---|---|
400 |
Invalid JSON, missing or invalid parameters |
401 |
Missing or invalid bearer token (non-loopback request) |
404 |
Unknown account, mailbox, message or token |
405 |
Wrong HTTP method for the route |
500 |
Internal failure (database, encryption) |
502 |
Upstream IMAP/SMTP failure (connection, login, network) |
502 responses mean Pigeon could not reach or authenticate with the mail
server; the request may succeed later once connectivity is restored.
CORS
The server answers OPTIONS preflight requests with 204 and allows any
origin, the Authorization and Content-Type headers, and the methods GET,
POST, PUT, PATCH, DELETE. Authentication is still enforced on
non-loopback requests.
Endpoint map
| Area | Endpoints | Guide |
|---|---|---|
| Health & meta | GET /api/health, GET /api/meta |
this page |
| Accounts | GET/POST /api/accounts, PUT/PATCH/DELETE /api/accounts/{id} |
Accounts |
| Provider detection | GET /api/detect?email= |
Accounts |
| Mailboxes & sync | GET /api/accounts/{id}/mailboxes, POST /api/accounts/{id}/sync, POST /api/mailboxes/{id}/fetch-older |
Mailboxes & Sync |
| Messages | GET /api/mailboxes/{id}/messages, GET /api/messages/{id}, POST /api/messages/{id}/flags, GET /api/attachments/{id} |
Messages & Flags |
| Search | GET /api/search?q= (also from, subject, since, until, body, account, limit, offset) |
Search |
| Sending | POST /api/accounts/{id}/send |
Sending Mail |
| Tokens | GET/POST /api/tokens, DELETE /api/tokens/{id} |
Tokens & Auth |
| Settings | GET/PUT /api/settings |
Settings |
Health and meta
GET /api/health is public and reports liveness:
GET /api/meta requires authentication and tells a client how it was seen:
loopback is false when the request arrived over the network; a web client
can use it to decide whether to show a token login screen.