Guides
Authentication and API keys
How a key proves who you are, what each scope allows, and how to keep keys safe.
Send the key with every request#
The developer API lives under /v1. Every request carries an API key in the Authorization header, as a bearer token. Cookies are ignored on /v1, and an API key is refused by the dashboard's own routes: the two kinds of credential are kept apart on purpose.
curl https://api.cirrusmail.example/v1/usage \
-H "Authorization: Bearer cirrus_live_..."The client libraries do this for you: you give them the key once. There is no sign-in call and no token to refresh; a key works until it is revoked or expires.
Create a key#
Keys are created in the dashboard, under Developer then API keys; the API cannot create keys itself, so a stolen key can never mint another. You choose:
- a name, one to 100 characters, so you can tell keys apart later;
- a mode, live or test (see below);
- the scopes it holds, at least one.
The full key is shown once, when it is created. Cirrus keeps only a hash of it and cannot show it again. What you can always see in the dashboard is its recognisable start, for example cirrus_live_Ab3…, which is not a secret. Keys have this shape:
cirrus_live_<12-character key id><43-character secret>
cirrus_test_<12-character key id><43-character secret>Scopes#
A key can do exactly what its scopes allow, and nothing else. No scope implies another: a key that can send email cannot read it back unless it also holds email:read.
| Scope | Allows |
|---|---|
email:send | Send an email or a batch (POST /v1/emails, POST /v1/emails/batch). |
email:read | Look up an email, list events, read usage (GET /v1/emails/{id}, /v1/events, /v1/usage). |
domain:write | Register a sending domain (POST /v1/domains). |
domain:read | Read a domain and its DNS records (GET /v1/domains/{id}, /dns). |
webhook:manage | Register a webhook endpoint (POST /v1/webhooks). |
campaign:write | Send on the marketing and promotional streams. Without it, those are refused with 403 stream_not_allowed. See Marketing and promotional email. |
Live keys and test keys#
A live key (cirrus_live_…) sends real email and counts against your allowance. A test key (cirrus_test_…) accepts the same requests and answers the same way, but delivers nothing and uses no allowance. Read Test mode for what it simulates.
Keeping keys safe#
- Keep keys on your server, in an environment variable or a secrets manager. Never put one in a web page, a mobile app or a public repository.
- To rotate a key: create a new one, deploy it, check that the old one's last-used time stops moving, then revoke the old one. Revoking takes effect at once.
- If a key may have leaked, revoke it first and investigate afterwards. The dashboard's API log shows what each key was used for.
- The libraries never print the key, and keep it out of error messages and dumps. Do the same in your own logs.
When authentication fails#
| Answer | Code | Meaning |
|---|---|---|
| 401 | unauthenticated | No key was sent. |
| 401 | invalid_api_key | The key is unknown, revoked or expired. |
| 403 | insufficient_scope | The key does not hold the scope this operation needs. |
| 403 | account_suspended | Your organisation is suspended. None of its keys work until that is lifted. |
| 403 | account_closed | Your organisation has been closed. None of its keys will work again. |
What to do#
- On a 401, check the header is spelled
Authorization: Bearer …and that the key was copied whole. - On
insufficient_scope, create a key with the missing scope. A key's scopes cannot be edited afterwards. - On a suspension, contact support from the dashboard. Retrying will not help. The full list of error codes is in Errors.