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

# Authentication

Carbon uses two credentials for two jobs:

| Credential      | Header                        | Held by                               | Used for                                                                                            |
| --------------- | ----------------------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------- |
| **Session JWT** | `Authorization: Bearer <jwt>` | The wallet owner (via the Carbon app) | Account setup: enable subaccounts, create API keys, delegate permissions, set instant-action tokens |
| **API key**     | `x-api-key: ix.<hex>`         | Your app                              | Programmatic trading and reads                                                                      |

The model: a wallet owner uses a JWT to create API keys and grant them permission; the keys then do the day-to-day trading. Configure once with the JWT, run continuously with the key.

### Session JWT

Account-management endpoints require a **session JWT** representing a signed-in wallet. You obtain it by signing in with your wallet in the Carbon app, then send it as a bearer token:

```http
Authorization: Bearer eyJ…
```

The token is bound to your wallet and expires; expired tokens return `401` and require a fresh sign-in. JWT-authenticated endpoints include `/v1/account-auth/*` and the API-key management routes.

### API keys

For everything automated, use an **API key**:

```
ix.a1b2c3d4…            (prefix "ix." + 64 hex characters)
```

> The `ix.` prefix is a legacy identifier; it's still the live key format.

Send it in `x-api-key`:

```http
GET /v1/positions/all?subaccountAddress=0x…&chainId=42161
x-api-key: ix.a1b2c3d4…
```

Manage keys (JWT-authenticated):

| Action              | Endpoint                             |
| ------------------- | ------------------------------------ |
| Create              | `POST /v1/api-keys/create`           |
| List                | `GET /v1/api-keys/list`              |
| Rename              | `PUT /v1/api-keys/{id}`              |
| Revoke              | `DELETE /v1/api-keys/{id}`           |
| Inspect permissions | `POST /v1/api-keys/list-permissions` |

> **The secret is shown once**, at creation, and can't be retrieved again. Capture and store it securely; if lost, revoke and create a new one.

### Granting a key access to a subaccount

An API key can do nothing until the subaccount is enabled for API access and the key is granted permissions. That setup — via the Carbon app (recommended) or the API — is covered in [Enabling API access](/developers/http-api/enabling-api-access.md).

Permissions: `ALL`, `OPEN_POSITION`, `CLOSE_POSITION`, `CANCEL_POSITION`, `VIEW_DETAILS`. A key lacking a permission is rejected with `403`.

### Best practices

* **Never expose an API key** in a browser, mobile app, or public repo. Keep it server-side — it's a bearer credential.
* **Scope narrowly** — delegate only the permissions a key needs; avoid `ALL`.
* **One key per app/environment** — makes rotation and revocation surgical.
* **Rotate and revoke** — revocation is instant via `DELETE /v1/api-keys/{id}`.
* **Always HTTPS.**

### Failures

| Status | Meaning                                                    |
| ------ | ---------------------------------------------------------- |
| `401`  | Missing/invalid/expired JWT, or unknown/revoked API key.   |
| `403`  | Authenticated, but the key lacks the delegated permission. |


---

# 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.carbon.inc/developers/http-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.
