Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

REST API Basics

Base URL, authentication, error format and the endpoint map.

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:

PIGEON_ADDR=127.0.0.1:8788 pigeon serve

To call the API from other machines, bind an address they can reach:

pigeon serve --addr 0.0.0.0:8787

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:

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

Create tokens with the CLI or the API:

pigeon token create --name agent   # prints the token once, to stdout

See Tokens & Auth for the token endpoints and Security & Deployment for reverse-proxy caveats.

Errors

Errors always use the same shape:

{"error": "invalid email address \"nope\""}
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:

curl http://127.0.0.1:8787/api/health

GET /api/meta requires authentication and tells a client how it was seen:

curl http://127.0.0.1:8787/api/meta

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.