unauthenticated

HTTP 401 Don’t retry REST and MCP

The request carried no usable bearer credential, so there is no principal to authorise and the server stopped before looking at what you asked for.

How to fix it

  1. Send Authorization: Bearer <credential> on every request.
  2. Check the key prefix against the environment you are calling. A credential is efa_live_ or efa_test_ followed by eight hex characters and a 43-character body, and the secret is returned exactly once at creation.
  3. For /mcp, use the access token from a completed OAuth connection. Console sessions and API keys are refused there by the OAuth layer before they reach the API.
  4. Rotate rather than retry. This code is not retryable and a credential that failed verification will keep failing.

Which rule fired

Credential resolution happens in one place and fails closed. A missing Authorization header, a key that does not verify, an expired key and a credential whose authority has been withdrawn all return this code, and the message says which. Authority is re-read on every request rather than trusted from the token, so a credential that worked yesterday can return this today: revoking a connection, or the person who authorised a credential losing their membership, ends its access on the next call.

In error.messageMeans
Missing bearer credential. The Authorization header is absent or empty.
Invalid API key. An API key is malformed, unknown, revoked, or its secret does not match the stored digest.
API key expired. An API key's expiry has passed.
Invalid or expired credential. A bearer token that is not an API key does not verify, or it has expired. Verification failure and expiry are not distinguished in the response.
Credential or its authorizer is no longer active. A connection was revoked or has expired, a parent key the credential was minted from was revoked, or the person who authorised it no longer has an active membership in the workspace.
Wrong token audience. An MCP access token names a different resource than the one this server answers for.
Sign-in required. Creating a workspace with no Authorization header.
Human sign-in required. Creating a workspace with an API key, an MCP access token, or a session token that does not verify. Only a signed-in person can create one.

Why it works this way: Revocation is immediate because nothing is cached in the token. The bearer value is a lookup handle, and the authority behind it is read from current database state on each request, so removing a person removes every credential they authorised at once.

Example

GET /v1/me → 401
{
  "error": {
    "code": "unauthenticated",
    "message": "Missing bearer credential.",
    "request_id": "req_8Kd2x91",
    "retryable": false,
    "details": {}
  }
}

At the MCP server, a missing, unknown or expired access token is refused by the OAuth layer first: a 401 with WWW-Authenticate, and an invalid_token body when a token was sent. This body comes back when the connection behind a valid token is no longer active, or the token names another resource.

Where it appears

  • Every /v1 route
  • GET /me
  • POST /workspaces
  • POST https://mcp.emailforagents.ai/mcp

Paths are relative to https://api.emailforagents.ai/v1.

View as Markdown

Search docs