Authentication

All API requests to mails-agent, except POST /v1/bootstrap, require a Bearer token in the Authorization header. The server assigns each key a scope; the mk_ prefix does not imply elevated access.

Bearer Token Authentication

Include your API key in every request:

curl -s -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.mails0.com/v1/me

If the key is missing or invalid, the API returns 401 with {"error": "Unauthorized"}.

API Key Types

TypeScopeLifetimeUse Case
Provisionalprovisional72 hoursAutomatic agent onboarding for receive, read, search, and verification codes
Mailbox-scopedmailboxUntil revokedOne permanent mailbox, including outbound email and mailbox settings
OperatoroperatorDeployment-managedPrivate administration for a self-hosted deployment

Provisional Keys

mails bootstrap or the MCP create_temporary_mailbox tool creates an expiring receive-only mailbox. The key can read only that mailbox and cannot send, download attachments, manage domains or webhooks, create other mailboxes, or perform moderation.

npm install -g mails-agent
mails bootstrap
mails inbox
mails code --timeout 30

Mailbox-scoped Keys

Mailbox-scoped keys are bound to a single permanent mailbox at creation time. They can only send and receive email for their own mailbox. Any attempt to access another mailbox returns 403 Forbidden.

# Mailbox-scoped key — mailbox is implicit from the key
curl -s -H "Authorization: Bearer mk_xyz789..." \
  "https://api.mails0.com/v1/inbox"

# Trying to access another mailbox → 403
curl -s -H "Authorization: Bearer mk_xyz789..." \
  "https://api.mails0.com/v1/[email protected]"
# → {"error": "forbidden", "message": "Key not authorized for this mailbox"}

Operator Credentials

Operator access is never returned by hosted bootstrap or claim flows. It is reserved for deployment owners and is configured explicitly, such as with the self-hosted AUTH_TOKEN secret. Do not distribute an operator credential to an agent.

Key Format

API keys use the mk_ prefix followed by 64 hex characters, for a total of 67 characters:

# API key format (mk_ prefix + 64 hex chars = 67 chars total)
mk_5fbc897fa0380dc1875a5b9502ed316dbd5ad41dd1814b605fbc897fa0380dc1

# Mailbox-scoped key format
mk_8a3c12ef90b74d2e56f1a8c3d0e9b7f4a2c5d8e1f0b3a6c98a3c12ef90b74d2e

Getting Your API Key

You can obtain an API key in several ways:

Key Permissions Matrix

CapabilityProvisionalMailboxOperator
Read inbox, email, code, search, threads, events, statsOwn mailboxOwn mailboxConfigured mailbox
Extract structured dataOwn mailboxOwn mailboxConfigured mailbox
Send emailNoOwn mailboxConfigured mailbox
Attachments, webhooks, custom domainsNoOwn mailbox resourcesConfigured mailbox resources
Create or moderate mailboxesNoNoYes
Delete own mailboxYesYesYes

Security Best Practices

# Store key in environment variable
export MAILS_API_KEY="mk_8a3c12ef90b74d2e56f1a8c3d0e9b7f4a2c5d8e1f0b3a6c98a3c12ef90b74d2e"

# Reference in curl
curl -s -H "Authorization: Bearer $MAILS_API_KEY" \
  "https://api.mails0.com/v1/me"

Error Responses

StatusResponse bodyMeaning
401{"error": "Unauthorized"}Missing or invalid API key
403{"error": "Mailbox is paused"}The mailbox is paused. Resume it via PATCH /v1/mailbox/resume before making requests.