> ## Documentation Index
> Fetch the complete documentation index at: https://docs.akua.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Authenticate with the Akua API using a browser session or a personal API token

Every API request requires an `Authorization: Bearer` header with a valid token.

| Method | Format | Best for |
| - | - | - |
| Session credential | Issued after browser sign-in | Dashboard and CLI device sessions |
| Personal API token | `sk_akua_...` | CI/CD, scripts |

For CI/CD and scripts, **personal API tokens** are recommended.

## CLI browser/device authentication

Use browser/device authentication for interactive terminal and coding-agent
onboarding:

```bash
akua auth login
akua auth status --json
```

The CLI opens Akua's device page and waits for you to approve the displayed
code. Use `akua auth login --no-browser` on a remote terminal and open the
displayed URL yourself. The CLI stores the resulting credential locally only
after approval.

The flow uses the
[OAuth 2.0 Device Authorization Grant](https://datatracker.ietf.org/doc/html/rfc8628),
so the CLI never handles your account password.

Terminal

akua auth login
shows a code

Browser

You approve
check the code matches

session token

CLI

Signed in
never sees your password

## Session credentials

Session credentials back browser-approved interactive sessions: the dashboard, and the CLI after `akua auth login`. They are validated server-side on every request.

For non-interactive environments such as CI/CD and scripts, use personal API tokens instead.

## Personal API tokens

Personal API tokens are long-lived tokens prefixed with `sk_akua_`. They're the recommended approach for CI/CD pipelines, scripts, and automated workflows.

A token belongs to **you** and acts as you. It never does more than your own roles allow, and you can narrow it further when you create it:

* **Workspace**: limit the token to one Workspace. It then acts in that Workspace only.
* **Roles**: limit the token to what a list of IAM roles allows, such as `roles/viewer` for a read-only token. The token may do only what one of those roles includes and what you may do yourself.

A token without either limit has your rights in every Workspace you belong to.

### Create a token

Create a token from a signed-in session, in the dashboard or with the [create endpoint](https://docs.akua.dev/api-reference/api-tokens/create-an-api-token.md). An API token cannot create another token. The response returns the full token once.

> [!WARNING]
>
> The `token` field is only returned once at creation time. Store it securely. It cannot be retrieved later.

Use it with the CLI:

```bash
akua auth login --token "$AKUA_API_TOKEN"
```

### List and revoke tokens

```bash
# List your tokens
curl https://api.akua.dev/v1/api_tokens \
  -H "Authorization: Bearer $AKUA_API_TOKEN"

# Revoke a token
curl -X DELETE https://api.akua.dev/v1/api_tokens/TOKEN_ID \
  -H "Authorization: Bearer $AKUA_API_TOKEN"
```

A revoked token stops working immediately.

## Workspace scoping

Many endpoints operate within a Workspace. Select it with the `Akua-Context` header:

```bash
curl https://api.akua.dev/v1/installs \
  -H "Authorization: Bearer $AKUA_API_TOKEN" \
  -H "Akua-Context: ws_xxx"
```

A token limited to one Workspace uses that Workspace when you send no header. An `Akua-Context` that names another Workspace returns `403 Forbidden`. Any other credential calling a Workspace endpoint without `Akua-Context` also returns `403 Forbidden`.

For Workspace discovery, call `workspaces.list` without `Akua-Context` to discover all Workspaces you can access, or select a Workspace to list only that one. A Workspace-limited token can discover only its own Workspace.

## Security

* Akua **never stores plaintext tokens**. Tokens are hashed before storage.
* Every API token carries a checksum, so a mistyped or truncated token is rejected at once and secret scanners can recognize Akua tokens.
* Tokens can have an **expiration date**. Expired tokens are rejected automatically.
* Each token tracks its **last used** timestamp for auditing.
* A revoked token stops authenticating requests immediately and cannot be recovered.

## Related topics

> [card] [API introduction](https://docs.akua.dev/apis/introduction.md)
>
> Base URL, conventions, pagination, and error codes.

> [card] [API tokens reference](https://docs.akua.dev/api-reference/api-tokens/list-api-tokens.md)
>
> Manage your API tokens programmatically via the API reference.

> [card] [CLI](https://docs.akua.dev/cli.md)
>
> Sign in, select workspace context, and run generated commands.

> [card] [OpenAPI specification](https://docs.akua.dev/apis/openapi.md)
>
> Download the spec and generate type-safe clients.
