Skip to the documentation
API

Authentication

Two credentials, and the ways a request is refused.

Check a key works

GET /ping is the smoke test: it needs no scope and tells you what the key is.

curl
curl "$API/ping" -H "$AUTH"
Response
{  "ok": true,  "keyId": "4c1b257a66287fd113bd89d0",  "mode": "live",  "scopes": ["emails:send", "emails:read"],  "roleId": null,  "grantedScopes": ["emails:send", "emails:read"],  "workspaceId": "10417196-e324-4283-af98-66ec62167c47"}

If this works and something else 401s, the problem is the scope, not the key.

scopes is the EFFECTIVE list and the only one that authorises anything. grantedScopes is what the key was issued with, and the two differ only when a role is capping the key. The Scopes page explains that intersection. A roleId of null means no ceiling, which is the widest a key gets.

See what a key may send as

GET /addresses is the answer to a 403 you did not expect.

curl
curl "$API/addresses" -H "$AUTH"
Response
{  "object": "list",  "unrestricted": false,  "data": [    { "object": "address", "address": "[email protected]", "enabled": true, "canSend": true, "role": "owner" },    { "object": "address", "address": "[email protected]", "enabled": true, "canSend": false, "role": "member" }  ],  "domains": [    { "domain": "acme.com", "receivingVerified": true, "sendingVerified": true, "catchAll": false }  ]}

canSend: false has two causes: the address is switched off, or the domain cannot sign yet. A key limited to some addresses or domains does not see the others at all, so an address missing from the list is not a sending problem. role says whether the address belongs to the owner, a member or a viewer. enabled on the address and sendingVerified on its domain tell the two causes apart, and that is most of the debugging time this endpoint saves. A domain can be verified for receiving and still unable to send.

unrestricted: true means any local-part on a verified domain is accepted, including ones nobody has created yet.

How a key is refused

CodeMeans
missing_api_keyNo Authorization header at all.
invalid_credential_typeNeither an API key nor the OAuth access token of an app you connected. A cookie, a session token, any other token starting nm_ and a bearer longer than 512 characters all end up here.
invalid_api_keyNot a key we issued, or the secret does not match.
revoked_api_keyIssued here, then revoked. Distinct on purpose. It is the difference between a five-minute fix and an afternoon.
expired_api_keyIssued here, then expired.
insufficient_scopeA real key, without the scope this endpoint needs.
invalid_access_tokenAn OAuth access token whose app is gone or switched off.
expired_access_tokenAn OAuth access token past its expiry. Refresh it.
grant_requiredAn OAuth token for an app with no approval under the current rules. Send the person through authorization again.
grant_expiredThe approval the person gave the app has run out.
grant_workspace_goneThe workspace the app was approved for no longer exists.
grant_access_lostThe person no longer has access to the approved workspace.
grant_no_reachA member’s app whose approval reaches none of the addresses that member still holds.
mailbox_login_forbiddenA password sign-in for one address, which cannot connect apps.
owner_onlyAn OAuth token of someone who does not own the workspace, on an operation only the owner may do, such as importing from another provider. Reading API keys and managing webhooks answer the same to a member whose role does not reach every address.
api_key_onlyAn OAuth token on an operation only a key can do, such as POST /keys/self/rotate.
step_up_requiredAn OAuth token on a sensitive operation, such as deleting a domain, before the app has verified a code in the last 60 minutes. An API key never gets it. Verification codes, below, has the list and the two calls that clear it.
ip_not_allowedA key with an IP allowlist, called from an address outside it. Send the call from one of those addresses or change the list.

Revoking takes effect on the next call. The row stays on the keys page afterwards, so you can still tell whether anything was using the key when you killed it. The most useful state on that screen is "never used", because it is how a leaked key is told from a live dependency.

Rotating is the other way to retire a secret. It mints a new secret for the same key, so the id, the name, the scopes, the role, the send scope and every request and activity row all carry on; only the secret changes. The old one stops working the instant the rotation completes, with no overlap window, and the replacement is shown once. From the console it is in the same menu as Revoke and asks you to re-verify first. A key holding keys:write can also rotate itself with POST /keys/self/rotate, which is how an integration rotates on a schedule without anyone opening the console.

Over the API, a key reaches other keys only behind scopes no key holds unless somebody gave it one: keys:read lists keys and reads their request log and activity, and keys:manage creates, changes, switches off, rotates, revokes and deletes them, never wider than the key making the call, in its own workspace or, with workspaceId, in another workspace the account owns. No app is ever given keys:manage, so an OAuth access token only reads keys and is refused every change with 403 api_key_only. The API keys page has the rules.

