# Errors

> Every error has the same shape and a stable code.

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_document",
    "message": "pages[0].canvas needs a width and height",
    "param": "document",
    "docs_url": "https://muzekit.com/docs/errors#invalid_document"
  }
}
```

`type` groups errors by status; `code` never changes meaning, so match on it.

| Status | type |
|---|---|
| 400 and other 4xx (402, 410, 413, 415, 422, 428) | `invalid_request_error` |
| 401 | `authentication_error` |
| 403 | `permission_error` |
| 404 | `not_found_error` |
| 409 | `conflict_error` |
| 429 | `rate_limit_error` |
| 5xx | `api_error` |

## Codes

| Code | Meaning |
|---|---|
| `missing_api_key` | No `Authorization: Bearer` header |
| `invalid_api_key` | Unknown or revoked key |
| `workspace_suspended` | `403`: the editor is suspended |
| `invalid_request` | A field is missing or invalid; see `param` |
| `invalid_document` | The document breaks a rule; `problems` lists them all |
| `template_not_found` | No such template in this workspace and environment |
| `revision_conflict` | The document changed since you read it |
| `if_match_required` | Saving a document needs `If-Match` |
| `external_id_taken` | Another template has this `external_id` |
| `idempotency_key_reused` | The same `Idempotency-Key` was used on another request |
| `idempotency_in_progress` | A request with this `Idempotency-Key` is still running; retry in a moment |
| `invalid_client_secret` | The session's client secret is unknown, expired or used |
| `origin_not_allowed` | The page embedding the editor is not an allowed domain, or a Live key was used on localhost (use your Test key there) |
| `rate_limited` | Too many requests; wait for the time in the `RateLimit` header |
| `render_unavailable` | `503`: renders can't be queued for a moment; try again shortly. Nothing was charged |
| `plan_required` | `402`: the editor has no plan, or its plan is paused or unpaid; `reason` says which (`no_plan`, `payment_failed`, `subscription_paused`) |
| `sessions_exhausted` | `402`: this period's sessions and the 3% margin are used. Editors already open keep working; add sessions in Billing, move up a plan or wait for the next period. `top_up_url` is set when you can add a pack |
| `localhost_sessions_exhausted` | `402`: this period's free localhost sessions (fair use) are used. Test on your staging domain, or wait for the next period |
| `api_credits_exhausted` | `402`: this period's API credits are used. Test-key renders stay free |
| `test_renders_exhausted` | `429`: this Test environment made 500 renders (or 50 videos) in the last 24 hours. Test renders are for trying things out; render with your Live key for production |
| `ai_credits_exhausted` | `402`: this period's AI credits are used, or the plan has none |
| `member_limit` | `402`: the plan's team seats are used |
| `unsupported_file` | An upload isn't an image, video, audio file or font the editor can use (checked from the file's bytes) |
| `file_too_large` | Over the size limit: images 25 MB, video 200 MB, audio 50 MB, fonts 10 MB |
| `unsafe_svg` | The SVG contains scripts, event handlers or `javascript:` links |
| `upload_expired` | The upload link was used, or is older than 15 minutes |
| `storage_full` | `402`: the editor's storage (plan plus storage add-ons) is full; files already uploaded keep working. Remove files or add storage |
| `addon_required` | `402`: AI assistants for your users need their add-on in Live; they are free in Test. Add it in Billing |
| `trial_no_addons` | `409`: add-ons start with the first payment; start your plan now in Billing to add them |
| `no_trial` | `409`: the editor isn't in a free trial, so there is no trial to end |
| `payment_needs_action` | `402`: an upgrade needs the card holder to approve the payment; `invoice_url` opens it |
| `yearly_to_monthly` | `409`: a yearly plan moves to monthly at renewal, not mid-period |
| `copy_direction` | `400`: Copy to Live only goes from Test to Live |
| `request_expired` | `404`: an AI app's sign-in request (`/v1/assistant/requests/…`) was used or is older than 10 minutes; the user starts again from their AI app |
| `asset_in_use` | `409`: templates still use the file you are deleting; `templates` is how many, `names` the first few. Send `force=true` to delete it anyway, which breaks them |

## Connected apps

An AI app connected through [MCP](/docs/mcp) gets the codes above, plus these when its sign-in doesn't allow a call:

| Code | Meaning |
|---|---|
| `invalid_token` | `401`: the sign-in expired or was revoked; the app signs in again |
| `forbidden` | `403`: the member's role can't do this on that editor (see [Team](/docs/team)) |
| `insufficient_scope` | `403`: the member didn't allow this for that editor when they connected the app; `scope` names what's missing |
| `live_write_not_granted` | `403`: a change in Live without **Live changes**; reconnect and allow it |
| `dashboard_only` | `403`: billing, API keys, webhook secrets and deleting or transferring an editor are done in the dashboard only |

## In the browser

The SDK reports these through `on.error`, and logs them to the console when
your page has no error handler.

| Code | Meaning and fix |
|---|---|
| `client_secret_unavailable` | `fetchClientSecret` failed or did not return the `client_secret` string. Check what your session route returns. |
| `editor_unreachable` | The editor never loaded. Check `editorUrl`, and allow the editor's origin in your Content-Security-Policy `frame-src`. |
| `no_parent` | The editor got no client secret from your page in time. Mount it with `Muzekit.mount`. |
| `invalid_session` | The session ended. Mount again so your server opens a new one. |
| `session_expired` | The session reached its maximum age. Mount again. |
| `read_only` | A view session tried to change a template. |
