Skip to main content
Embed sessions are short-lived sessions scoped to one canvas. Your backend creates them with a Moda API key, then passes the returned embed_url to your frontend. The URL contains a short-lived boot token; the iframe exchanges it for a narrower browser credential before calling canvas, asset, export, or chat endpoints.

Create an embed session

Moda-Version: 2026-05-01 is the REST API version. It is not the same as the browser protocol version: 2026-05-27 you send in postMessage envelopes — see the Browser SDK version note. They version independently.
Request
Response
Edit-mode session creation also verifies that the API key owner can edit the canvas. If not, the API returns 403.

Request fields

Modes

UI options

chat controls where the Moda agent chat appears:
  • "hidden" disables agent chat for the embed session.
  • "inside" renders a Moda-hosted chat panel inside the iframe.
  • "external" enables the agent runtime but leaves the chat UI to your application through postMessage commands and events.

Origin validation

allowed_origins must contain origins only: scheme, host, and optional port. Do not include paths.
If the iframe receives a message from an origin that is not in this list, it ignores it.

Refresh a session

Refresh rotates the session boot token for an existing session and returns a fresh browser token for the iframe. Call this from your backend before expiry, then pass the new values to the iframe with session.refresh.
Response
Then tell the iframe:
The iframe acknowledges a successful refresh by posting session:refreshed with { expiresAt }. The iframe also proactively warns you before expiry by posting session:refresh_requested (by default 60 seconds before expiry), and posts session:expired if the token lapses — refresh in response to the warning (see Refresh long-running sessions).

Revoke a session

Call revoke when the user closes the embedded editor, signs out, or loses access in your product.

Error codes

Every public API error — including session create/refresh/revoke and the internal iframe endpoints — returns the same envelope:
Session failures map to these HTTP statuses and code categories:
Expired, revoked, and invalid-token failures all surface as 401 / authentication; today they are distinguished only by the human-readable message ("Embed session expired", "Embed session revoked", "Invalid embed browser token"). Branch on status for recovery (re-mint on 401, surface a permission error on 403), and treat message as non-stable display text. Finer-grained machine codes are a known beta limitation.
When one of these failures happens inside the loaded iframe (for example, the browser token expires mid-session), the iframe forwards it to your page as a load:error event carrying the same code and status.

Internal iframe endpoints

The iframe exchanges the boot URL token for a short-lived embed browser credential, then uses that credential for internal browser-hit endpoints:
  • GET /v1/embed/sessions/{session_id}/canvas
  • PATCH /v1/embed/sessions/{session_id}/canvas
  • POST /v1/embed/sessions/{session_id}/images
  • GET /v1/embed/sessions/{session_id}/images/{file_id}
These calls use Authorization: Bearer <embed_browser_token>. You normally do not call these directly. Use the iframe and browser SDK commands instead.