16:9 architectural rendering or store floorplan (compressed JPEG under 48 KB) and let stakeholders walk the space in WebRTC while testing live lighting, weather, and material changes via key-bound prompts at ~$3.02 per 30-second walkthrough.24 fps frame streams.48 kHz audio.Keep GEMINI_API_KEY strictly on your backend, mint a single-session token via interactions.authTokens.create(), and enforce a hard visibility/timeout guard so idle tabs call session.complete() automatically.
import { GoogleGenAI } from "@google/genai";
// Server-side endpoint (Node.js)
const serverAi = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY, apiVersion: "v1beta" });
export async function createGenieSession() {
const interaction = await serverAi.interactions.create({
model: "models/genie-4",
api_version: "v1beta",
});
const { auth_token } = await serverAi.interactions.authTokens.create(interaction.id, {
api_version: "v1beta",
});
return { interactionId: interaction.id, authToken: auth_token };
}
// Browser client: connect over WebRTC and always complete() on exit
export async function launchWorld(interactionId, authToken, videoEl) {
const clientAi = new GoogleGenAI({ apiKey: authToken, apiVersion: "v1beta" });
const session = await clientAi.interactions.connect(
interactionId,
{ transport: "webrtc", api_version: "v1beta" },
{ timeout_ms: 30000 }
);
session.transport.setVideoElement(videoEl);
await session.send({
event_type: "world_setup",
world_prompt: {
text: "First-person POV on a coastal cedar boardwalk at dawn. Rule: Approaching the brass telescope far away from me reveals distant cargo ships through sea mist.",
},
});
return session;
}
import asyncio
from google import genai
async def stream_world():
client = genai.Client(http_options={"api_version": "v1beta"})
interaction = await client.aio.interactions.create(model="models/genie-4", api_version="v1beta")
async with client.aio.interactions.connect(interaction.id, api_version="v1beta") as session:
await session.send({
"event_type": "world_setup",
"world_prompt": {"text": "First-person POV inside a quiet botanical glasshouse with rain tapping on glass."},
})
frames = 0
async for event in session.receive():
if event.event_type == "step.delta" and getattr(event.delta, "type", None) == "video":
frames += 1
if frames == 1:
await session.send({"event_type": "user_action", "action": "key_down", "input": "key_w"})
elif frames == 120: # 5 seconds at 24 fps
await session.send({"event_type": "user_action", "action": "key_up", "input": "key_w"})
await session.complete()
elif event.event_type == "interaction.completed":
break
asyncio.run(stream_world())
Estimate session costs at 5,760 tokens/sec, lint your causal Rule: world prompts against Google’s five tested patterns, and test WebRTC payload limits inside Genie 4 Interactive World API Studio [SIMULATED DEMO].