---
title: Authentication
description: API keys, scopes and headers for REST, plus the bearer JWT agent runtimes use for MCP — two credential types over a single identity and permission surface.
---

# Authentication

Authenticate REST calls with an API key in the `X-API-Key` header;
MCP agent runtimes use a bearer JWT. An agent without an account needs
neither: it pays per calculation, see [Pay per call](./pay-per-call.md).
The two credential types sit over one identity surface:

| Surface | Credential | Use case |
|---|---|---|
| **REST** | API key in `X-API-Key` | Server-to-server integrations, scripts, CI |
| **MCP** | API key **or** session JWT, as `Authorization: Bearer` | Agent runtimes — Claude Code, Cursor, custom |
| **Dashboard** | Session JWT + refresh + MFA | Humans in the browser |

> API keys never grant admin-plane access. Billing, member invites,
> the credential vault, SSO/SCIM, and tenant settings stay JWT-only. A
> leaked key has a bounded blast radius — its minted scope set is the
> maximum reach.

---

## API keys

### Minting a key

From the dashboard:

1. Sign in.
2. **Settings → API keys → New key.**
3. Name it (e.g. `production-erp-sync`), pick scopes, copy the plaintext.
4. The plaintext is shown **once**. We store a one-way Argon2 hash and
   cannot recover it. If you lose it, revoke and re-mint.

Keys can also be minted programmatically with the `api-keys` API using a
**user session JWT** (an owner or admin whose email is verified) — the
plaintext is returned **once**. Unknown scopes are dropped against the
catalog below; if *every* requested scope is unknown the call returns
`400 bad_request`. API keys themselves cannot mint other keys — key
management requires a user JWT, so a compromised key can never create a
successor with broader scope.

### Format

```
ak_live_dXt8q2Rb_9f3c…6Pk
└┬┘ └┬─┘ └──┬───┘ └───┬───┘
 │   │     │          └─ secret (shown once, never stored in plaintext)
 │   │     └──────────── public prefix (identifies the key in logs / lists)
 │   └────────────────── mode: "live" or "test"
 └────────────────────── key marker
```

### Sending a key

API keys go in the `X-API-Key` header:

```http
X-API-Key: ak_live_…
```

> `Authorization: Bearer …` is reserved for **user/MCP JWTs** and is not
> a valid transport for an API key. Put API keys in `X-API-Key`.

If your key is scoped to a tenant with more than one organization, add
`X-Org-Slug: <slug>` to pin the org context.

### Test vs live keys

| Prefix | Cost | Notes |
|---|---|---|
| `ak_test_…` | €0 | Sandbox keys. Refused in the production environment. |
| `ak_live_…` | Billed | Real traffic. |

Mint test keys for CI; mint live keys for production deployments.

### Rotating a key

Rotate a key from the dashboard (or the `api-keys` API). Rotation keeps the
name, scopes, and `expires_at` intact and issues a fresh secret, returned
with its plaintext exactly once. Deploy the new key **first**, then rotate —
the old secret stops working immediately.

### Revoking a key

Revoke a key from the dashboard. Revocation is immediate — requests with the
revoked key get `401` (`invalid_api_key`) from the next request onward.

A key also stops working, with the same `401`, once the member who created
it is deactivated or leaves the organization, whether they are removed in
the dashboard or deprovisioned by your identity provider. Create integration
keys from an account that stays with the organization.

### Listing keys and their scopes

View your keys in the dashboard. The list shows each active key's `prefix`,
`name`, `scopes`, and `expires_at` — never the plaintext. Key management is
a user-session (owner/admin) operation, so it isn't reachable with an API
key.

### Checking a key: `GET /whoami`

`GET /api/v1/whoami` answers who the calling credential is, for any key and
whatever its scopes: its organization (`id`, `name`, `slug`), its kind
(`api_key`, `oauth_grant` or `session`, with a key's `name` and `prefix`,
never its secret), `scopes` and `effective_scopes` (the scopes plus those
they imply: `parts:write` also covers `setup:write` and `calibration:write`),
the `plan`, and the costing environment a calculation that names none is
priced in (`default_costing_environment_id`, with
`default_costing_environment_source`). Read-only and free; call it first
when a key answers `403`.

```bash
curl https://api.arcnm.io/api/v1/whoami -H "X-API-Key: $ARCNM_API_KEY"
```

---

## Scopes

Scopes follow `<resource>:<action>`. Mint the **narrowest** set you can:
a leaked `parts:read` key cannot trigger a billable calculation.

