API keys and scopes

All five HTTP APIs authenticate with the same API keys. A key belongs to one mail server; everything it does is scoped to that server and its organisation's verified domains.

Choosing an API

APIBase URLKey inUse it when
Karta APIhttps://<host>/api/v2Authorization: Bearer <key>you write new code; it has an OpenAPI document
Postal-compatiblehttps://<host>/api/v1X-Server-API-Key: <key>you move from Postal
Mailgun-compatiblehttps://<host>/mailgun/v3Basic auth, user api, password <key>you use a Mailgun client or adapter
SendGrid-compatiblehttps://<host>/sendgrid/v3Authorization: Bearer <key>you use a SendGrid client or adapter
Postmark-compatiblehttps://<host>/postmarkX-Postmark-Server-Token: <key>you use a Postmark client or adapter

A message sent through any of them can be read through any other; the ids differ (see each page).

Keys

A key looks like this:

karta_ln6ml74h_cjjbpagpze62miy66k4fg6vn7tapdw2e
      └prefix┘ └──────────── secret ──────────┘

karta_, an 8-character prefix that identifies the key, _, and a 32-character secret (160 random bits). All characters are lower-case base32 (a-z, 2-7), so a key never needs quoting. The key is shown once, when it is created; Karta keeps only an Argon2id hash of the secret. The prefix is not secret: it appears in the key's listing and as the source of suppressions the key adds (api:ln6ml74h).

Create keys from the console (Managing organisations, servers and keys) or with a key that has credentials:write:

curl -s https://karta.example.com/api/v2/credentials \
  -H "Authorization: Bearer $KARTA_API_KEY" -H "Content-Type: application/json" \
  -d '{"kind": "api", "name": "Billing", "scopes": ["messages:send"], "rate_limit_per_minute": 120}'
{
  "created_at": "2026-11-08T15:52:29.164937Z",
  "id": "b429ace6-af98-4e0d-88de-7fd6fca1c22e",
  "key": "karta_tuxmfyqf_qspl3nh2knzsbddw7osfxu7nj57x2rot",
  "kind": "api",
  "name": "Billing",
  "prefix": "tuxmfyqf",
  "rate_limit_per_minute": 120,
  "scopes": ["messages:send"]
}

A key can give only scopes it has itself. Revoke a key with DELETE /api/v2/credentials/{id}; a revoked key never authenticates again, on every node, from the next request.

Scopes

ScopeAllows
messages:sendsending (every API); creating SMTP credentials
messages:readreading messages, deliveries and events (every API)
messages:manageretrying, holding, releasing and cancelling messages (/api/v2)
suppressions:readreading the suppression list (every API)
suppressions:writeadding to and removing from the suppression list
credentials:readlisting the server's credentials
credentials:writecreating and revoking credentials
webhooks:readlisting webhooks and their deliveries
webhooks:writeadding, changing and removing webhooks, rotating their secrets, test events and replays
routes:readlisting routes and endpoints, reading received messages
routes:writeadding, changing and removing routes and endpoints

A new key gets messages:send and messages:read unless other scopes are given.

Rate limits

  • Per key: at most rate_limit_per_minute requests (default 600), counted in a sliding one-minute window in the database, shared by every node: two nodes do not allow twice the limit. Over the limit, every API answers 429 with Retry-After (seconds). A batch is one request, however many messages it sends; the server's sending limit counts each message when it is delivered.
  • Per client: at most 60 Argon2id verifications of keys that are not in the cache, per minute, per IPv4 address or IPv6 /64. The count is shared by every node too. This keeps anyone from making Karta hash without limit; requests with a cached key do not count. Over the limit: 429.

A limit is counted before the work it guards; when its counter cannot be read (the database is unavailable), the request is refused rather than allowed, and it answers 429 until the database answers again.

Behind a reverse proxy, set KARTA_TRUSTED_PROXIES (Installation) so that the client is the one in X-Forwarded-For; otherwise all clients of the proxy share the second limit. With many distinct keys first used at the same moment, raise verifications_per_minute (Configuration reference).

A request's body is read only after its key has been accepted: a request without a valid key is refused before Karta reads any of it.

The key cache

Verifying an Argon2id hash takes time and memory (16 MiB, 3 passes) on purpose, so a key verified once is remembered per node for 10 minutes (Karta.Credentials.KeyCache): the cache maps the SHA-256 hash of the key to its credential; the key itself is never kept. The cache is per node, while the limit on verifications is shared, so the hashing work is capped across all of them. The credential and its server are still read from the database on every request, so revoking a key or suspending a server takes effect at once. At most 10,000 keys are cached; when full, the cache is emptied.

Authentication errors

ProblemKarta APIPostal APIMailgun APISendGrid APIPostmark API
no key401 unauthorized200, AccessDenied401 Forbidden401 authorization required401, code 10
wrong or revoked key401 unauthorized200, InvalidServerAPIKey401 Forbidden401 authorization required401, code 10
missing scope403 forbidden200, AccessDenied401 Forbidden403 access forbidden401, code 10
server suspended403 server_suspended200, ServerSuspended403403422, code 413
rate limited429 rate_limited429, TooManyRequests429429 too many requests429, code 429