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
| API | Base URL | Key in | Use it when |
|---|---|---|---|
| Karta API | https://<host>/api/v2 | Authorization: Bearer <key> | you write new code; it has an OpenAPI document |
| Postal-compatible | https://<host>/api/v1 | X-Server-API-Key: <key> | you move from Postal |
| Mailgun-compatible | https://<host>/mailgun/v3 | Basic auth, user api, password <key> | you use a Mailgun client or adapter |
| SendGrid-compatible | https://<host>/sendgrid/v3 | Authorization: Bearer <key> | you use a SendGrid client or adapter |
| Postmark-compatible | https://<host>/postmark | X-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
| Scope | Allows |
|---|---|
messages:send | sending (every API); creating SMTP credentials |
messages:read | reading messages, deliveries and events (every API) |
messages:manage | retrying, holding, releasing and cancelling messages (/api/v2) |
suppressions:read | reading the suppression list (every API) |
suppressions:write | adding to and removing from the suppression list |
credentials:read | listing the server's credentials |
credentials:write | creating and revoking credentials |
webhooks:read | listing webhooks and their deliveries |
webhooks:write | adding, changing and removing webhooks, rotating their secrets, test events and replays |
routes:read | listing routes and endpoints, reading received messages |
routes:write | adding, 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_minuterequests (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 answers429withRetry-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
| Problem | Karta API | Postal API | Mailgun API | SendGrid API | Postmark API |
|---|---|---|---|---|---|
| no key | 401 unauthorized | 200, AccessDenied | 401 Forbidden | 401 authorization required | 401, code 10 |
| wrong or revoked key | 401 unauthorized | 200, InvalidServerAPIKey | 401 Forbidden | 401 authorization required | 401, code 10 |
| missing scope | 403 forbidden | 200, AccessDenied | 401 Forbidden | 403 access forbidden | 401, code 10 |
| server suspended | 403 server_suspended | 200, ServerSuspended | 403 | 403 | 422, code 413 |
| rate limited | 429 rate_limited | 429, TooManyRequests | 429 | 429 too many requests | 429, code 429 |