A key can be held to the places it is used from. ipAllowlist on POST /keys and PATCH /keys/{id} takes up to 50 IP addresses and ranges, such as 203.0.113.7 or 2001:db8::/32, and every call or SMTP sign-in from anywhere else is refused with 403 ip_not_allowed. An empty list lets the key work from anywhere again. A key cannot change its own list, and a key with a list can only give the keys it makes a list inside its own. Set it in the console on the page of the key, under Edit.

OAuth access tokens

An app a person connected over OAuth receives an access token, and the same token authenticates here. It is held to the approval the person gave: one workspace, the permissions they chose intersected with their role, and any domains or addresses they picked. A member’s token reaches only the addresses that member reaches, the ones they were granted or every address when their role holds addresses:all, and sends only from the ones they may send from.

GET /ping answers "kind": "oauth" and the app’s clientId for one. An Idempotency-Key is honoured per person. Calls made with a token are not in the per-key request log: they are in the log of the app, which the person reads under Connected apps or with GET /account/connected-apps/{clientId}/requests. Operations that belong to a key or to the owner, such as rotating a key or importing from another provider, are refused for anyone else with api_key_only or owner_only, and so is managing webhooks for a member whose role does not reach every address. No app is ever given keys:manage, so a token reads API keys and changes none.

No account yet

A program can begin with no account and no key. POST /signups and POST /signups/{id}/verify take no Authorization header. The first emails a six-digit code to the address the account is for. The second takes that code, creates the account with its workspace, on the same free plan and limits as any other, and answers with an API key that acts for the new owner. The code is the person’s consent: an agent asks them for it, and nothing is created until it is right.

curl -X POST https://api.nextmail.sh/signups \  -H "Content-Type: application/json" \  -d '{ "email": "[email protected]", "name": "Ada Park", "agent": "Claude Code" }' curl -X POST https://api.nextmail.sh/signups/sgn_4f9b2e6c71a38e5b9f1c24d0a6e83b17/verify \  -H "Content-Type: application/json" \  -d '{ "code": "482913" }'
The first answer, 202
{  "object": "sign_up",  "id": "sgn_4f9b2e6c71a38e5b9f1c24d0a6e83b17",  "sentTo": "a•••@example.com",  "expiresAt": "2026-10-31T10:52:07.000Z"}
The second answer, 201
{  "object": "sign_up_account",  "id": "sgn_4f9b2e6c71a38e5b9f1c24d0a6e83b17",  "userId": "q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E",  "email": "[email protected]",  "name": "Ada Park",  "workspaceId": "10417196-e324-4283-af98-66ec62167c47",  "apiKey": {    "object": "api_key",    "id": "4c1b257a66287fd113bd89d0",    "name": "Claude Code",    "scopes": ["emails:send", "emails:read", "…"],    "token": "nm_live_9f2c1a4b7e05d3862c1f0a44_kX7…"  }}
  • apiKey.token is in that answer and nowhere else, so store it before anything else. It works until the person revokes it.
  • The key is named after agent and carries every scope unless the sign-up listed fewer in scopes. The person sees it in Console → API keys, where its activity says it was made by an agent when it created the account, and narrows or removes it there. They also get a welcome email with a link to set a password.
  • An address that already has an account gets no code. Its owner is emailed how to connect an agent to the account they have, and the first call answers exactly as it would for a new address, so it never reveals who has an account.
  • An address that cannot receive mail, or one on a disposable domain, is refused with 422 sign_up_address_refused, and nothing is sent.
  • The code works once, for 10 minutes, and a sign-up takes 5 tries. A wrong code is 400 sign_up_code_invalid with the tries left, the last wrong one cancels the sign-up with 429 sign_up_locked, and a code that ran out or was used already is 400 sign_up_code_expired.
  • One network may start 3 sign-ups an hour, and one address 5 an hour. One network may also check 30 codes every 10 minutes. Past either limit the answer is 429 sign_up_rate_limited with Retry-After.

Verification codes

The web app asks a person for a verification code before a change that could lock them out or leak their mail, and an app acting for them with an OAuth access token is asked the same thing. Until the app has verified a code, the operations below answer 403 step_up_required and change nothing. One verified code unlocks all of them for that app for 60 minutes. An API key is never asked for a code.

