Docs
Guides and references for building games on oai.
Getting Started
Recipes
- Multi-character scenesPattern for several AI characters in a shared scene, each tracking their own perspective. One agent per character, broadcast each event via addMessage, take turns via message-less send. Covers chat rooms, juries, panels, councils, debates, ensemble casts.
- Reference images & multi-character shotsUse generateImage's referenceImages to keep a character visually consistent across images and to compose several characters into one image (a two-shot of both speakers, a group scene). Generate one canonical portrait per character, store its URL in state, then pass it as a reference for every later shot.
- Time, ticks & background playHow to build time-driven games — countdown timers, pets, farms, day/night, idle simulations. Pair onTick with tickInterval to run code on a fixed cadence; read the two frozen clocks state.gameTime (game-active ms, the one for timers) and state.now (wall timestamp, for real-world logic); emit input events from a tick to bridge into onEvent; and opt into backgroundExecution to keep ticking up to 48h after the player leaves.
- NotificationsReach the player when something happens in your game — "your farm needs water", "the negotiation took a turn". Call ctx.io.notify({ title, body, image?, tag? }) from onEvent (or a tool's execute) to push a notification into the player's cross-game inbox (the nav bell) and, when they're on the site, a toast. Detect a condition in onTick and bridge to onEvent with emitInputEvent. Notifications are replay-safe, free (only the content you generate spends), and coalesce by tag.
Physiology
- Urethral cascadeDrop-in TS implementation. Given the bladder pressure and each gate's closing pressure, returns the flow rate and pressure profile along the urethra. For why the formula has its shape, see Urethral fluid dynamics.
- Urethral fluid dynamicsClosed-form derivation of urethral flow and pressure, given bladder pressure, the sphincter chain, and any external obstruction.