Skip to main content
This tutorial covers HappyOyster worlds and character performances. The world walkthrough uses the typed HappyOyster React SDK. The world app can:
  • open an Adventure or Directing session
  • create a world and show build progress
  • save and reattach a world
  • stream the live world into a video element
  • expose controls appropriate to the selected experience
For a complete project, see the HappyOyster example.

Install the SDK

Install @reactor-models/happy-oyster. The world walkthrough imports its React bindings from @reactor-models/happy-oyster/react.

Mint a client token

Keep the Reactor API key on your server. Exchange it for a short-lived JWT and return only the JWT to the browser:
Use a resolver in the client so the SDK can request a fresh token for later Reactor API calls. A session can only be operated by the exact token that created it, so the resolver memoizes the token itself and only re-mints once it’s close to expiring — re-minting on every call would hand a later call a fresh token with no sessions bound to it, and it 403s. See Authentication for the full pattern:

Mount the provider

The mode belongs on the provider, not on createWorld(). Use "adventure" for movement controls or "directing" for text steering:
The provider owns one client for its lifetime. To switch from Adventure to Directing, remount it:

Create a world

createWorld() accepts parameters for the provider’s mode and resolves when the world reaches ready.
Adventure parameters:
Directing parameters:
The client mode determines which parameter set is valid. createWorld() does not take a mode field.

Reopen a saved world

Worlds persist beyond a session. Reopen one by its encrypted id:
A world id saved before SDK version 1.0.1 no longer resolves. attachWorld() rejects it with code 403001. Drop the saved id and create a new world. The world must belong to the provider’s selected mode. Attach an Adventure world through an Adventure provider and a Directing world through a Directing provider.

Start and stop a travel

Mount <HappyOysterVideo /> before starting. Once the current world is ready:
endTravelSession() ends the live travel but keeps the Reactor session and world ready. disconnect() closes the session; the world remains available for a later attachWorld().

Show the remaining travel time

An Adventure travel runs for up to 2 minutes, and the platform ends the stream when that budget runs out. The hook reports the granted length as maxExperienceTimeSec. Count down from it, with ADVENTURE_MAX_EXPERIENCE_SEC covering the render before a travel is open:
A Directing travel runs for up to 3 minutes and reports maxExperienceTimeSec as null. Count its clock down from that length and call endTravelSession() when it reaches zero.

Add Adventure controls

Adventure input is held state. Call move, look, or interact when an input begins, then release the corresponding axis when it ends:
The SDK maintains the resend cadence required for held controls. Send transitions instead of sending commands every animation frame.

Add Directing controls

Directing uses text instructions and playback controls:
Instructions and chapters arrive in the authoritative travel snapshot:
Use useHappyOysterTravelStatus() to track whether a Directing travel is running, paused, or completed.

Handle errors

Awaited setup calls reject on failure. Gate and upstream failures use HappyOysterActionError:
Useful codes include: Runtime stream errors are available through useHappyOysterTravelError().

Add an Acting experience

Acting uses a reusable character and a performance. The token route above includes reactor/happy-oyster-acting in authorization_details. An Acting-only app can scope its route to that model alone. Keep the API key on the server and return the same token for the session’s life.

Create or attach a character

  1. Supply a character prompt and exactly one image source to create_character. For portrait 9:16, use an image with width/height from 0.5 to 0.667. For landscape 16:9, use a ratio from 1.5 to 2.0.
  2. Mirror session_state to show build progress. The command returns before the build finishes.
  3. Save the account-scoped character_id for later reuse with attach_character. The API specifies no retention period; handle CHARACTER_NOT_FOUND if a saved id cannot be attached.
  4. Wait for character_status: "ready" before starting a performance.

Perform and direct

Call start_performance and wait for snapshot phase live. Display main_video with speech from main_audio. Supply a playback control for browsers that block audible autoplay. Receiving an audio track alone does not establish audible playback. Send instruct commands with a text field for actions and speech. Track pending and performed instructions in the snapshot. Paused instructions take effect after resume; an acknowledgment does not mean the character performed an instruction. A rejected instruction can leave the performance live. Read the end_performance result from the awaited call, then wait for snapshot phase ended before starting another performance. The character stays attached. Keep Start disabled through starting and ending, and show failures from the current snapshot alongside SDK call errors. The active performance limit excludes paused time. performance_elapsed_seconds includes it, so subtracting that field from performance_max_seconds gives an incorrect countdown after a pause.

Keep connection state current

Mirror the authoritative session_state broadcast, and apply replies from get_state only to the connection that requested them. Clear local snapshots when the connection ends. Ignore replies and uploads from older connections so they cannot restore stale state in a new session. The Acting reference lists command fields, image formats, URL alternatives, replies, phase gates, and errors.

Next steps