| Scope | Lets the holder |
|---|---|
| `parts:read` | List + read parts, revisions, **and calculation results** |
| `parts:write` | Create / update / delete parts and revisions, **and create + run calculations** (billable). Also covers everything `setup:write` and `calibration:write` cover |
| `setup:write` | Set up and change costing environments and what they price with: machines, tools and their own cutting data, materials and their prices, stock formats, subcontractors, rates, economics and the master-data imports. Starts no calculation |
| `calibration:write` | Calibrate an environment to your own history: outcomes, actual costs, ERP work orders and the calibration imports. The import's price step runs calculations of the imported parts and is **billable** |
| `countries:write` | Take one of your plan's ARCNM countries: install an environment, or move one, into a country your organization does not price in yet (the install and the move also need `setup:write`). Without it a key installs only in the countries your organization prices in. No other scope implies it, `parts:write` included. It lasts while the person who created the key is an owner or admin of the organization. API keys only: an OAuth grant acts with its user's role, so an owner's or admin's grant takes a country without it |
| `uploads:read` | List + read existing uploads |
| `uploads:write` | Upload new CAD / drawings / RFQ text |
| `webhooks:read` | List webhook endpoints and deliveries |
| `webhooks:write` | Create / update / delete webhook endpoints |

> **Calculations authorize on `parts:read` / `parts:write`.** Finer-
> grained `parts:calculations:read` / `parts:calculations:write` scopes
> exist in the catalog for forward compatibility, but calculation
> endpoints currently enforce `parts:read` (reads) and `parts:write`
> (create + run). To run a calculation, mint a key with `parts:write`.

> **Setup and calibration have scopes of their own.** A key or grant made
> to set up the shop or to calibrate it needs only `setup:write` or
> `calibration:write` (with `parts:read` to read what it changes). A
> `setup:write` key starts no calculation; a `calibration:write` key starts
> only the ones a calibration import disclosed before its price step.
> `parts:write` still covers both,
> so a key minted before they existed keeps every write it had. Over MCP, a
> grant that names `setup:write` also lists the `setup` toolset, and one
> that names `calibration:write` the `calibration` toolset, without a
> header — see [MCP](./mcp.md#toolsets). Reading an upload back as a table
> for an import needs `uploads:read`.

> **Admin scopes don't exist.** Plan changes, member invites, SSO/SCIM,
> credentials, OAuth provider config, the wallet and the audit log are
> human-dashboard-only. Machine keys cannot reach those surfaces by design.
> A scope is a restriction: a key holds exactly the scopes it was minted
> with, whoever created it.

---

## Required headers

Every authenticated REST request includes:

```http
X-API-Key:    ak_live_…
Content-Type: application/json    (or multipart/form-data for uploads)
```

Recommended:

```http
Idempotency-Key:  9c5f-… (UUIDv4 from your client — see Idempotency)
X-Org-Slug:       your-org-slug   (required only for multi-org tenants)
```

We stamp `X-API-Version` and `X-Request-ID` on **every response**. Echo
the request id when filing a support ticket — we can pull the
structured log row in one query.

---

## MCP authentication

The MCP server at `https://api.arcnm.io/mcp-server/mcp` is a bearer-token
protected resource and publishes
[RFC 9728 protected-resource metadata](https://datatracker.ietf.org/doc/html/rfc9728)
at `/.well-known/oauth-protected-resource`. The verifier accepts **either**
credential in the `Authorization: Bearer …` header:

- an ARCNM **API key** (`ak_live_…` / `ak_test_…`) — the same key you use
  for REST, just carried as a bearer token (tried first); or
- a tenant-scoped **session access token** (a JWT, audience-pinned to
  `/api/v1`). Refresh tokens and tokens for other audiences are rejected.

Most agent setups use an API key — it's long-lived, revocable, and
scoped. Supply it to your agent runtime's client config — see
[MCP](./mcp.md) for the exact `claude mcp add` / Cursor `mcp.json`
snippets. Note the MCP door only reads the `Authorization: Bearer`
header — there is no `X-API-Key` transport on the MCP server (that header
is REST-only).

---

## Verifying webhook payloads server-side

ARCNM signs every webhook with the per-endpoint secret using the
[Standard Webhooks](https://www.standardwebhooks.com/) scheme. Verify
the `webhook-signature` header before trusting a delivery — see
[Webhooks → verifying signatures](./webhooks.md#verifying-signatures).

---

## See also

- [Errors](./errors.md) — `401 invalid_api_key`, `403 insufficient_scope`.
- [Rate limits](./rate-limits.md) — per-key and per-caller limits.
- [Versioning](./versioning.md) — the `X-API-Version` response header.
- [MCP](./mcp.md) — bearer auth, tenant scoping, exposed tools.
