API Reference

Mallard Metrics exposes a JSON HTTP API. All endpoints are served by the same process as the dashboard.

Base URL

http://your-instance.com

Authentication

Most /api/stats/* and /api/keys/* endpoints require authentication. Provide one of:

  1. Session cookie — Set after POST /api/auth/login. Sent automatically by browsers.
  2. Bearer token — An API key in the Authorization: Bearer mm_... header.
  3. X-API-Key header — An API key in the X-API-Key: mm_... header.

Endpoints that do not require authentication:

  • POST /api/event — Event ingestion (uses Origin allowlist instead).
  • GET /api/event — Pixel tracking (same parameters as POST via query string; returns 1×1 GIF).
  • POST /api/auth/login, POST /api/auth/setup, GET /api/auth/status, POST /api/auth/logout
  • GET /health, GET /health/ready, GET /health/detailed
  • GET /metrics — optionally protected by MALLARD_METRICS_TOKEN bearer token.
  • GET /robots.txt, GET /.well-known/security.txt
  • GET / (dashboard)

Content Type

All request bodies are application/json. All responses are application/json unless otherwise noted.

Error Responses

Errors are returned as JSON objects:

{
  "error": "human-readable description"
}

HTTP Status Codes

CodeMeaning
200Success
202Event accepted (ingestion only)
400Bad request — missing or invalid parameters
401Unauthenticated — no valid session or API key
403Forbidden — origin not in allowlist, or CSRF check failed
404Not found
408Request timeout (30-second server-side limit)
409Conflict — resource already exists (e.g. password already set)
413Request body too large (limit: 64 KB on ingestion routes)
422Unprocessable — JSON validation failed
429Rate limited or concurrent query limit — includes Retry-After header
503Service unavailable — database not ready
500Internal server error

Sections