BeatAPI Realtime Video API
Use BeatAPI Realtime Video API to stream browser video and guide live AI generation with a prompt, an optional reference image, or both.Your server continues to authenticate with the same BeatAPI API key:The browser never receives that API key. It receives a short-lived BeatAPI client_secret and uses @beatapi/realtime. Browser control requests stay on the BeatAPI transport endpoint; WebRTC media remains direct and is not relayed through BeatAPI.1. Create a session on your server#
Allowed durations are 15, 60, and 300 seconds. Reusing the same user and Idempotency-Key with the same body returns the same Session and the same short-lived client_secret; it does not reserve credits or capacity twice or invalidate a browser already using that credential.2. Connect in the browser#
import { createRealtimeClient } from '@beatapi/realtime';
const camera = await navigator.mediaDevices.getUserMedia({ video: true });
const output = document.querySelector<HTMLVideoElement>('#output')!;
const client = createRealtimeClient({ clientSecret: session.client_secret });
const realtime = await client.connect({
input: camera,
output,
initial: {
prompt: 'Transform the person while preserving movement and lighting.',
referenceImageUrl: 'https://media.example.com/character.png',
},
});
await realtime.set({
referenceImageUrl: 'https://media.example.com/character.png',
prompt: 'Use a painterly style while preserving motion.',
});
await realtime.disconnect();
The public SDK surface contains only connect, set, disconnect, and event subscriptions. set requires a non-empty prompt, an HTTPS reference image URL, or both. BeatAPI /v1/files or your own public HTTPS storage is recommended for reference images.input: a browser MediaStream, usually from a camera or a captured media element.
prompt: optional text that describes the requested live transformation.
referenceImageUrl: an optional HTTPS image that guides character, clothing, object, or visual-style generation.
Realtime describes the live WebRTC input/output path. A static reference image is an optional generation condition; it does not replace the live video input.Lifecycle and billing#
Public states are ready, connecting, active, closed, failed, and expired.Credits are reserved when the Session is created. The BeatAPI browser runtime sends its first billing heartbeat only after the first remote output frame is rendered. When that accepted BeatAPI billing heartbeat succeeds, the Session becomes active and the selected fixed duration is fully settled. A Session that closes or expires without an accepted billing heartbeat is fully refunded. Billing activation is derived from the trusted transport lifecycle, not from a caller-supplied browser event. DELETE /v1/realtime/sessions/{session_id} is idempotent and releases capacity; expired sessions are also cleaned automatically.Browser security#
Set exact production origins in allowed_origins; wildcards are rejected.
Never place a BeatAPI sk_... API key in browser code.
Do not log or persist client_secret; discard it after the Session closes.
Show camera permission, likeness, IP, and reference-asset consent before capture.
Handle realtime_session_expired, realtime_capacity_unavailable, and rate-limit errors by creating a new Session or retrying after the supplied delay.
The private SDK transport is intentionally absent from the public OpenAPI navigation. It accepts only the fixed Session create/get/heartbeat/delete control paths and cannot be used as a general HTTP proxy.SDK events and cleanup#
Subscribe on the client before connecting when you need the full lifecycle:const client = createRealtimeClient({ clientSecret: session.client_secret });
const unsubscribe = client.on('error', ({ error }) => {
console.error(error?.message);
});
const connection = await client.connect({ input: camera, output });
// connecting -> connected -> first_frame -> disconnected, or error
await connection.disconnect();
unsubscribe();
camera.getTracks().forEach((track) => track.stop());
Disconnecting the browser transport does not replace server-side cleanup. Your server should also call DELETE /v1/realtime/sessions/{session_id}; that operation is idempotent.Browser requirements#
HTTPS in production, or localhost for development.
navigator.mediaDevices.getUserMedia, MediaStream, WebRTC, and HTMLVideoElement playback.
User-granted camera permission and an exact origin listed in allowed_origins.
Testing on every browser, device, embedded webview, and network your product supports.
BeatAPI does not document a fixed first-frame latency, frame rate, resolution, or universal browser matrix. Live behavior depends on the browser, device, network, region, and currently available capacity.Errors and retries#
Use the HTTP status, stable BeatAPI error code, and request_id together. When retry_after_seconds is present on a rate-limit or retryable capacity response, wait at least that long before retrying.realtime_capacity_unavailable: capacity is temporarily unavailable; retry with backoff.
realtime_session_expired: create a new Session and reconnect.
origin_not_allowed: recreate the Session with the browser's exact origin.
invalid_client_secret: discard the credential and create a new Session from your server.
transport_not_allowed: the private transport path or operation is not part of the SDK contract.
CLI#
@beatapi/realtime-cli manages server-side Session operations and diagnostics. It does not run camera or WebRTC media.The CLI reads the key only from BEATAPI_API_KEY, prints the API JSON envelope to stdout, and returns a non-zero exit code on failure.Privacy and acceptable use#
Give clear notice and obtain the rights and consent required before capturing or processing a camera, screen, voice, face, likeness, or reference asset. Realtime does not automatically create a hosted MP4. If your product records output locally with MediaRecorder, your product controls the recording, disclosure, security, retention, sharing, and deletion flow.Availability#
Realtime Video production access remains limited while BeatAPI completes commercial, package-licensing, legal, capacity, and real-browser acceptance checks. The REST and SDK interfaces in this guide describe the release-candidate contract; they are not a promise of unrestricted production capacity. Modified at 2026-07-31 15:12:20