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

# Authentication and authorization

#### Bearer is the header scheme, not the credential type

For the documented REST operations, the portable default is:

```http
Authorization: Bearer YOUR_CREDENTIAL
```

A personal API key and a user access token are different credentials even when both use this header. Personal keys begin with `sk_`. They are tied to an owner and organization, can expire or be revoked, and remain bounded by the owner's live permissions. A JWT is a user session access token governed by the organization's sign-in and MFA rules. Do not use an ID token or refresh token in place of an access token.

| Surface                           | Credential to use                                                                   | Important distinction                                    |
| --------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------- |
| v1 knowledge bases and v2 REST    | Personal API key in Bearer; authenticated user JWT where supported                  | Resource access and permission checks still apply        |
| `/inference/v0/...`               | Personal API key in Bearer; legacy organization public key where still enabled      | These are API-key routes; do not assume a user JWT works |
| Legacy `/analytics/org/...`       | Personal API key in Bearer; legacy organization **private** key where still enabled | The legacy public key is not the analytics credential    |
| SCIM Users and Groups             | Dedicated SCIM token in Bearer                                                      | Not a normal personal API key or user session token      |
| Webhook deliveries to your server | Verify webhook signature headers                                                    | The signing secret is not a StackAI REST API key         |

#### What about X-API-Key?

Some endpoints accept the raw personal key as `X-API-Key: sk_...`. Other public routes explicitly read the Bearer authorization header. **X-API-Key is not a universal substitute across these APIs.** All examples in this documentation use Bearer. Do not send both headers: mixed JWT/key credentials or different keys can be rejected as ambiguous or conflicting. Use the exact `Bearer` spelling in examples.

| Endpoint family                                              | Personal-key header                                                                            |
| ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| `/v2/runs` and its run detail, resume, and cancel operations | `Authorization: Bearer sk_...` or `X-API-Key: sk_...`                                          |
| `/inference/v0/...` and legacy `/analytics/org/...`          | Use `Authorization: Bearer sk_...`; do not substitute `X-API-Key`                              |
| Other REST examples in this guide                            | Use the documented `Authorization: Bearer sk_...` form                                         |
| `/scim/v2/...`                                               | Use the dedicated SCIM token in `Authorization: Bearer`; a personal key is not interchangeable |

For example, read a run with the alternative personal-key header:

```bash
curl --fail-with-body -sS "$STACKAI_BASE_URL/v2/runs/$RUN_ID" \
  -H "X-API-Key: $STACKAI_API_KEY"
```

Obtain personal API keys in StackAI settings. Obtain user access tokens through your organization’s supported sign-in flow. These API routes do not provide a public password-grant login endpoint.

#### Scope and resource access both matter

A scope grants no extra access beyond the key owner's current permissions. A key can carry `kbs.read` and still fail to read a knowledge base the owner cannot access. A project can be in the same organization yet unavailable because of folder permissions. Review the permission note on each endpoint.

Typical minimum sets:

| Task                                     | Permissions/scopes                                                                                    |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Inspect a project's IO                   | `projects.read`                                                                                       |
| Start/resume/cancel v2 runs              | `projects.run`                                                                                        |
| Poll/list v2 runs                        | `analytics.read`                                                                                      |
| Read a v2 pause token                    | Both `analytics.read` and `projects.run`                                                              |
| Create, upload, poll, search a KB        | `kbs.create`, `kbs.index`, `kbs.read`, `kbs.query`                                                    |
| Sync a KB                                | `kbs.sync`                                                                                            |
| Browse providers/connections; run action | `connections.read`; `connections.use`                                                                 |
| Manage evals                             | Relevant `evals.read/create/update/delete/run`; trace-backed operations also require `analytics.read` |
| Manage skills                            | Relevant `skills.read/create/update/delete`                                                           |
| Manage outbound webhook subscriptions    | `org.webhooks.manage`                                                                                 |

Webhook management is not an assignable scope in the current personal-key scope picker. Use an authorized user session for this administrative workflow; an existing unscoped key remains subject to its owner's live permissions. Do not widen a production integration's credential just to avoid a scope error.

Store keys in a server-side secret manager. Do not embed them in browser JavaScript, mobile binaries, URLs, screenshots, or logs. Put your own authenticated backend between an end-user interface and these APIs. Rotate compromised credentials and update dependent services. An embed-session credential has a restricted surface and is not a general-purpose REST key.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/stackai-api/stackai-api-developer-guide/authentication-and-authorization.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
