Worlds
A world is a programmable, playable graph of states (what the scene is) and events (what the player can do to move between them), rendered live as the player navigates it. You don’t author that graph by hand. You describe a premise and the API generates a complete, valid world. From there it’s yours to program: read it, patch it, fork variants, and react to its events at runtime. Every world returned by the API conforms to a frozen, versioned contract, the SMWorld schema (schemaVersion: "1.0"). New optional fields may be added in
minor versions; breaking changes only ever come with a major version, and the
previous major stays readable. See the SMWorld schema in the
API reference for the full shape.
Apps and keys
An app is your project: the tenant every world, session, and usage record belongs to. Each app issues API keys:- Publishable (
pk_…): safe to expose in a browser, read-only (it can also drive a like button). It cannot mint session tokens, so embedding a world is driven by a session token your server mints with a secret key, not by apk_key directly. - Secret (
sk_…): server-only. Creates and edits worlds and mints session tokens.
test and live modes. The prefix tells you which (sk_test_…
vs sk_live_…). A test key runs against a free sandbox: generative
endpoints return deterministic mocks ("mock": true), test data is isolated
from live, and nothing is billed. See Testing.
Sessions and the two-token rule
To play an embedded world, the browser needs a credential, but never your secret key. Instead:- Your server calls
/v1/sessions/tokenwith the secret key. - You get back a short-lived session token, scoped to one world, one player, and (optionally) one embedding origin.
- The browser passes that token to
@alakazamworld/embed.
Idempotency
POST /v1/worlds, POST /v1/characters, and POST /v1/worlds/{id}/edit accept
an Idempotency-Key header. A retried request with the same key returns the
original result (cached for 24h) instead of generating a second time. Use it
whenever a network retry is possible. Keys are scoped per (app, mode, key value),
so test and live keep separate idempotency caches. Reusing the same
key across modes is safe.
Quota and billing
Every operation is reserved before any GPU spend against a per-app daily quota; over it you get402 and nothing runs. That is a free abuse guard, not a charge.
Billing, when enabled, is runtime-only: you pay for session_seconds (live
play time), while creating, editing, and everything else are free. Test-mode
usage is never billed. Everything is free during the developer preview. Check
your balance with GET /v1/usage; see Pricing for the full model.
