Skip to main content

Authentication Errors

Authentication and authorization problems can include an invalid or inactive API key, an unusable access token, an invalid, expired, or already-rotated/ revoked refresh token, or an invalid X-SubAccount-Id.

Verified status codes​

SituationStatusNotes
Invalid or inactive API key401Token exchange (POST /api/v1/auth/token). An inactive key answers exactly like an unknown one, ApiKey.Unauthorized
API key that is not in the Mailhub key format422ApiKey.InvalidFormat — the value can never be a key, so it is a validation outcome, not a 401
Request from an address outside the key's IP allowlist401ApiKey.Unauthorized, the same code as an invalid key, on token exchange and on every authenticated operation — see IP allowlist
Missing, empty, or whitespace-only required field (apiKey, refreshToken)422Fails validation before any lookup, so it is never a 401
Unrecognized, expired, or already-rotated/revoked refresh token401Refresh answers 401 for a token that can no longer be used. Revoke has one documented exception: a token Mailhub has already revoked — by an earlier revoke or by refresh rotation — answers 200 again. That is the bounded behaviour, not blanket idempotency; a token Mailhub does not recognize still answers 401
Malformed X-SubAccount-Id (not a GUID)400
X-SubAccount-Id for a sub-account that doesn't exist or belongs to another account404
X-SubAccount-Id for a sub-account that is inactive409

IP allowlist​

When an API key has an IP allowlist, a request from any other address is refused with 401 ApiKey.Unauthorized. The code is deliberately the same as for an invalid key, so the response does not reveal that the key exists. If a key that worked starts answering 401 after a network change, check the allowlist before rotating the key.

Recover safely​

Confirm that the correct environment credential is active and that the Authorization value is present without logging it. When the access token is no longer usable, attempt one refresh; if it fails, stop and authenticate again. Do not treat every authentication failure as token expiry and never create an infinite refresh loop.

See Authentication for the token flow.