API and MCP
API key scopes and key hygiene for the mailers.io API
By mailers.io team Published 5 min read
public/media/blog-api-key-scopes-and-hygiene-cover.webp An API key is the smallest thing in your account that can do real damage if it leaks. It does not need your password, it works from anywhere, and it keeps working until somebody turns it off. The good news is that mailers.io keys are scoped, so you can decide in advance how much damage a leaked key could do. This post covers the scopes, how to choose them, and the habits that keep keys from becoming a problem.
What a key looks like
A key begins with mio_live_. You pass it as a bearer token in the Authorization header, after the word Bearer.
When you create a key, the full secret is shown once. After that the app shows only an eight-character hint, enough to recognise the key in a list. The platform stores a hash of the secret, not the secret, so it cannot be shown again. Lose it, and the fix is to create a new key.
Creating or revoking a key needs a recent step-up check, which means you confirm your identity again shortly before the action. The account owner also gets an e-mail every time a key is created. If you did not make a key and an e-mail says one exists, that is a signal to look at your account.
Every id the API handles is scoped to the key’s account. A key cannot read another account’s data, whatever scopes it holds.
The scopes
A key carries one or more of these scopes.
| Scope | What it allows |
|---|---|
messages.read |
List messages in a time range and read one message with its delivery events |
send |
Send a transactional e-mail |
lists.read |
Read lists and a list’s custom fields |
lists.write |
Create and rename lists |
contacts.read |
Read contacts in a list, or one contact |
contacts.write |
Add, update, unsubscribe and delete contacts, and relay a sign-up |
templates.read |
List and read templates |
templates.write |
Create, replace, rename and delete templates |
sequences.write |
Enrol one contact in a sequence |
automations.trigger |
Enter one contact into an automation |
mcp |
Call the MCP endpoint (see the MCP post) |
Notice how the scopes pair up. Reading and writing are separate, so a reporting script can see messages without being able to send. contacts.write includes deleting a contact, which is a bigger permission than it sounds, so do not hand it to something that only needs to add people.
A separate kind of key, the SMTP key, carries only send and works only on the relay. It is covered in SMTP relay credentials and rate limits.
Choosing scopes for a job
Start from what the integration does and list the calls it makes. Then grant only those scopes. Some examples:
- A password-reset mailer in your app. It sends one kind of message. Give it
sendand nothing else. - A sign-up form on your site. It adds a person to a list and relays the person’s own opt-in. Give it
contacts.write. It does not needlists.write, because the list already exists. - A dashboard that shows recent delivery. Give it
messages.read. It can look but not send. - A script that keeps templates in step with your repository. Give it
templates.readandtemplates.write. - A lead-routing job that enrols new leads. Give it
contacts.writeandsequences.write. See cold email through an API and MCP.
If you are not sure what a job needs, start narrow and watch for 403 responses. Adding a scope later by making a new key is cheap. Cleaning up after a key that could do everything is not.
A key cannot outrank its maker
A key may not hold a scope that its creator’s role does not allow. If a team member whose role cannot write templates tries to create a key with templates.write, the app refuses. The check is made again on every call, so if that person is later demoted, their keys lose the matching power at once. A Viewer’s key can only read.
This makes keys safe to hand out inside a team. They follow the permissions of the person, rather than becoming a back door around them. See team roles for what each role can do.
Good habits
One key per integration. If every system shares one key, you cannot tell which one misbehaved, and revoking it breaks all of them. Name each key after the thing that uses it, so the list tells a story.
Set an expiry. A key with an end date cleans itself up. Use short expiries for contractors, trials and one-off migrations. Seven days before a key expires, the account owner gets a notice, so a long-lived integration does not fail by surprise.
Keep the secret out of code. Put it in an environment variable or a secrets manager. Do not commit it, paste it into a chat, or embed it in a mobile app or browser script, where anyone can read it. A key that must run in a browser is a design problem; put a small server in between.
Keep logs clean. Do not print the Authorization header in your own request logs. Many a leak has come from a debug line.
Watch last use. The app records when and from which address a key was last used. A key nobody has used in months is one to revoke. A key used from an address you do not recognise is one to revoke now.
Rotate on a schedule. Create the new key, deploy it, check that the old one is idle, then revoke the old one. Because you can hold several keys at once, rotation needs no downtime.
If a key leaks
- Revoke it in the app. It stops working immediately.
- Check the message log for sends or changes you did not make.
- Create a replacement with a narrower scope than the one you lost, if you can.
- Find out how it leaked, and fix that, or the next key will leak the same way.
A revoked key stays in your list for a while and is removed from the system after 90 days.
Limits worth knowing
- An account can hold up to 50 live keys of each kind. Creating keys is rate limited to 20 an hour.
- Calls are limited per account and per key. The default is 600 requests a minute per account. A 429 response carries
Retry-After. - Repeated failed authentication from one address is slowed down.
Where to go next
The endpoint list, request shapes and error formats are in the developer docs at https://docs.mailers.io/. The API overview is the short version. If you are connecting an assistant, read using the MCP endpoint with an AI assistant, where the same scoping rules matter even more.
Questions and answers
Can I change the scopes of an existing key?
Treat scopes as fixed at creation. If an integration needs something different, make a new key with the right scopes and revoke the old one.
Is a key a login?
No. A key is a credential for the API and never a browser session. It cannot open the app, and the app's sign-in cannot call the API.
How many keys can an account have?
Up to 50 live keys of each kind. Expired keys do not count toward the limit.
Written by the mailers.io team. Published .