x-api-token— a long-lived JWT issued from Settings → Developer → API Tokens. Used by server-to-server scripts.Authorization: Bearer <token>— short-lived user-session tokens scoped to a single organisation. Used by MCP clients, the admin panel’s internal calls, and any tooling that impersonates a logged-in user.
Use Bearer tokens when the caller represents a specific user session (e.g. an AI agent acting on behalf of a signed-in admin). Use
x-api-token for headless integrations.How the two differ
x-api-token | Authorization: Bearer | |
|---|---|---|
| Issuer | Admin panel → Developer settings | Nudj auth service (NextAuth) at sign-in |
| Audience | Scripts, CI, backend integrations | Interactive user sessions, MCP clients |
| Lifetime | Long-lived (rotate manually) | Short-lived (session TTL) |
| Organisation scope | Embedded in token claims | Enforced at the middleware by the token + x-api-domain combination |
| Revocation | POST /auth-config/tokens/{tokenId}/revoke | Sign out or let the session expire |
Making a request
Authorization: Bearer <token>— your session token.x-api-domain— the exact API domain the token is scoped to. This tells Nudj which organisation’s subdomain to route the request through.
403 if they diverge.
Organisation scoping (why this matters)
Before bearer-token org scoping shipped, a session minted for org A could — under specific routing conditions — be used against org B’s API if the caller changed the subdomain. That cross-tenant leak is closed: every Bearer request is checked at the middleware layer against both the token’s claimedorganisationId and the x-api-domain header.
Don’t attempt to work around the scope check. If you need to call a different organisation’s API, sign in to that organisation and obtain a fresh token. Sharing tokens across orgs silently won’t work and will always return 403 Forbidden.
Error cases
| Status | Cause |
|---|---|
401 Unauthorized | Missing header, token expired, or signature invalid |
403 Forbidden | Token valid but scoped to a different organisation than x-api-domain |
404 Not Found | x-api-domain points to a subdomain that doesn’t exist |
Where to get a token
Bearer tokens are minted by the Nudj auth layer when a user signs in. Two common paths:- Interactive admin session: sign into the admin panel at
https://{subdomain}.nudj.cx/admin. The session cookie is exchanged for a Bearer token on each admin API call automatically. - MCP client: follow the MCP Bearer + Domain header pattern —
mcp-remoteand Claude Code inject both headers from a token copied out of the admin panel.
Security considerations
- Store tokens in OS keychains or secret managers, never in source.
- Rotate tokens when a team member leaves or any suspicion of compromise.
- The middleware-level org scope check is a defence-in-depth measure, not a replacement for least-privilege RBAC on the token itself.
Related
x-api-token Authentication
The long-lived token path for headless integrations.
MCP Bearer + Domain Headers
How AI clients (Claude, Cursor) configure the headers.

