# API reference

> Base URL, authentication, ids, pagination, idempotency, errors and the OpenAPI spec.

## Base URL

```text
https://api.muzekit.com/v1
```

## Authentication

Every request needs a secret key: `Authorization: Bearer mk_test_…` or `mk_live_…`. A key only sees its own environment's data. See [API keys](/docs/api-keys). AI apps don't use keys: they connect through the [MCP server](/docs/mcp) with a Muzekit sign-in.

## IDs

Ids are opaque strings with a prefix (`tpl_`, `usr_`, `ver_`, `ast_`, `rnd_`, `bat_`, `shr_`, `ses_`, `ws_`). Store them as strings.

## Lists

List endpoints return `{ "object": "list", "data": [...], "has_more": true, "next_cursor": "tpl_…" }`. Pass `?limit=` (1 to 100, default 20) and `?after=<next_cursor>` for the next page.

## Idempotency

Send `Idempotency-Key: <unique string>` on any `POST`. Repeating the request within 24 hours returns the first response (with `Idempotent-Replayed: true`) instead of doing the work twice. While the first request is still running, a repeat answers `409 idempotency_in_progress`; retry in a moment. A key used on a different endpoint answers `409 idempotency_key_reused`.

## Rate limits

600 requests a minute from one address, and of those up to 60 renders a minute per key (single and batch). Responses carry `RateLimit` headers; over the limit you get `429 rate_limited`.

Test renders are free, so a Test environment can make up to 500 renders a day, 50 of them videos (`429 test_renders_exhausted`); render with your Live key for production.

## Errors

See [Errors](/docs/errors).

## Common flows

Each flow runs on your server with your secret key. Each step links to its endpoint, with examples there.

### Onboard a user with their own library

1. When the user signs up in your app, [create the user](/docs/api-reference/users-upsert) with your own id. Keep the `usr_…` id it returns.
2. [Upload files](/docs/api-reference/assets-upload) into their library with `user: "usr_…"`, then `PUT` the bytes to `upload_url`. Their logo and photos are ready before they open the editor.
3. When they open the editor, [create a session](/docs/api-reference/sessions-create) with the same `user.id` and mount it on your page with [the SDK](/docs/embed-sdk).

### Let a user fill in your template and get the files

1. Your team makes a template in the dashboard, marks its fillable fields, and gives it a key such as `product-card` (or [set the key](/docs/api-reference/templates-update) with `external_id`).
2. [Create a session](/docs/api-reference/sessions-create) with `mode: "fill"` and `template: "product-card"`.
3. The user's first change saves their own copy: you get the `template.created` [webhook](/docs/webhooks), then `template.updated` on each save. Store the `tpl_…` id against your user to [reopen it](/docs/api-reference/sessions-create#reopen-a-design-your-user-saved) later.
4. Get the files: turn on **Render on save** to receive `render.succeeded` with the file URLs, or [create a render](/docs/api-reference/renders-create) of the saved template when you need it.

### Render personalized images in bulk

1. [List the template's parameters](/docs/api-reference/templates-parameters) to get the keys a render can change.
2. With a Live key, [check your API credits](/docs/api-reference/workspace-get#check-api-credits-before-a-large-batch) cover the job.
3. [Create a batch](/docs/api-reference/renders-batch) with up to 100 items, one set of `modifications` each.
4. Follow it with [List renders](/docs/api-reference/renders-list) (`?batch=bat_…`) or the `render.succeeded` webhook, and store each output URL before `expires_at`.

### Show a user their designs in your app

1. [List templates](/docs/api-reference/templates-list) with `?user=usr_…` for their designs and preview images.
2. When they pick one, [create a session](/docs/api-reference/sessions-create) with `template: "tpl_…"` in `design` mode; saves update that design in place.
3. For a read-only preview or an approval step, open the same design with `mode: "view"`.

### Match the editor to your pricing tiers

1. Map each of your tiers to session choices: `features`, `formats`, `videoFormats`, `maxPages` ([example](/docs/api-reference/sessions-create#give-each-pricing-tier-its-own-editor)).
2. Pass them on every [session](/docs/api-reference/sessions-create) your server creates. Your page can narrow them further, never widen them.
3. Watch what it costs you: [get the workspace](/docs/api-reference/workspace-get) for this period's sessions and credits, and [get usage](/docs/api-reference/usage-get) for what your users did each day.

## OpenAPI

[Download the OpenAPI spec](/openapi.json) (OpenAPI 3.1) for every endpoint on these pages. Import it into Postman, Insomnia or a client generator.