OperationMCP toolAsks for a code
POST /account/sign-in-methods/{provider}/connectconnectSignInMethodAlways
DELETE /account/sign-in-methods/{provider}disconnectSignInMethodAlways
POST /webhooks, PATCH /webhooks/{id}createWebhook, updateWebhookAlways
POST /rules, PATCH /rules/{id}createRule, setRuleEnabled, updateRuleAlways
PATCH /roles/{id}, DELETE /roles/{id}updateRole, deleteRoleAlways
POST /members, PATCH /members/{userId}, DELETE /members/{userId}inviteMember, setMemberRole, removeMemberAlways
POST /members/{userId}/addresses, DELETE /members/{userId}/addresses/{addressId}grantMemberAddress, revokeMemberAddressAlways
POST /members/{userId}/domains, DELETE /members/{userId}/domains/{domainId}grantMemberDomain, revokeMemberDomainAlways
DELETE /domains/{id}, DELETE /domains/{id}/addresses/{addressId}removeDomain, removeDomainAddressAlways
POST /domains/{id}/addressesaddDomainAddressWhen it is sent destination, webhookId or tapWebhookIds, or onExpiry: "delete" with an expiry
PATCH /domains/{id}/addresses/{addressId}setAddressForwardMode, updateDomainAddressWhen it sets destination, webhookId or tapWebhookIds, or onExpiry: "delete" with an expiry
POST /domains/{id}/addresses/{addressId}/forwards, PATCH /domains/{id}/addresses/{addressId}/forwards/{forwardId}, DELETE /domains/{id}/addresses/{addressId}/forwards/{forwardId}, POST /domains/{id}/addresses/{addressId}/forwards/{forwardId}/resendaddAddressForwards, setAddressForwardEnabled, removeAddressForward, resendAddressForwardConsentAlways
POST /domains/{id}/routes, PATCH /domains/{id}/routes/{routeId}, POST /domains/{id}/addresses/{addressId}/group-memberscreateDomainRoute, updateDomainRoute, addGroupMembersAlways
PUT /domains/{id}/addresses/{addressId}/loginNone. A password never goes through MCP.Always
POST /domains/{id}/addresses/{addressId}/app-passwordscreateAppPasswordAlways
POST /domains/{id}/addresses/{addressId}/mail-app-setupsendMailAppSetupAlways
POST /domains/{id}/addresses/{addressId}/mail-app-profile-linkcreateMailAppProfileLinkAlways
POST /calendar/loginscreateCalendarLoginAlways
POST /calendar/logins/profile-linkcreateCalendarLoginProfileLinkAlways
PUT /domains/{id}/dns, POST /domains/{id}/dns/syncsetDomainDnsZone, syncDomainDnsAlways
DELETE /dns-connections/{id}disconnectDnsConnectionAlways
POST /dns-connectionsstartDnsConnectionAlways
DELETE /audiences/{id}deleteAudienceFor an audience you created. The built-in default audience cannot be deleted at all.
PUT /app-hostsetAppHostWhen it replaces a host the workspace already has
DELETE /app-hostremoveAppHostAlways
DELETE /forms/{id}deleteFormAlways
POST /encryption/keyspublishEncryptionKeyAlways
POST /exports, GET /exports/{id}/contentstartExportAlways
PATCH /billing/pay-as-you-go, PUT /billing/pay-as-you-go/limit, POST /billing/pay-as-you-go/confirmsetPayAsYouGo, setPayAsYouGoLimit, confirmPayAsYouGoAlways
POST /billing/checkout, POST /billing/portalstartPlanCheckout, openBillingPortalAlways
PUT /billing/invoices/{orderId}/detailssaveBillingDetailsAlways
DELETE /workspaces/{id}deleteWorkspaceAlways
POST /workspaces/{id}/ownership-offer, POST /account/ownership-offers/{workspaceId}/acceptofferOwnership, acceptOwnershipOfferAlways
POST /directory-sync, DELETE /directory-sync, PUT /directory-sync/default-role, PUT /directory-sync/groups/{groupId}/roleconnectDirectorySync, disconnectDirectorySync, setDirectoryDefaultRole, setDirectoryGroupRoleAlways
PATCH /security/policysetTwoFactorRequirementAlways
POST /billing/add-ons/checkout, DELETE /billing/add-ons/{addOn}startAddOnCheckout, cancelAddOnAlways
POST /sending/streams/{stream}/resumeresumeSendingStreamAlways
DELETE /automations/{id}deleteAutomationAlways

