# HTTP API v1 overview

The external authoring API uses the `/v1` prefix. Select a resource in the sidebar
to see each operation's request and response schemas, code examples, and request
form. The machine-readable OpenAPI 3.1.1 document is available at `/docs/spec.json`.

Requests submitted from an operation page run against the current Studio
environment with your Studio session cookie or the API key you enter.

## Authentication and integration keys

- **Studio session (`studioSession`).** Studio uses the `avatarstudio.session_token`
  cookie. Production adds the `__Secure-` prefix. Integrations and global avatar
  writes require a Studio session with the appropriate role.
- **Integration key (`integrationKey`).** Server applications send
  `Authorization: Bearer nsk_dev_…` or `Authorization: Bearer nsk_prod_…`.
  In an organization, owners and administrators can create integrations in the
  current workspace. In a personal workspace, the workspace owner can create one.

An integration (`ipr_*`) limits which experiences its keys can access. The
`owned` policy covers the owner's experiences in the captured workspace and
allows creation. The `selected` policy limits access to the listed
`experience_ids` and excludes creation. A key (`key_*`) grants a subset of the
integration's experience, revision, and publication scopes. Session scopes can
be assigned during integration setup and are currently reserved.

Copy the `nsk_…` secret when issuing or rotating a key. Studio shows it only
in that response. Set `expires_in_seconds` between 60 seconds and 90 days.
The default is 30 days. An integration can have up to 1,000 keys.

An invalid, expired, or revoked bearer token returns `401 invalid_api_key` with
`WWW-Authenticate: Bearer error="invalid_token"`. When you supply an
`Authorization` header, Studio authenticates the request with that header.
All keys for one integration share its per-minute request limit
(`requests_per_minute`, default 120, range 1–6,000). Exceeding it returns
`429 rate_limit_exceeded` with `Retry-After: 60`.

## Resources

- **Avatars** are global entries. Anyone can read them. Platform administrators can add or edit them.
- **Experiences** hold the draft document. The owner of an archived experience can export its original JSON without secrets.
- **Experience revisions** snapshot a draft. A revision ID starts with `rev_`.
- **Publications** bind a public `slug` and delivery policy to a revision. Draft edits leave the linked revision in place.
- **Integrations** manage workspace access and the issue, rotation, and revocation of keys.

Create a draft with `POST /v1/experiences` and this JSON body.

```json
{
  "document": {
    "schemaVersion": 1,
    "title": "Product assistant",
    "instructions": "Answer with verified facts and ask one question at a time.",
    "character": {
      "displayName": "Mia",
      "greeting": "Hello! How can I help?"
    }
  }
}
```

Write tool credentials to `document.tools.secrets`. Responses hide their values
and return configured names to the owner in `tool_secret_names`. Literal HTTP
and MCP authorization headers move to protected storage and become
`{{secrets.KEY}}` references. The selected character determines how it renders.
When supplied, `document.runtime.renderer` must be `mesh2d` or `vrm` and match
the character type.

## Open a published experience

Use `/s/{slug}` for a standalone player with chat and microphone controls, or
`/embed/{slug}` for an iframe controlled by the host page. The
[Embed SDK quickstart](/documentation/en/guides/embed/sdk-quickstart) shows how to connect it.

## Pagination and conditional requests

- List operations accept `limit` from 1 to 100 and the `after` cursor.
- Each operation page shows whether it requires `If-Match`. For example,
  `POST /v1/experiences` creates a draft without it. On
  `PUT /v1/experiences/{experience_id}`, send a single strong `ETag` from the
  latest read of that experience, including the quotes. An operation that
  requires the header returns `428 precondition_required` when it's missing
  and `412 precondition_failed` when the revision has changed. Use the latest
  collection `ETag` when updating the collection of publications.
- For a POST operation whose request schema is an empty object, send `{}`.

## JSON and errors

Use `Content-Type: application/json` for JSON request bodies. The body limit is
2 MiB for `/v1/experiences*` and 300 KiB for other `/v1/*` routes. The API
requires UTF-8 without a BOM, unique object keys, a maximum nesting depth of 128,
and numbers of at most 256 characters that preserve their value through a
JSON round trip.

Each response includes `Cache-Control: no-store` and a server `x-request-id`
(`req_*`). To correlate client requests, send `X-Client-Request-Id` with
1–512 printable ASCII characters. Studio returns the validated value.
Errors contain an `error` object with `message`, `type`, `param`, and `code`.
