# Keys and PINs

A **world key** names one world and says what the caller may do in it. The **PIN** proves the caller may write. Both are managed in the [account portal](https://www.onlyworlds.com/account/), where keys are minted and revoked. A world's keys are on its page under Access; `https://www.onlyworlds.com/account/worlds/<world_id>/keys` opens them there for the world's owner, after a sign-in if one is needed.

## Headers

```http
API-Key: {key}
API-Pin: {pin}
```

The header names are exactly `API-Key` and `API-Pin`. A world key alone determines the world, so a request made with one passes no world id; an [account token](#account-tokens) and a read of an [open world](/docs/development/api/public) name it with `?world=<id>`.

## Key types

| Key | What it is | Reads | Writes |
|:--|:--|:--|:--|
| `ow_w_…` | World write key | Key alone | Key and PIN |
| `ow_r_…` | World read key | Key alone | Refused: `403` [`permission_error`](/api/errors/#permission_error) |
| 10-digit legacy key | The original world key | Key and PIN when the world has a PIN, open to the public or not; the demo keys `0000000000` to `0000000009` read with the key alone | Key and PIN |
| `ow_a_…` | Account token | Acts on your account, not on one world: see [Account tokens](#account-tokens) | |

- Each world key (`ow_w_`, `ow_r_`, legacy) is scoped to one world.
- Legacy 10-digit keys keep working and stay valid. New ones are no longer issued: mint a prefixed key instead.
- The one exception is your own act: the world page on onlyworlds.com can retire a world's legacy key for good. From then on it answers `401` [`invalid_credentials`](/api/errors/#invalid_credentials) on every door (this API, the Classic API, MCP and worldsync), as an unknown key would. Demo keys can't be retired.
- A new key is shown once, when it is minted. Key lists afterwards show only its last four characters. On onlyworlds.com the new key's box has **Copy instructions for your AI**: a message that has your AI write the key into its own `.env` file, say where, keep it out of version control, check the key and read the world's Charter when the check's answer names one; a write key's PIN line is left empty for you to type. The raw lines are under **Show the lines**.
- `ow_r_` keys are made for sharing: hand one to readers and they can read the whole world without any second secret. A key you mint is your own tool and shows what you [hid](/docs/development/api/hidden). To share a world without what you hid, use a [player link](/docs/development/api/members#player-links) (a friend reads as one Character, with no account) or an [invite](/docs/development/api/members#invite-links) with a role.
- Both the current API and the [Classic API](/docs/development/api/classic) accept prefixed and legacy keys.

## Demo keys

The legacy keys `0000000000` to `0000000009` are reserved for demo worlds. They are read-only on every route (a write is `403` [`permission_error`](/api/errors/#permission_error)) and read without a PIN. A demo key is one of these ten on a world open to read; a world's own keys are never demo keys, even when the world is open to read (keel, 2026-10-20). These answer today:

| Key | World | Try |
|:--|:--|:--|
| `0000000000` | Hyperion, the public example world | `GET /api/v2/character?fields=id,name` |
| `0000000001` | Moppetopia | `GET /api/v2/character?name__icontains=admiral` |

The rest of the range is not for public use; unassigned keys answer `401` [`invalid_credentials`](/api/errors/#invalid_credentials).

## The practice world

:::tip[No account yet? Write to the practice world]
Key `ow_w_QRRMlAFPF9vPZSqmiV6QJm2HDJH_sP28x2RccPmYP1A`, PIN `1234`.

Everyone shares this key. Every night at 03:00 UTC the world goes back to the same copy, so write freely: whatever you make is gone by morning, and until then anyone who has this page can see it. Put nothing private in it.
:::

The practice world is a copy of Moppetopia under its own ids. Read examples use the [demo key](#demo-keys) on the real Moppetopia, and write examples use this key, so an id you read in one world is not found in the other. The key is the world's owner key, so it reads and writes everything in it, and `GET /api/v2/me` with it answers the world `Practice`. It does not reach past the world: in the Council it is refused, as below.

It differs from your own world in five ways, each refused or limited by the real error:

- **No files and no members.** A file upload is refused with `403`, and the world takes no invites or seats. For those, [make your own world](https://www.onlyworlds.com/account/).
- **At most 2,000 elements.** A create past that is refused until the next reset.
- **60 requests a minute per address**, not a key's 300, so that one person's loop never uses up the shared key for everyone else. Over the limit is `429` [`too_many_requests`](/api/errors/#too_many_requests), with `Retry-After`.
- **A wrong PIN never locks the key.** It answers `401` [`invalid_credentials`](/api/errors/#invalid_credentials) with `param` `API-Pin`, as it does everywhere, but here the failures are never counted toward a lockout.
- **No part in the [Council](/docs/tools/council).** A motion, a vote, an endorsement, a delegate or a dispatch sent with this key and its PIN is refused with `403`, in the Council's own answer ("The practice world cannot act in the council"), as a demo key is. The PIN is checked first, so a wrong one answers as on any world.

## The PIN

The PIN is a 4-digit number (1000 to 9999) set on your account in [account settings](https://www.onlyworlds.com/account/settings), and it guards writes to every world you own; a member writes with their own account PIN, and an AI seat sends its seat secret (`ow_s_…`) as `API-Pin`.

- **Send the PIN only where it is checked.** The server verifies a PIN on every request that carries one, and each verification is deliberate work (a memory-hard hash). A client sends it on writes, on `/me` (to test a connection), and on every call only with a 10-digit legacy key; a prefixed key's reads go without it. The SDK (since 4.59.0) and the Python package (since 0.27.0) do this for you.
- **A world with a PIN requires it on every write.** New worlds always have one. An account without a PIN chooses it when creating its first world, and changing it in account settings changes it on every world the account owns. One way in is the exception: the holder of a [talk address](/docs/development/agents#a-talk-address) adds Messages to its one conversation with no key and no PIN, for up to seven days (since 2026-12-02).
- **Reads with a prefixed key (`ow_w_`, `ow_r_`) never need the PIN.** Only a legacy 10-digit key (other than the demo keys) must send it, on every read of a world that has a PIN, whether or not the world is open to read. A PIN that is sent is checked all the same: a wrong one is refused on a read too, so a connection test learns of it at once. A demo key never checks it, and a member's key checks it only on a write.
- Failed PIN attempts are limited (since 2026-11-21): a wrong PIN is a `401` every time until ten different wrong PINs have been tried on one key or account inside fifteen minutes; then every request carrying a PIN there answers `429` [`rate_limited`](/api/errors/#rate_limited), the right PIN included, with a `Retry-After` of up to 900 seconds. The same wrong PIN sent again never locks anything, and a request with no PIN is never counted.

Creating a world through the API with an account token: an account without a PIN sends `pin` (4 digits, 1000 to 9999) with its first world, and it becomes the account's PIN. An account that has one may send its `pin` too, to have it checked before the world is made: a wrong one answers `401` [`invalid_credentials`](/api/errors/#invalid_credentials) with `param` `pin` and nothing is made, counted toward the same lockout as a write's PIN. Left out, the world takes the account's PIN.

## Member keys

A world can have members besides its owner (see [Members and sharing](/docs/development/api/members)). A member mints their own keys for the world in their own account, and **a member's key writes with the member's own account PIN**, never the owner's. Accepting an invite or an invite link needs no PIN; a member without an account PIN cannot mint a write key: `409` [`pin_required`](/api/errors/#pin_required).

Removing a member, or a member leaving, deletes that member's keys for the world.

<a id="agent-seat-keys"></a>

## AI seat keys

An AI seat, whether a member made it or it joined through an AI link, receives once an `ow_w_` key and a seat secret (`ow_s_…`). The agent sends the secret as `API-Pin` on writes. It is never the world's PIN or any account's PIN, and reads take the key alone. A lost key is replaced with a new one, never a new seat. Joining is described on [AI agents](/docs/development/agents).

## Checking a key

`GET /api/v2/me` answers who the calling key is, for any key and without a PIN:

```bash
curl -s "https://www.onlyworlds.com/api/v2/me" -H "API-Key: {key}"
```

```json
{ "world": { "id": "0695…", "name": "Hyperion" }, "scope": "write", "kind": "owner",
  "role": "owner", "membership": null, "character": "0698…" }
```

`GET /api/v2/world` also validates a key: a `200` means it is accepted.

### Checking the PIN

Send the PIN with a read and the read checks it. `/me` and every read take the key alone (except a legacy key, which sends its PIN on every read), but a PIN that comes with the request is checked all the same, so `GET /api/v2/me` with the key and the PIN confirms both. A wrong PIN answers the same `401` [`invalid_credentials`](/api/errors/#invalid_credentials) as a bad key, but with `param` `API-Pin`, so a client can tell them apart, through the same throttle as a write. An empty `API-Pin` header counts as none. Three keys are exceptions: a member's key, whose PIN (or an AI seat's secret) is checked on a write and on `GET /api/v2/me` when one is sent (other reads ignore it); a [demo key](#demo-keys), which reads with any PIN; and, since 2026-11-21, any key that cannot write (an `ow_r_` read key, a player's key): a PIN sent with it is never read, and the answer is the one that key gets with no PIN. The `message` tells the failures apart:

| Answer | `message` | Meaning |
|:--|:--|:--|
| `401` `invalid_credentials` | `No valid API-Key.` | The key is missing or unknown |
| `401` `invalid_credentials` | `A PIN is required: send it as API-Pin.` | The key is valid; the PIN is missing (`param` `API-Pin`) |
| `401` `invalid_credentials` | `Incorrect PIN.` | The key is valid; the PIN is wrong (`param` `API-Pin`) |
| `401` [`key_revoked`](/api/errors/#key_revoked) | | The key was recognized but revoked |
| `403` [`permission_error`](/api/errors/#permission_error) | `This key is read-only and cannot write to this world.` | The key is genuine but lacks the scope, such as a read key on a write route |
| `429` [`rate_limited`](/api/errors/#rate_limited) | `Too many failed PIN attempts. Try again later.` | Too many wrong PINs: wait the `Retry-After` seconds |

Message wording may change: branch on `code`, and use the message only to tell a person what to fix.

## Keeping credentials safe

- A key and PIN in browser code are visible to anyone who opens the page. Ship only an `ow_r_` read key in a public page, or ask each visitor for their own credentials at runtime. See [CORS](/docs/development/api/cors).
- Keep keys and PINs in a `.env` file that git ignores, never in a commit or a chat.
- An MCP client stores the `API-Key` and `API-Pin` headers in its own configuration as written. Use a key you can revoke on its own. See [MCP server](/docs/development/mcp).
- An AI seat's key and secret are shown once, when the seat is made or joins; a lost one is replaced with a new key, never shown again. See [AI agents](/docs/development/agents).
- A leaked key is revoked in the account portal; mint a new one in its place.

## Account tokens

An `ow_a_` token acts on your account: it lists your worlds, creates worlds, mints and revokes world keys, and manages invites, members, seats, links and watched worlds. Mint one in the account portal under **Settings → Account tokens**, or with `POST /api/v2/account/tokens`; an app can make one from the user's email and password (the TypeScript SDK's `signInWithPassword`, which calls that route after the login API). Like a key, it is shown once. With `ai_uses`, the same route mints a token that opens only the [AI door](/docs/development/ai#the-ai-door-a-use-by-name)'s uses it names, until midnight UTC at the latest.

It is sent as a bearer token, not as `API-Key`:

```bash
curl -s "https://www.onlyworlds.com/api/v2/account/worlds" \
  -H "Authorization: Bearer ow_a_…"
```

An app signed in through the login API (`/api/v2/auth/app/v1/auth/login`) may send its `X-Session-Token` on any account route in place of the token; an unknown or expired one is a `401`, and so is one made before the account's password was last changed or reset (`invalid_credentials`, since 30 Nov 2026): the app signs in again. A page on onlyworlds.com signed in with the site's own session cookie sends the `csrftoken` cookie's value in the `X-CSRFToken` header on every write, or the write is a `403` [`csrf_required`](/api/errors/#csrf_required) and nothing is written; a token or an `X-Session-Token` needs none.

### Reading a world with an account token

The token also reads a world's elements, read only, so a tool that signed you in needs no key per world and leaves nothing on your keys page. Send it instead of an `API-Key` and name the world with `world=<id>`:

```bash
curl -s "https://www.onlyworlds.com/api/v2/character/?world=<world_id>" \
  -H "Authorization: Bearer ow_a_…"
```

- **Where**: an element list and an element read (`/api/v2/{type}/` and `/api/v2/{type}/{id}`), [search](/docs/development/api/reads#search), the metadata routes (`/api/metadata/{type}/`), `GET /api/v2/world` (which also takes a public page's address as `world`) and [the draught](/docs/development/api/draught). These are the routes the [keyless public reader](/docs/development/api/public#the-keyless-reads) uses.
- **As whom**: your own access in that world. The owner reads it whole, hidden elements included. A member reads what their own member key reads, by their role. An account with no access there reads what the public reads, and a world that is not open to the public is the same `404` a keyless request gets.
- **The members list**: [`GET /api/v2/members`](/docs/development/api/members) with `world=<id>` answers the token too, as the owner's keys for the owner and as their own member key for a member. An account with no access there gets a `404`, since the list is never public.
- **What it doesn't do**: a write, `/changes`, `/me`, files and the MCP server answer the token with the `401` they always gave a request without an `API-Key`. View as (`?as=`) stays the owner's: a member's or a stranger's token gets [`view_as_owner_only`](/api/errors/#view_as_owner_only).
- **One credential**: a request with both an `API-Key` and the token is a `400`, [`one_credential`](/api/errors/#one_credential).
- **Budget**: these reads count against the token's 300 requests a minute, not the 60 a minute of a request with no credential.

| Method | Route | Purpose |
|:--|:--|:--|
| GET, PATCH | `/api/v2/account` | Your profile |
| GET | `/api/v2/account/worlds` | The worlds you own, then the worlds shared with you, each by name |
| POST | `/api/v2/account/worlds` | Create a world: `201` with the world and a new `ow_w_` key, shown once |
| POST | `/api/v2/account/worlds/handover` | Create a world with its first elements, all or nothing ([below](#a-world-with-its-first-elements)): `201` with the world, each item's result and `door`, the world's page; no key is made |
| POST | `/api/v2/account/worlds/{world_id}/keys` | Mint a world key, shown once |
| GET | `/api/v2/account/worlds/{world_id}/keys` | List a world's keys (last four characters only) |
| GET | `/api/v2/account/worlds/{world_id}/keys/made?key=` | The key a mint sent with that `Idempotency-Key` made, without the key itself ([below](#a-lost-mint)) |
| DELETE | `/api/v2/account/worlds/{world_id}/keys/{key_id}` | Revoke a world key |
| POST | `/api/v2/account/tokens` | Mint an account token, shown once. A client that signed in through the login API (`/api/v2/auth/app/v1/auth/login`) may send its `X-Session-Token` here instead of a Bearer token, which is how an app on a phone gets a token of its own after sign-in |
| GET | `/api/v2/account/tokens` | List your account tokens (last four characters only), each with `keys_minted`: the live world keys it minted |
| DELETE | `/api/v2/account/tokens/{token_id}` | Revoke an account token, and the world keys a sign-in token minted unless they were minted with `keep` ([which keys outlive a token](/docs/development/api/signin#consent-and-revoking)) |

Minting a world key takes `scope` (`"read"` or `"write"`, default `"write"`), an optional `keep` (`true` keeps the key when the token that minted it is revoked; the answer says `kept`) and an optional `name`, a label such as `"atlas · my laptop"` that is echoed back in the key list. A `name` is trimmed, and one over 80 characters is a `422`, the same rule as the `key_name` a new world's key takes; `null` or a blank `name` mints a key with no name. An account token's name takes up to 255 characters.

```bash
curl -s -X POST "https://www.onlyworlds.com/api/v2/account/worlds/{world_id}/keys" \
  -H "Authorization: Bearer ow_a_…" -H "Content-Type: application/json" \
  -d '{ "scope": "read", "name": "players" }'
```

```json
{ "id": "…", "name": "players", "last4": "…", "scope": "READ",
  "last_used_at": null, "revoked": false, "key": "ow_r_…" }
```

`key` appears in this response only. Creating a world answers its summary with a new write key the same way:

```bash
curl -s -X POST "https://www.onlyworlds.com/api/v2/account/worlds" \
  -H "Authorization: Bearer ow_a_…" -H "Content-Type: application/json" \
  -d '{ "name": "Hyperion", "key_name": "My tool" }'
```

```json
{ "id": "…", "name": "Hyperion", "role": "owner", "public_read": false,
  "keys": [ { "name": "My tool", "last4": "…", "scope": "WRITE", "revoked": false } ],
  "key": "ow_w_…" }
```

`key_name` is optional: it names that write key as the website's key list shows it (1 to 80 characters once trimmed; a blank or longer name is a `422` and nothing is made). Without it the key has no name. Either way the route makes exactly one key.

Since 2026-11-07 the route takes an `Idempotency-Key`, as [`/bulk`](/docs/development/api/writes#idempotency) does, so a retry after a lost answer makes no second world: the same key and body answer the same world with `Idempotent-Replay: true`, but without `key`, which is shown only the once it is minted (mint another with the keys route above). The same key with another body is `409` [`idempotency_error`](/api/errors/#idempotency_error). Past the day a key replays, `GET /api/v2/account/worlds/made?key=<the key>` still finds the world (below).

Since 2026-10-31 this route, and the hand-over's `world` below, also take the World's extension keys (`x_…`, `atlas_…`, `shadow_…`), as [`PATCH /world`](/docs/development/api/writes#the-world) does: each kept as given, a `null` one not stored, all of them within the same 64 KB, written with the world and echoed on the answer. Any other key the route does not name is ignored.

### A lost mint

A mint is never replayed, because a stored answer would keep the key: a second mint makes a second key. Since 2026-11-08 the mint takes an `Idempotency-Key` header and remembers it on the key's row instead. If the answer is lost, `GET /api/v2/account/worlds/{world_id}/keys/made?key=<the Idempotency-Key>` answers that key's row, the same fields as the mint's answer without `key`, or `404` when the mint made none. A revoked key still answers, with `revoked: true`. The owner finds the keys they minted, and a member only the keys bound to their seat. So a tool that keeps a key on the device:

- keeps the `Idempotency-Key` on the device before it sends the mint;
- treats a `4xx` as no key made;
- after a network error or a timeout, asks the lookup, revokes the id it names, and mints again with a new `Idempotency-Key` (the same one sent again makes a second key, and the lookup keeps naming the first, so the second can never be found);
- believes a `404` only a couple of minutes after the send: a request it gave up waiting for may still be running on the server.

In the [TypeScript SDK](/docs/development/typescript), `mintWorldKey` takes `idempotencyKey` and `madeWorldKey(worldId, idempotencyKey)` is the lookup, null when none was made (from 4.134.0). In [Unity](/docs/development/unity) the same pair is `MintWorldKeyAsync` with an `idempotencyKey` and `MadeWorldKeyAsync` (from v0.36.0).

### A world with its first elements

`POST /api/v2/account/worlds/handover` (since 2026-10-29) makes a world on the account and writes its first elements in one transaction: a page that let a visitor make things before signing in hands them over this way. `world` takes what `POST /api/v2/account/worlds` takes, without `key_name`: no key is made, and the world's page makes keys. `items` is [`/bulk`](/docs/development/api/writes)'s array, 1 to 1000 entries of `{type, element}`. Each element keeps the `id` it carries, and the items link to each other by those ids.

```bash
curl -s -X POST "https://www.onlyworlds.com/api/v2/account/worlds/handover" \
  -H "Authorization: Bearer ow_a_…" -H "Content-Type: application/json" \
  -d '{ "world": { "name": "Hyperion" },
        "items": [ { "type": "character", "element": { "id": "019a…", "name": "Mira" } } ] }'
```

- **All or nothing.** It writes the account PIN first when the account has none (a PIN-less account sends `world.pin`, 1000 to 9999; an account with a PIN may send it to have it checked first, as on the create above, or leave it out), then the World, then every item. On success: `201` with `world`, `items` (each item's result) and `door`, the world's page.
- **A refusal writes nothing**, not the world and not the PIN: [`handover_refused`](/api/errors/#handover_refused), `409` when an id is held in another world or by a membership (that slot says `id_conflict`: give it a new id and send again), else `422`, with each item's result in `items`.
- **An `Idempotency-Key` makes a retry safe** (since 2026-11-07): the same key and body answer the same `201` again with `Idempotent-Replay: true`, the one world; the same key with another body is `409` [`idempotency_error`](/api/errors/#idempotency_error). The key belongs to the account, since there is no world before the call. Without one, a retry after a lost answer meets `409` on every id, and the first world stands under the account's worlds.
- **A lost answer is found by its key** (since 2026-11-07): `GET /api/v2/account/worlds/made?key=<Idempotency-Key>` answers the world this account's hand-over or create made under that key, for as long as the world exists; the world keeps only a hash of the key. One identical `404` [`not_found`](/api/errors/#not_found) for a key never sent, another account's, a deleted world's, no key or one too long, and a create's key never names a hand-over's world. Ask it first: a world that holds one of the sent ids may be an older world of yours (a file of your own online world put online again meets `id_conflict` on every id). A tool that kept no key asks [which world holds an element](/docs/development/api/signin#the-account) by any of the ids it sent.
- The website's own page sends it with its session cookie; a client sends an account token or `X-Session-Token`.

The routes for invites, members, seats, links and watched worlds are on [Members and sharing](/docs/development/api/members#managing-members). A missing or invalid account credential answers `401`.