Troubleshooting

Fix 401 invalid_api_key and missing_api_key errors

Short answer

A 401 means Mailcandor did not get a key it recognises. missing_api_key means there was no Authorization: Bearer header. invalid_api_key means the key is wrong or has been revoked. Check the header format, that the full key starting with mc_live_ is loaded from your environment, and that it still appears under API keys. If it was revoked or lost, create a new key.

Last checked 16 November 2026

Both errors mean the request did not carry a key Mailcandor recognises.

{ "error": { "type": "missing_api_key", "message": "Add your API key as \"Authorization: Bearer mc_live_...\"." } }
{ "error": { "type": "invalid_api_key", "message": "This API key is not valid. It may have been revoked." } }

Fix missing_api_key

The request had no bearer token. Send the header exactly like this:

Authorization: Bearer mc_live_xxxxxxxxxxxxxxxx

Common causes:

  • The word Bearer and a space are missing.
  • The environment variable is empty in this environment. Print its length (not its value) at startup: console.log((process.env.MAILCANDOR_KEY || '').length).
  • A proxy or framework strips the Authorization header.
  • For the Postmark-compatible endpoints, the key goes in X-Postmark-Server-Token instead; that works too.

Fix invalid_api_key

The key was sent but does not match an active key.

  1. Check it is complete. Keys start with mc_live_. Copying often drops the last characters or adds a space or newline. Trim the value.
  2. Check it still exists. Open API keys. Keys show their first characters (for example mc_live_a1b2c3…). If yours is not in the list, it was revoked.
  3. Check the team. If you are on several teams, the key may belong to another one.
  4. Check the base URL. Use https://api.mailcandor.com. A key sent to another provider’s URL, or another provider’s key sent to Mailcandor, fails.
  5. Check the audit log (admins): api_key.revoked shows who revoked it and when. A key locked to a domain is deleted when that domain is deleted (domain.deleted).

Test the key on its own:

curl https://api.mailcandor.com/v1/whoami \
  -H "Authorization: Bearer $MAILCANDOR_KEY"

A 200 shows the team, key name and permission. A 401 confirms the key is the problem.

Create a new key

Keys are shown once and cannot be recovered. Open API keys, press Create API key, choose Sending only for apps, copy the key into your secrets store, and redeploy. See Create an API key.

SMTP

The same problem over SMTP looks like:

  • 535 5.7.8 Use the username "mailcandor" and an API key as the password. The username is wrong or the password is empty.
  • 535 5.7.8 That API key is not valid. It may have been revoked.

The username is always mailcandor, and the password is the full API key. See SMTP connection failed.

If it does not work

  • 401 only in production. The production environment has an old or empty variable. Redeploy after updating it.
  • 401 after moving from another provider. You are still sending the old provider’s key. Mailcandor needs an mc_live_ key. See Switched provider and it does not work.
  • It is a 403, not a 401. The key works but is sending-only or locked to another domain. See API key best practices.

See the API reference for authentication.

Questions

My key worked yesterday. Why 401 today?

It was probably revoked, or the domain it was locked to was deleted, which deletes the key too. Check the audit log for api_key.revoked or domain.deleted.

Can I recover a revoked key?

No. Revoking cannot be undone. Create a new key.

Is 401 the same as 403 restricted_api_key?

No. 401 means the key is not recognised at all. 403 restricted_api_key means the key is valid but not allowed to do that.

I get 535 over SMTP. Is that the same problem?

Yes. SMTP answers 535 when the username is not mailcandor or the API key used as the password is not valid.

Related

Send with someone on your side.

Unlimited domains on every plan, a person before any block, and 3,000 emails a month free. Tell us what you send and we set you up within one business day.