The check runs after the scope, the request body and the resource itself have been checked, so a 422 or a 404 still means what it says, and before anything is written.

  1. Ask for a code with POST /security/step-up. method says where it comes from. email means a six-digit code has just gone to the address the person signs in with, shown masked in sentTo. totp means they have two-factor sign-in on, so they read the code from their authenticator app or use one of their backup codes, and nothing is sent.
  2. Ask the person for the code and send it to POST /security/step-up/verify as { "code": "…" }.
  3. Repeat the call that was refused. elevatedUntil in the answer says when the app will be asked again.
Ask for a code
curl -X POST "$API/security/step-up" -H "$AUTH" {  "object": "step_up_challenge",  "method": "email",  "sentTo": "a•••@acme.com",  "reused": false}
Verify it
curl -X POST "$API/security/step-up/verify" -H "$AUTH" \  -H "Content-Type: application/json" \  -d '{ "code": "482913" }' {  "object": "step_up",  "elevated": true,  "elevatedUntil": "2026-09-26T11:42:07.000Z"}

GET /security/step-up says where the app stands without sending anything: elevated, elevatedUntil, the method the next code will use, and minutes, the length of the window. Check it before a run of changes, so the person is asked once at the start rather than halfway through. None of the three calls needs a scope, and an API key calling any of them gets 400 step_up_not_applicable.

  • An emailed code works for 10 minutes. Asking again while one is waiting and still has tries left reuses it, sends nothing and answers reused: true. Send { "resend": true } for a fresh code, which stops the waiting one from working.
  • A wrong code is 400 step_up_code_invalid, and the message says how many tries are left. The fifth wrong code is 429 step_up_locked, and so is every try after it. A locked code is never reused, so a plain POST /security/step-up starts a fresh one, with no resend needed.
  • An expired code, or a verify with no code waiting, is 400 step_up_code_expired. Ask for a new one with POST /security/step-up.
  • Each app has a budget of its own with each person: 5 codes an hour and 20 in 24 hours. The next request is 429 step_up_throttled, and the message says when to try again. A reused code does not count, and neither does one whose email could not be sent. The person’s other apps and the web app, which allows 10 codes an hour, never use it up. When the email cannot be sent the answer is 503 step_up_undeliverable, and no code is left waiting.
  • The 60 minutes belong to the person and this app together. Another app they connected is asked on its own, and revoking the app, or removing it in Account → Connected apps, ends the window at once. The person can also start the 60 minutes there with no code from the app: they choose Allow changes for 60 minutes in the app’s menu, after verifying on the website themselves, and End allowed changes stops them early.
  • Wrong codes also count against the app for 24 hours, across every code it asked for, and a correct code does not clear them. The tenth pauses verification for that app: asking for a code and verifying one both answer 429 step_up_locked, with a message that says it is paused until a given time, and until then even a correct code is refused. The person gets one email about it that names the app. Wrong codes from all of the person’s apps also count together: 20 in 24 hours pause verification the same way for every app they connected, even one that sent none of them, and removing an app does not lift that pause. Codes entered on the website count toward neither pause, and the person can still verify there.
  • An authenticator code is accepted once. Entering one that was already accepted, by any app or in the web app, counts as a wrong code, so wait for the next one.
  • The email with the code says a connected app asked for it, and shows the name the app registered with, its client ID, when the person connected it and, when it was refused in the last 15 minutes, the change it last asked to make. It also says that the code unlocks more than that one change: for 60 minutes the app can make any change on the list above that the person gave it access to. The name is chosen by whoever registered the app, so it is never proof of who is asking.

The MCP server asks the same. Each tool in the table makes the change of the operation beside it, and until the app has verified a code it answers with an ordinary tool result whose text starts Refused (step_up_required):, and changes nothing. The app asks for a code with the beginStepUp tool, checks the one the person gives with verifyStepUp, or makes the calls above with the same access token, and calls the tool again. getStepUpStatus says whether it is verified. When the person cannot give a code, they can choose Allow changes for 60 minutes on it in Account → Connected apps, as the refusal says. REST and the tools share the 60 minutes, so one code covers both. emptyAudience, like POST /audiences/{id}/empty, never asks.

Tool result
{  "content": [    {      "type": "text",      "text": "Refused (step_up_required): This action needs a verification code. Call beginStepUp, ask the person for the code it sends them or the one their authenticator app shows, pass it to verifyStepUp, then call the tool again. If they cannot give you a code, ask them to choose Allow changes for 60 minutes on this app in Account settings, Connected apps, on the Nextmail website, then call the tool again."    }  ]}