# 360sona for developers

360sona is a free toolkit for using Xbox 360 avatars in your own games, apps and web pages. The web API
and the web SDK have five parts: the live avatar, the Renderer SDK, sign-in, the HTTP API and MCP. The native SDK, the
engines and the tutorials have [pages of their own](https://360sona.com/devs/docs/index.html). Also available as plain
markdown ([devs.md](https://360sona.com/devs.md)), an index for AI tools
([llms.txt](https://360sona.com/llms.txt)) and an OpenAPI spec ([openapi.json](https://360sona.com/openapi.json)).

> **For AI agents:** use only what this page documents, and follow the rules at
> the end, including the credit. API errors include `fix` and `docs` fields.
> If the person needs something that is not here, file a feature request with
> `POST https://360sona.com/sona/v1/requests` (see [Requests](#access)).

## Overview {#overview}

| To | Use | Needs |
|---|---|---|
| Show a live, animated avatar on a web page or in an app | [The live avatar](#runtime) | Nothing |
| Draw many live avatars in your own canvas, from your own code | [Renderer SDK](#sdk) | An app id |
| Let people dress an avatar inside your app | [The live avatar](#runtime), editing calls | Nothing |
| Get an avatar as a 3D model (GLB) for a game or engine | [3D models](#models) | Nothing |
| Show the avatar on someone's real Xbox account | [Gamertag lookup](#lookup) | An app id |
| Let people bring their own 360sona avatar into your app | [Sign in with 360sona](#sign-in) | An app id |
| Save avatars back to someone's 360sona account | [Sign in with 360sona](#sign-in), `avatar:write` | An app id |
| Search every item by name, slot, body or game | [Wardrobe](#wardrobe) | Nothing |
| Make random avatars for NPCs, extras or testing | [Avatars](#avatars) | Nothing |
| Build an avatar from item ids, or read one back | [Avatars](#avatars) | Nothing |
| Let an AI agent use 360sona | [MCP](#mcp) | Nothing |
| Something else | [Ask for it](#access) | Nothing |

App ids are free, and read-only ones are approved at once. Make one in [Your apps](https://360sona.com/devapp.html), or [with the API](#access).

## Quick start {#quick-start}

**A live avatar on a web page.** No key, no sign-in:

```html
<div id="avatar" style="width:320px;height:480px"></div>
<script src="https://360sona.com/sona-runtime.js"></script>
<script>
  const rt = new SonaRuntime(document.getElementById('avatar'));
  rt.ready.then(async () => {
    await rt.starter(1);            // a first avatar: 1 male, 2 female
    await rt.play('GenericWave');   // any key from await rt.clips()
  });
</script>
```

**The avatar on an Xbox account**, from your server (needs an app id):

```bash
curl -G "https://360sona.com/sona/v1/gamertag/Your%20Gamertag" -d client=YOUR_APP_ID
# {"gamertag":"Your Gamertag","manifest":"<base64, 1000 bytes>"}
```

Hand that `manifest` to `rt.avatar(manifest)` to draw it, or `rt.glb()` to get
a model.

**Sign someone in** and read their saved avatars (needs an app id): see
[Sign in with 360sona](#sign-in) for the full flow. It is standard OAuth 2.0
authorization code with PKCE.

## The live avatar {#runtime}

`https://360sona.com/runtime.html` is a page with only the 360sona renderer on it, made to sit in an iframe. Its background is transparent, so your page shows through around
the figure. It stops drawing when it is scrolled out of view or the tab is
hidden. It needs WebGL.

The simplest way to use it is `https://360sona.com/sona-runtime.js`, a plain script (no
modules, no build step) that adds the frame and returns promises:

```js
const rt = new SonaRuntime(element);   // element: where the avatar goes
await rt.ready;
await rt.avatar(manifestBase64);       // draw this avatar
rt.on('shown', () => { /* the figure is on screen: hide your placeholder */ });
```

| Call | Does |
|---|---|
| `rt.avatar(manifest)` | Draw an avatar (base64 manifest) |
| `rt.starter(gender)` | Draw a first avatar: `1` male, `2` female |
| `rt.clips()` | The animations it can play: `[{ key, name, prop }]` |
| `rt.play(key)` | Play one; `'idle'` goes back to idling, `'still'` stops |
| `rt.shot(name)` | Frame the camera: `'full'`, `'upper'`, `'bust'`, `'face'` |
| `rt.drag(true)` | Let the person spin the figure |
| `rt.snapshot()` | A PNG of the frame, as a `data:` URL |
| `rt.glb()` | `{ glb, manifest }`: the avatar as a 3D model, see [3D models](#models) |
| `rt.manifest()` | The avatar as it is now, to save |
| `rt.wardrobe({ section, query, source, offset, limit })` | Items the person can wear |
| `rt.worn()` | What is worn now |
| `rt.wear(itemId)` / `rt.remove(itemIdOrSlot)` | Put on or take off an item |
| `rt.colours()` / `rt.colour(slot, value)` | Colour slots and their swatches; set a swatch index or `'#rrggbb'` |
| `rt.shape(weight, height)` | Body shape, each `-1` to `1` |
| `rt.gender(g)` | `1` or `2` |
| `rt.thumb(itemId)` | An item's picture, as a `Blob` |
| `rt.faces()` | The face shapes by index: `{ mouth, eye, brow }` name lists |
| `rt.face({ mouth, eye, brow })` | Set the face; a part left out follows the animation, `null` gives it all back. Mouths 7-13 are speech shapes, for lip sync |
| `rt.status()` | Whether it is drawing, and at what frame rate |
| `rt.destroy()` | Remove the frame |

Every call returns a promise that rejects with a readable message. Editing
calls answer with the figure as it now is: `{ gender, weight, height, colours, worn }`.

**Without the helper** (a webview, another language): post messages to the
frame and listen for replies. Every message carries `sona: 1`.

```js
frame.contentWindow.postMessage({ sona: 1, rid: 1, type: 'avatar', manifest }, 'https://360sona.com');
// The frame answers: { sona: 1, rid: 1, type: 'reply', ok: true, ... }
//                 or { sona: 1, rid: 1, type: 'reply', ok: false, error: '...' }
// It also sends { type: 'ready' } once, { type: 'shown' } when the figure is up,
// and { type: 'error', error } if it cannot start.
```

The `type` names are the call names above (`avatar`, `play`, `shot`, `glb`, ...),
with the arguments as fields: `{ type: 'play', clip }`, `{ type: 'shot', shot }`,
`{ type: 'wear', id }`, `{ type: 'colour', slot, value }`,
`{ type: 'shape', weight, height }`, `{ type: 'face', face: { mouth } }`.

## Renderer SDK {#sdk}

The **360sona Renderer SDK** is a JavaScript module you import into your own
page. It draws live, animated avatars into your own canvas: many at once, in
one WebGL2 context, with your camera and your loop. Use it when one iframe per
avatar is not enough: a crowd, a lobby, a game scene.

**It is free.** The only condition is a small "Powered by 360sona" badge, which
the SDK draws. Set `credit: false` to put the line in your credits or about
page instead.

### Getting it {#sdk-download}

1. Sign in to [Your apps](https://360sona.com/devapp.html) with your 360sona account and make an app. An app that
   only reads works at once.
2. Accept the SDK Licence there.
3. Download the setup. It is made for your app: it installs the tools and SDK Studio, downloads the SDK
   for what you are building, and checks that it draws. One setup runs on up to three computers.
4. For the web SDK, add the addresses your pages run on under **Your sites**: `https://your-site.com`, and
   `http://localhost` while you develop (any port).

Without the setup, the same page downloads each SDK on its own, or the API does it with the app's key:

<!-- snippet: run by test/devstest.mjs (the same two calls with a real key, against a local accounts server) -->
```bash
curl -X POST https://360sona.com/sona/v1/apps/YOUR_APP_ID/sdk-licence -H "Authorization: Bearer sak_..." \
  -H "Content-Type: application/json" -d '{ "agree": "I have read and understand the SDK Licence" }'
curl -OJ https://360sona.com/sona/v1/apps/YOUR_APP_ID/sdk -H "Authorization: Bearer sak_..."
```

The zip holds `sona-renderer.js` (the SDK), `sona-renderer.d.ts` (its types),
`theme.css`, `README.md`, `CHANGELOG.md`, `LICENSE.txt`, the API reference in
`docs/` and working pages in `examples/`. The `X-Sona-SDK-SHA256` header is the
SHA-256 of the zip.

The SDK talks to `https://360sona.com` (the origin check, the asset bridge frame, the
CSP lines in its README) unless `SonaRenderer.create({ canvas, host })` names
another 360sona service, such as one of your own for tests.

The native SDK (C, C++, C#, Rust, Python, the engines) comes the same way with
`?platform=` (`linux-x64`, `windows-x64`, `macos`, `ios`, `android`, ...;
`&catalogue=1` adds the offline catalogue). The command-line tools (`sona`, `sona-mcp`, SDK Studio) are one
installer per system: `GET /sona/v1/apps/{id}/tools?platform=linux-x64` with the
same key. An agent with no person present can do all of it
([Unattended agents](https://360sona.com/devs/docs/guides/unattended.html)).

<!-- snippet: not run: it needs an app key and a built download on the server; test/accept/unattended.mjs makes both calls -->
```bash
curl -OJ "https://360sona.com/sona/v1/apps/YOUR_APP_ID/sdk?platform=linux-x64&catalogue=1" -H "Authorization: Bearer sak_..."
curl -OJ "https://360sona.com/sona/v1/apps/YOUR_APP_ID/tools?platform=linux-x64" -H "Authorization: Bearer sak_..."
```

### Using it {#sdk-start}

```js
import { SonaRenderer } from './sona-renderer.js';

const canvas = document.querySelector('canvas');
const sona = await SonaRenderer.create({ canvas });
const a = sona.add(manifestBase64, { position: [0, 0, 0], turn: 0 });
const b = sona.add(otherManifest,  { position: [1.2, 0, 0], turn: -20, clip: 'GenericWave' });
sona.camera.preset('crowd');
await a.ready;
a.play('GenericClap');
```

- `add()` returns at once. The avatar builds over the next frames and appears
  when it is ready; `ready` resolves then.
- Each handle has `play(clip)`, `stop()`, `move({ position, turn, scale }, { over })`,
  `setVisible()` and `remove()`.
- `sona.camera` has the console's framings (`full`, `upper`, `bust`, `face`) on
  one avatar, `crowd` to fit them all, `orbit()` and `lookAt()`.
- `loop: 'manual'` and `await sona.frame(t)` draw from your own loop. Avatars build only inside `frame()`, so with
  the manual loop `await a.ready` alone waits for ever: call `frame()` until they are ready, or
  `await sona.settle()`, which draws frames while it waits and gives up with `not_ready` after `seconds`
  (default 120).
- `snapshot()` gives a picture with the credit in its file details; `glb(manifest)` gives a model.
- `scene.stats()` and `scene.benchmark()` measure it on the device it runs on.

Serve your page over `https` (or `http://localhost` while you develop). A
`file://` page has no origin, so it cannot load avatars.

### How the items get to your page {#sdk-bridge}

The avatar items are never in the package. The SDK puts a hidden 360sona frame
on your page (`https://360sona.com/sona/v1/sdk/bridge/{app}`). The frame checks your
page's origin against your app's origins, then streams each item from 360sona
and hands it to the SDK. Only your registered origins can frame it. If your page
sets a Content Security Policy, allow `frame-src https://360sona.com`,
`connect-src https://360sona.com` and `worker-src blob:`.

### SDK errors {#sdk-errors}

`create()` rejects with a `SonaError`: `error.code` says what, and
`error.fix` says what to do.

| `code` | Means | Fix |
|---|---|---|
| `unsupported` | No WebGL2 in this browser | Show something else |
| `origin` | Your page's origin is not registered for the app | Add it to your app's origins, then reload |
| `licence` | The app has not accepted the SDK Licence | Accept it on your app's page |
| `app` | No such app, or it was turned off | Check the app id |
| `gate` | 360sona could not be reached | Try again later |
| `limit` | Too many avatars, or this page asked for too many items | Use fewer, or reload |

`add()` never throws for a bad manifest: its `ready` rejects with `manifest`.
`GET /sona/v1/sdk/check?app={app}&origin={origin}` answers the same question
the frame asks, for your own checks.

### SDK limits {#sdk-limits}

| What | Limit |
|---|---|
| Avatars in one scene | 256 by default, 1,024 at most |
| Origins per app | 10 |
| Downloads | 10 an hour per app |
| Items per page load | 3,000 different items |

## Avatar manifests {#manifest}

Every avatar is one **manifest**: the 1000-byte avatar description that the Xbox 360 stores, sent as base64. It names the body, face, colours and every worn item. Everything here takes and returns manifests, including the lookup, the saved slots and the runtime. A manifest is small enough to keep in your own database or pass between players, and the same manifest always draws the same avatar.

The bytes are big-endian. You never need to read them yourself: the runtime
draws, edits and exports them.

## 3D models {#models}

`rt.glb()` gives you the avatar as a binary glTF (`.glb`) you can load in
Unity, Unreal, Godot, Blender or three.js:

- A skinned mesh with Unity humanoid bone names, so humanoid retargeting works.
- The animations, as glTF animation clips you can play by name.
- Textures embedded, with the editor's lighting baked in.
- Credit in the file's `asset` block. Keep it there.

Save the model once per manifest and reuse it: the same manifest always gives
the same model. For a one-off file, the editor's own Export dialog on
https://360sona.com has presets for Unity and VRChat, Blender, Garry's Mod and Roblox.

Exporting by URL, without a browser, is [planned](#roadmap).

## Gamertag lookup {#lookup}

```text
GET https://360sona.com/sona/v1/gamertag/{gamertag}?client={app id}
```

Returns the avatar on that Xbox account: `{ "gamertag": "...", "manifest": "<base64>" }`.
Add `&format=bin` for the raw 1000 bytes (`application/octet-stream`).

- Needs an app id ([ask for one](#access)). No sign-in, and any origin may call it.
- `403`: the account keeps its avatar private. `404`: no such gamertag, or it has no avatar. `400`: the text cannot
  be a gamertag. With `&missing=empty` these three answer `200` with
  `{ "gamertag": null, "manifest": null, "error": "..." }`, so a page that shows the message logs no failed request.
  `429` (too many lookups) and `502` or `503` (Xbox not answering) stay errors: try again later.
- Answers are cached for ten minutes. Cache them on your side too.
- 60 lookups an hour per address. See [Limits](#limits).

## Wardrobe {#wardrobe}

Every item, searchable. No key needed; any origin may call it.

```text
GET https://360sona.com/sona/v1/items?q=hoodie&slot=shirt&gender=female&plain=1&limit=20
```

```json
{ "total": 7, "offset": 0, "limit": 20, "items": [
  { "id": "00000008-010f-0002-c1c8-f109a19cb2e0", "name": "Green full-zip hoodie", "game": null,
    "slots": ["shirt"], "gender": "female", "source": "builtin", "plain": true,
    "category": null, "description": null } ] }
```

| Parameter | Means |
|---|---|
| `q` | Words to find in the name, game or category |
| `slot` | `hair`, `shirt`, `trousers`, `shoes`, `headwear`, `glasses`, `gloves`, `wristwear`, `earrings`, `ring`, `carryable`, `costume`, and the face slots (`eyes`, `eyebrows`, `mouth`, `nose`, `chin`, `ears`, `facialHair`, `facialFeature`, `eyeShadow`) |
| `gender` | `male` or `female`: items for that body, plus items for both |
| `source` | `builtin` (Microsoft's stock items), `award` (unlocked in games) or `marketplace` |
| `plain` | `1` for stock items only: no game or brand on them |
| `game` | Part of a game's name |
| `offset`, `limit` | Paging; 50 at most per page |

- `GET /sona/v1/items/{id}` is one item.
- `GET /sona/v1/games` lists every game that has items, with how many.
- Items come as ids, names and labels. Pictures of items are not part of the API.

## Avatars {#avatars}

Make, read and check avatars on the server. No key needed. Every route answers
with a [manifest](#manifest), which [the live avatar](#runtime) draws.

**A random avatar from a seed.** The same seed always gives the same avatar.

```text
GET https://360sona.com/sona/v1/avatar/random?seed=guard-7&gender=any&style=plain
```

- `style=plain`: stock clothes only, safe for staff, extras and NPCs in your own product.
- `style=costume`: a full-body costume. Those can be licensed brands, and the answer says so with `licensed: true`.
- The answer has `manifest`, `avatar` (the items it wears, its colours and shape) and `licensed`.

**Build an avatar from items:**

```bash
curl -X POST https://360sona.com/sona/v1/avatar/build -H "Content-Type: application/json" -d '{
  "gender": "female",
  "items": [
    "00000008-010f-0002-c1c8-f109a19cb2e0",
    "00000004-01ae-0003-c1c8-f109a19cb2e0"
  ],
  "colours": { "skin": "#c68a62", "hair": "#2b1d16" },
  "height": 0.3, "weight": -0.2 }'
```

- It starts from a blank figure, or from `manifest` if you send one.
- `skipped` lists anything it could not do, with why: an unknown id, an item made for the other body, a bad colour.
- Colour slots: `skin`, `hair`, `mouth`, `eyes`, `eyebrows`, `eyeShadow`, `facialHair`, `facialFeature`, `facialFeature2`.

**Read an avatar back:** `POST /sona/v1/avatar/describe` with `{ "manifest": "..." }`
gives its body, height, weight, colours and every item with its name.

**Check it for Xbox:** `POST /sona/v1/avatar/check` with `{ "manifest": "..." }`
says whether an Xbox 360 account could save it (`ok`), and if not, `why` and
which `items`. `mustOwn` lists the marketplace items the account would need.

## MCP {#mcp}

360sona is an MCP server, so AI agents and coding tools can use it directly.

```text
https://360sona.com/sona/mcp
```

Claude Code:

<!-- snippet: not run: it registers the server in the reader's own Claude Code setup -->
```bash
claude mcp add --transport http 360sona https://360sona.com/sona/mcp
```

Other clients:

```json
{ "mcpServers": { "360sona": { "type": "http", "url": "https://360sona.com/sona/mcp" } } }
```

| Tool | Does |
|---|---|
| `search_items` | Search the wardrobe |
| `get_item` | One item by id |
| `list_games` | Every game with items |
| `random_avatar` | A complete avatar from a seed, plain or in costume |
| `build_avatar` | An avatar wearing the items you list |
| `describe_avatar` | What an avatar wears, its colours and shape |
| `check_avatar_for_xbox` | Whether an Xbox account could save it |
| `lookup_gamertag` | The avatar on a real Xbox account |

No key needed. It shares the limits of the routes above.

## Sign in with 360sona {#sign-in}

Standard OAuth 2.0 authorization code with PKCE. The person signs in on
360sona, sees what your app is asking for, and allows it. You never see their
password.

**What you register** (with your app id): a name, the scopes you need, and one
return address:

- **Desktop and mobile apps:** a custom protocol, like `virtualcinema://linked`.
  Open the sign-in page in the person's own browser; the browser hands the
  return address back to your app. Any engine can do this.
- **Desktop apps with a local listener:** `http://127.0.0.1/callback` (or `http://[::1]/...`).
  Register it without a port. Sign-in accepts any port on that path, so your app can
  listen on a free port each time and send `http://127.0.0.1:{port}/callback`.
- **Web apps:** an `https://` address on your own site. Swap the code for
  tokens on your **server**: the token routes do not answer browsers on other
  sites, and tokens must never reach a browser.

**1. Send the person to the sign-in page:**

```text
https://360sona.com/link.html?client={app id}&redirect={your return address}&method=S256&challenge={challenge}&state={state}&scope={scopes}
```

- `verifier`: 43 to 128 random characters (`A-Z a-z 0-9 . _ ~ -`). Keep it.
- `challenge`: base64url of the SHA-256 of `verifier`, no padding.
- `state`: 8 to 128 random characters. Check it when the person comes back.
- `scope`: optional, space separated. Leave it out to ask for everything your
  app was registered with.

**2. The person comes back** to `{return address}?code={code}&state={state}`,
or `?error=access_denied&state={state}` if they said no.

**3. Swap the code** within its 60 seconds limit:

```bash
curl -X POST https://360sona.com/sona/v1/token -H "Content-Type: application/json" -d '{
  "grant_type": "authorization_code", "client": "YOUR_APP_ID",
  "redirect": "virtualcinema://linked", "code": "CODE", "verifier": "VERIFIER" }'
```

```json
{ "access_token": "sat_...", "token_type": "Bearer", "expires_in": 3600,
  "refresh_token": "srt_...", "scope": "profile:read avatar:read",
  "username": "Your Gamertag" }
```

**4. Call the API** with `Authorization: Bearer {access_token}`.

A complete client for Electron (PKCE, the sign-in window, token storage and
refresh) is in the Dash360 integration; ask for it with your app id.

### Tokens {#tokens}

- Access tokens last an hour.
- Refresh before then: `POST /sona/v1/token` with
  `{ "grant_type": "refresh_token", "client": "...", "refresh_token": "..." }`.
  You get a new refresh token every time. Store it and drop the old one. If a refresh token is used twice, it is treated as copied and that sign-in ends.
- A sign-in unused for the limit of 180 days ends.
- `POST /sona/v1/revoke` with the bearer token signs out. People can also end
  any app's access from their account on 360sona.
- Keep tokens on a server or in your app's main process, never in a web page.

### Scopes {#scopes}

| Scope | Lets your app |
|---|---|
| `profile:read` | See their gamertag, profile and gamer picture |
| `profile:write` | Change their motto, name, location, bio, zone and gamer picture |
| `avatar:read` | See their saved avatars |
| `avatar:write` | Change and save their avatars |
| `xbox` | See and change the avatar on the Xbox account linked to their 360sona account. Given to trusted apps only. |

Ask for the fewest you need. People see each one, in those words, before they allow it.

## API {#api}

Base: `https://360sona.com/sona/v1`. JSON in, JSON out. `GET https://360sona.com/sona/v1` lists every route.

| Route | Needs | Does |
|---|---|---|
| `GET /gamertag/{gamertag}?client={app}` | app id | The avatar on an Xbox account |
| `POST /token` | none | Swap a code or a refresh token for tokens |
| `POST /revoke` | bearer | End this sign-in |
| `GET /me` | `profile:read` | Gamertag, profile, gamer picture |
| `PUT /profile` | `profile:write` | Change the profile |
| `GET /slots` | `avatar:read` | Every saved avatar |
| `PUT /slots/{n}` | `avatar:write` | Save an avatar into slot `n` |
| `GET /xbox` | `xbox` | Whether an Xbox account is linked |
| `GET /xbox/avatar` | `xbox` | The avatar on that Xbox account |
| `POST /xbox/check` | `xbox` | Whether Xbox would take an avatar |
| `PUT /xbox/avatar` | `xbox` | Save an avatar to Xbox |
| `GET /items` | none | [Search the wardrobe](#wardrobe) |
| `GET /items/{id}` | none | One item |
| `GET /games` | none | Every game with items |
| `GET /avatar/random` | none | [A random avatar](#avatars) |
| `POST /avatar/build` | none | An avatar from items |
| `POST /avatar/describe` | none | An avatar read back |
| `POST /avatar/check` | none | Whether Xbox would take it |
| `POST /requests` | none | [Ask for an app id or a feature](#access) |

The MCP server is at `https://360sona.com/sona/mcp` ([MCP](#mcp)).

### Profile {#profile}

`GET /me`:

```json
{ "username": "Your Gamertag",
  "profile": { "pic": "20000", "zone": "pro", "motto": "...", "name": "...", "location": "...",
               "bio": "...", "score": 10000, "rep": 5 },
  "pics": [{ "id": "...", "made": 1761000000000 }],
  "limits": { "motto": 40, "name": 24, "location": 40, "bio": 300 },
  "zones": ["", "recreation", "pro", "family", "underground"],
  "dashboardPics": ["20000", "..."] }
```

- `username` is the gamertag.
- `pic` is a Dashboard gamer picture id, or one the person made, served at
  `https://360sona.com/sona/gp/{id}`.

`PUT /profile`: send only what changed, any of `motto`, `name`, `location`,
`bio`, `zone`, `pic`. If one field is bad, the whole request fails and the error names that field in `field`.

### Saved avatars {#slots}

`GET /slots` returns `[{ "idx": 0, "name": "...", "at": 1761000000000, "manifest": "<base64>" }]`,
one per saved avatar. The newest `at` is usually the one they use.

`PUT /slots/{n}` with `{ "manifest": "<base64>", "name": "..." }` saves into slot
`n` (0 to 19). The manifest must be exactly 1000 bytes.

### Xbox {#xbox}

For apps with the `xbox` scope. People link their Xbox account on 360sona, so your app never shows Microsoft's sign-in.

- `GET /xbox/avatar` answers `{ avatar, worn, wearsAward }`.
- `POST /xbox/check` with `{ manifest }` says what Xbox would do, without saving.
- `PUT /xbox/avatar` with `{ manifest }` saves.
  - Get the manifest from `rt.xboxManifest()`, which applies the fixes Xbox needs.
  - The answer says `stored: true` (Xbox kept it) or `restored: true` (Xbox did
    not, and the previous avatar was put back), with a `historyId` to undo.
- Six saves an hour per account.

## Errors {#errors}

Every error is JSON:

```json
{ "error": "That sign-in has ended. Sign in again.",
  "fix": "Swap the refresh_token at POST /sona/v1/token ...",
  "docs": "https://360sona.com/devs/docs/web-api.html#tokens" }
```

- `error` is written for people. You can show it as it is.
- `fix` says what your code should do. `docs` links the section.
- `field` names the bad field, when there is one.

| Status | Means |
|---|---|
| `400` | Something in the request is wrong: see `field` and `fix` |
| `401` | No token, or the sign-in has ended |
| `403` | The person did not allow that scope, or an avatar is private |
| `404` | No such thing, or an app id that is not registered for this |
| `429` | Too many requests: wait for `Retry-After`, or a minute |
| `5xx` | Our side, or Xbox's. Try again later |

## Limits {#limits}

| What | Limit |
|---|---|
| API calls per sign-in | 120 a minute |
| Token swaps per address | 30 a minute |
| Gamertag lookups | 60 an hour per address, and a shared hourly budget per app |
| Xbox saves | 6 an hour per account |
| Wardrobe, avatar tools and MCP | 600 an hour per address |
| Requests to us | 5 an hour per address |

Cache what you can. A manifest does not change unless the person changes it.

## Requests {#access}

Ask for an app id or a feature, or report a bug, with the form or the API.

**App ids are approved at once** when the app's name is its own (not close to 360sona,
Xbox, Microsoft or another app), its return address is its own, and you have read the
[Developer Terms](https://360sona.com/devterms.html) and say so (below). The answer then includes the
app id and its key. A name too close to someone else's is read by a person first, and the
answer says why.

**Every scope is yours at once.** Reading (`profile:read`, `avatar:read`, `awards`, gamertag lookup)
and changing what players have (`profile:write`, `avatar:write`, `xbox`) are granted when your app is
made, and a scope you add later is switched on the moment you ask for it, on your app's Sign-in tab in
the [developer portal](https://360sona.com/devapp.html) or with `POST /sona/v1/apps/{id}/ask` and your key:

```bash
curl -X POST https://360sona.com/sona/v1/apps/my-game/ask -H "Authorization: Bearer $SONA_APP_KEY" \
  -H "Content-Type: application/json" -d '{ "scopes": ["avatar:write"], "why": "Saves the outfit a player picks" }'
```

**A new app grows into its limits.** For its first week an app signs in up to 100 players and does not
get the Xbox link; for its first month up to 1,000, with fewer writes an hour. After 30 days the limits
lift. Players see exactly what your app may do on the sign-in screen, can remove it at any time from
their account, and can report it there.

**Reports, suspension and bans.** When at least five different players report an app within a week,
and they are at least 2% of its players, the app is switched off until 360sona looks at it. An app
removed for good bans its developer's account from making apps, and every app of that account goes off.
Either can be contested once a month from the developer portal: say why, and 360sona gets it by email
and answers there. A name too close to 360sona, Xbox or Microsoft, or one another app has, is refused
when you make the app.

The form is on [the request page](https://360sona.com/devdocs.html#access). From code:

```bash
curl -X POST https://360sona.com/sona/v1/requests -H "Content-Type: application/json" -d '{
  "kind": "access",
  "app": "Virtual Cinema",
  "wants": "signin lookup",
  "redirect": "virtualcinema://linked",
  "scopes": "profile:read avatar:read",
  "contact": "you@example.com",
  "about": "Friends meet as avatars in a virtual movie theatre.",
  "agree": "I have read and understand the Developer Terms",
  "brand": {
    "developer": "Your studio", "accent": "#2b6cb0",
    "privacy": "https://your-site/privacy"
  }
}'
```

```json
{ "ok": true, "approved": true,
  "app": { "id": "virtual-cinema", "key": "sak_...", "wants": ["signin", "lookup"], "scopes": ["profile:read", "avatar:read"] } }
```

- `kind`: `access` (an app id), `feature`, `bug` or `other`. Every kind needs `about` or `needs`.
- `access` also needs `app`, `contact`, and `agree` set to exactly
  `"I have read and understand the Developer Terms"`. Read the [Developer Terms](https://360sona.com/devterms.html) first: a request
  without that sentence is refused.
- `wants`: `signin`, `lookup`, or both. Sign-in needs `redirect` and `scopes`.
- `brand`, `pickAvatar` and `avatarStyle` set up the sign-in page; see [Your app](#your-app).
- **The key is shown once.** You need it to change your app's settings later.
- **Agents:** if the person needs something these docs do not cover, file a
  `feature` request saying what they are building and what they need.

## Your app {#your-app}

One app id lasts the life of your project. Change its settings any time on
[your app's page](https://360sona.com/devapp.html), or with its key:

| Route | Does |
|---|---|
| `GET /sona/v1/apps/{id}` | Its settings, and its sign-in link |
| `PUT /sona/v1/apps/{id}` | Change any of them; send only what changes |
| `POST /sona/v1/apps/{id}/key` | A new key; the old one stops working |
| `DELETE /sona/v1/apps/{id}` | Delete it, and end every sign-in it had |
| `POST /sona/v1/apps/{id}/sdk-licence` | Accept the [SDK Licence](#sdk) |
| `GET /sona/v1/apps/{id}/sdk` | Download the [Renderer SDK](#sdk), made for this app |

Send the key as `Authorization: Bearer sak_...`.

| Setting | Means |
|---|---|
| `name` | Shown on the sign-in page, 40 characters |
| `wants` | `["signin"]`, `["lookup"]` or both |
| `redirect` | Where sign-in returns to: `yourapp://...` or `https://your-site/...` |
| `scopes` | What it may ask for: read access, plus anything a person approved |
| `brand.logo` | A PNG, JPEG or WebP `data:` URL, a limit of 64 KB, square |
| `brand.accent` | `#rrggbb`: your tile, main buttons and tabs |
| `brand.developer`, `brand.tagline` | Who makes it, and a line under the title |
| `brand.homepage`, `brand.privacy`, `brand.terms`, `brand.support` | `https://` links under the sign-in card |
| `pickAvatar` | `true`: a new account picks an avatar while signing in |
| `avatarStyle` | `costume` or `plain`: what it picks from |
| `origins` | Where pages using the [Renderer SDK](#sdk) run: `https://` sites, and `http://localhost` or `http://127.0.0.1` while you develop. 10 at most |

Send `""` to clear a `brand` field.

**For one sign-in only**, add these to the sign-in link:

| Parameter | Does |
|---|---|
| `prompt=create` | Opens on "Create an account" |
| `login_hint=Gamertag` | Fills in the gamertag |
| `pick_avatar=0` or `1` | Skips or shows the avatar step |
| `avatar_style=plain` or `costume` | What a new account picks from |

The sign-in page always says your app is made by you, not by 360sona, and
links your privacy policy and terms when you give them.

## Rules {#rules}

The full rules are the [Developer Terms](https://360sona.com/devterms.html). The short version:

- **Credit 360sona.** Show "Powered by 360sona" linking to https://360sona.com,
  and keep the credit inside exported files.
- **Say your app is made by you**, not by 360sona or Microsoft, and never claim to be endorsed by either.
- **The avatar items are Microsoft's and its partners'.** Do not sell them,
  and keep licensed brands off anything you sell or promote: dress your own
  characters in plain clothes (`plain=1`, `style=plain`).
- **People's data is theirs.** Use it only for what your sign-in page said,
  have a privacy policy, and delete it when they ask or remove your app.
- **Never ask for a 360sona password**, frame the sign-in page, or put
  tokens or keys in web pages.
- **No bulk collecting.** Do not scrape the catalogue or the asset server
  (`/g/`), and do not gather avatars or gamertags in bulk.
- **We can turn any app off**, at any time.

360sona is not affiliated with or endorsed by Microsoft.

## Planned {#roadmap}

Roughly in this order. If you need one sooner, file a `feature` request.

- **Avatar pictures by URL:** a PNG, GIF or video of any manifest, any pose, any
  size, from a plain `<img>` tag. Gamercards for any gamertag.
- **3D models by URL:** GLB, VRM and FBX of any manifest, with no browser.
- **Packages:** npm first.
