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

# Authentication

Every request to `/api/v1` (other than the public discovery endpoints `/api/v1/openapi.json` and `/.well-known/agent-tools.json`) requires an API key.

## Obtain a key

Admins create keys in the admin app under **Settings → API Keys**. Each key:

* Is tenant-scoped — one key cannot operate across multiple tenants.
* Carries one or more **scopes**: `read`, `commerce`, `admin`.
* Has a **rate-limit tier**: `standard`, `premium`, `unlimited`.

Keys look like `pk_<64 hex chars>`. The plain-text value is shown only once at creation; only its SHA-256 hash is stored on disk.

## Sending a key

Use either header on every request:

```
Authorization: Bearer pk_<your_key>
```

…or:

```
X-API-Key: pk_<your_key>
```

Both are equivalent. If both are present, `Authorization` wins.

## Scope hierarchy

Scopes nest:

```
admin  ⊃  commerce  ⊃  read
```

So an `admin` key satisfies a `commerce` requirement, which satisfies a `read` requirement. Each endpoint declares the minimum scope it needs; this is shown on every reference page.

For example: reading the catalog or fetching a cart needs `read`; creating or modifying a cart, adding or removing items, and applying or clearing a promo code (the commerce surface) need `commerce`; managing API keys or webhooks needs `admin`. A `read`-only key receives `403 Forbidden` on any commerce write.

## Errors

| Status             | Reason                                             |
| ------------------ | -------------------------------------------------- |
| `401 Unauthorized` | No key, unknown key, or revoked key                |
| `403 Forbidden`    | Key is valid but does not carry the required scope |

```json
{
  "error": "Insufficient scope. Required: 'commerce'. Your key has: [read]."
}
```

## Revoking a key

Revoke a key from the admin app. Revocation takes effect immediately and is recorded in the audit log.

## Best practices

* **Never** ship a key in client-side code.
* Use the **least-privilege** scope. Read-only integrations should use `read` keys.
* Rotate keys periodically. Issue a new key, switch your integration, then revoke the old one.
* If a key may be exposed (e.g. logged accidentally), revoke it immediately and re-issue.

## Related

* [Base URL & environments](/developers/api-reference/base-url.md)
* [Rate limits](/developers/api-reference/rate-limits.md)
* [Errors](/developers/api-reference/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.peakcommerce.com/developers/api-reference/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.
