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

# Sonar authentication

> Authenticate with a personal or organization secret key, and what each one may read and write.

Every Sonar request carries a Turtle **secret** API key (`sk_live_`), either as a bearer token or on the `X-API-Key` header. A request with no key answers `401`.

```http theme={null}
Authorization: Bearer sk_live_xxxxx
```

```http theme={null}
X-API-Key: sk_live_xxxxx
```

> [!WARNING]
>
> Publishable keys (`pk_live_`) do not open Sonar: they are refused with `401`, like a missing key. Sonar holds your team's conversations, so a key that reads it belongs on a server or in a secret store, never in browser code.

## Two kinds of key

| | Personal key | Organization key |
| - | - | - |
| Made by | Any member, on their account page | An owner or admin, in the organization's settings |
| Reaches | Every organization you are a member of that has Sonar | Its own organization only |
| Acts as | You, as your dashboard session does | An agent of the organization, and no one person |
| Reads events | The ones you can read | The ones the team holds |
| Its writes are recorded as | Yours, or your agent's with `source: "ai"` | An agent's |

A personal key and your dashboard session are alike: what you may do in Sonar while signed in, your key may do through the API, and it is recorded as you. That makes it the right choice for your own scripts and assistants. An organization key acts as an agent: it suits a shared service that works for the whole team, and it cannot make the decisions a person answers for.

### Personal keys

* **Made on your account page.** Sign in to the [dashboard](https://dashboard.turtle.xyz), open your [account page](https://dashboard.turtle.xyz/account) and find **Personal API Keys**. The secret is shown once.
* **Acts as you**, as your dashboard session does, in the organizations you are a member of: your role, your permissions, the events you may read, and your name on its writes. A request for an organization you are not a member of answers `403`.
* **Expires after 90 days** unless you choose another expiry when you create it. You can hold at most five active personal keys; revoke one to make another.
* **A key cannot make keys.** Creating and revoking keys takes a signed-in session in the dashboard.

### Organization keys

* **Made by an owner or admin** in the organization's settings in the dashboard, under **API Keys**, with the **Secret** type.
* **Reaches its own organization only.** A path that names another organization answers `404`.
* **Acts as an agent.** Every write owes a rationale and evidence, and passes the permissions your workspace set for Sonar's agent. See [Writing](https://docs.turtle.xyz/sdk/sonar/conventions.md#writing).
* **Decides nothing for the organization.** The calls in [What takes an owner or admin](#what-takes-an-owner-or-admin) refuse it.

## Writing as your assistant

With a personal key, a write may send `"source": "ai"` (`?source=ai` on a DELETE). It is then recorded as your agent's write, with you as its user: it owes a rationale and evidence, and passes the same permissions as any agent write. Leave `source` out for a write that is your own.

## What a key may read

Some events are not every reader's to see, such as a message on a member's personal account, or in a group only its members may read. A key reads them as a person in Sonar would:

* A **personal key** reads what you can read.
* An **organization key** reads what the team holds.

An event the key may not read comes back **sealed**: its stub, with `sealed: {reason, conversationKind}` and no payload, sender or conversation. You can still cite it by its ID. Searches and filters that look inside events never match a sealed one.

## What takes an owner or admin

Some calls are a decision for the organization, and a person answers for each one. They take an owner or admin of the organization, with their personal key or their dashboard session:

* Deciding drafts: `POST /mutations/{id}/approve`, `POST /mutations/{id}/reject` and `POST /reports/{id}/decide`.
* Permission policies: `GET` and `PUT /permissions`.
* Changing what Sonar keeps: retention, forgetting, and deleting the organization's Sonar data (`/data/...`).

An organization key is refused on these calls with `403`, because it acts as an agent and nobody answers for what an agent decides. A personal key whose owner is a member of another role is refused too.

## Keep keys secret

Treat a key like a password. If one leaks, revoke it where it was made (your account page, or the organization's settings) and create a new one.

## Authentication errors

| Status | Meaning |
| - | - |
| `401` | No usable key: missing, wrong, revoked, expired or publishable. Every case answers the same. |
| `403` | The key works, but its organization does not have Sonar, a personal key's owner is not a member of the organization in the path, or an organization key called something that [takes an owner or admin](#what-takes-an-owner-or-admin). |
| `404` | An organization key used on a path that names another organization. |

These are answered before the request reaches an endpoint, with a plain-text body rather than JSON. See [Errors](https://docs.turtle.xyz/sdk/sonar/conventions.md#errors).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.