# Authentication (/api/authentication)

Every call says who it is for in the `Authorization` header. There are three ways in.

## An access token, for a person [#an-access-token-for-a-person]

Most operations act for a person: your tool asks them to allow it, and then acts with exactly their access, in every
organization they belong to: the products they can open and the role they have there. There are no narrower scopes. Heuristic is an OAuth 2.1 authorization server:

1. Read the server's details at `/.well-known/oauth-authorization-server` on your Heuristic app's address. They name
   the authorization, token and registration endpoints.
2. Register your tool once: with dynamic client registration at the registration endpoint, or by using the address
   of a client ID metadata document as your client ID.
3. Send the person to the authorization endpoint with the authorization code flow and PKCE (`S256`). They sign in to
   Heuristic and allow your tool. Ask for the `offline_access` scope to get a refresh token as well; `openid`,
   `profile` and `email` are also available.
4. Exchange the code at the token endpoint, then send the token on every call:
   `Authorization: Bearer <access token>`.

A call without a usable token answers `401` with the code `unauthorized`. The person can see and disconnect the apps
they allowed in Settings → Personal → MCP server, which ends your tool's access.

Calls with access tokens are limited per person, across all their apps; [Conventions](/api/conventions) names the
limits and what happens at one.

## An API key, for a script or another tool [#an-api-key-for-a-script-or-another-tool]

An API key lets a script or another tool call the API without anyone signing in. Keys are created only in the
Heuristic web app and shown once:

- A **personal key** (Settings → Personal → My API keys) acts as its person in one of their organizations, with exactly
  their access there, checked on every call: when their role or product access shrinks, so does the key's reach, and
  it stops working while they are disabled.
- An **organization key** (Settings → Organization → API keys, created by Admins) acts for the organization, not a
  person, and keeps working when the Admin who made it leaves. It can see and change every product and its feedback
  as an Admin can, but not people, product access, CRM connections or the organization's settings, and it can't
  delete a product. Those calls answer `403` with the code `api_key_not_allowed` and "Organization keys can't do
  this. Use the Heuristic web app."

A key starts with `ha_`. Send it on every call as `Authorization: Bearer ha_…`. Keys made before the rename to Heuristic start with `fsa_` and keep working. A feedback endpoint's key starts with `hk_` (older ones with `fsk_`, which keep working). It reaches only its own
organization: others answer `404`.

Each key is **Full access** or **Read only**. A change with a read-only key, a dry run or sending feedback included,
answers `403` with the code `read_only_key` and "This API key is read only. Use a full-access key to make changes."
No key can change the person's account or organizations: those calls answer `403` with the code
`api_key_not_allowed` and "API keys can't change your account or organizations. Use the Heuristic web app." Keys
can't create keys or manage the organization's API keys either.

A wrong, expired or revoked key, or the key of a member who was disabled, answers `401` with the code `unauthorized`
and "This API key isn't valid. It may have expired or been revoked."

Keys work only on the API under `/v1`. The MCP server refuses them with "API keys work only on the Heuristic API
(/v1). AI agents connect to the MCP server by signing in." `GET /v1/me` answers who a key acts for, with the key's
own name, kind, organization and access under `apiKey`. The person and their Admins list and revoke keys in the web
app, the API and MCP. [Conventions](/api/conventions) names the limits on calls with a key.

## A feedback endpoint key, for sending feedback [#a-feedback-endpoint-key-for-sending-feedback]

Sending feedback (the `send_feedback` operation) takes a feedback endpoint's key, so a form, a support tool or a
script can send feedback without anyone signing in. A product Owner adds an endpoint in the product's **Feedback
sources** with **Add endpoint**, or with the `add_feedback_endpoint` operation, and sees its key once. Send it as
`Authorization: Bearer <key>`; it works for `send_feedback` only. A wrong or revoked key answers `401` with the code
`invalid_key`. A key only sends feedback to its own product; revoking the endpoint stops it at once.

`send_feedback` also takes the person's access token, so an app or agent signed in as a product Owner (an Admin, or
a User with Owner access to the product) can send feedback without a key. The feedback's source then names the app
and the person, for example "via Claude (Jasper Bakker)", and the app is not listed in **Settings → Product → Feedback sources**. A
full-access API key sends feedback too: a personal key as its person, under the same rule, the source reading, for
example, "via API key "Weekly report" (Jasper Bakker)", and an organization key to any product of its organization,
the source reading "via API key "Salesforce sync"". A Viewer of the product is refused with `403` "Only product Owners can add feedback.", and someone who can't open the
product gets `404`; disconnecting the app stops it. Send an
`externalId` with each piece of feedback: a repeat by the same person through the same app answers the feedback it
stored, so a retry is safe.

## Calls with no authentication [#calls-with-no-authentication]

The health check (`GET /v1/health`) and the list of CRMs Heuristic can connect (`GET /v1/crm-connectors`) need no
authentication.