> For the complete documentation index, see [llms.txt](https://docs.netmap.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.netmap.dev/api/authentication.md).

# API Authentication

NetMap REST API clients should authenticate with an API key unless they are part of the browser session flow.

## Recommended Method: API Key

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

```
X-API-Key: nm_<prefix>_<secret>
```

API keys are checked before bearer tokens or cookies. They authenticate as the owning user and inherit that user's current permissions.

Do not send API keys in query strings or as bearer tokens.

## First Test Request

```bash
API_URL="https://netmap.example.com"
API_KEY="<api-key>"

curl --fail-with-body \
  --request GET \
  --url "${API_URL}/api/v1/auth/me" \
  --header "X-API-Key: ${API_KEY}" \
  --header "Accept: application/json"
```

Expected result: JSON describing the user that owns the key.

## Other Auth Methods

The backend also supports:

* `Authorization: Bearer <access-token>`;
* `netmap_access` cookie;
* refresh-token cookie for `/api/v1/auth/refresh`;
* local login at `/api/v1/auth/login`;
* OIDC browser login endpoints under `/api/v1/auth/oidc/*`.

These are primarily used by the SPA. Automation should use API keys.

## Error Behavior

| Status | Meaning                                                              |
| ------ | -------------------------------------------------------------------- |
| `401`  | missing, invalid, expired, revoked, or inactive-owner authentication |
| `403`  | authenticated user lacks required permission                         |
| `429`  | API-key request limit or failed-lookup lockout exceeded              |

## Proxy Requirements

Reverse proxies must preserve `X-API-Key`. If direct requests work but proxied requests fail with `401`, check proxy header forwarding first.

## Related Pages

* [Generating API Keys](/api/generating-api-keys.md)
* [API-Key Permissions](/api/api-key-permissions.md)
* [API Errors](/api/errors.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.netmap.dev/api/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
