wss://api.interhuman.ai/v1/stream/analyze. This guide covers what the quickstart deliberately leaves out: how to put that call inside a real application — one where the camera runs in a user’s browser and your API key stays secret.
If you follow only three rules from this page, make them these:
- Never ship your API key to the browser. Mint a short-lived, capped client token server-side and hand that to the client instead.
- Let the browser stream directly to Interhuman with the client token. The token is designed for exactly this, and the API enforces its caps.
- Send media segments exactly as the recorder produces them. Never re-slice, reassemble, or reinterpret the media container in between.
This guide is written for humans and for AI coding agents. If you are prompting an agent to build an Interhuman integration, include this page (or paste the three rules above) — the naive implementation that hardcodes the API key in client code works in a demo and leaks your credential in production.
Why you can’t ship the API key
The stream endpoint authenticates with your API key (ih_live_...) as a Bearer credential on the WebSocket handshake. If that key appears anywhere in client code, it ships to the user — it’s in your JS bundle, visible in the network tab, extractable from anyone’s devtools. That is a leaked production credential.
The key must stay server-side. What the browser gets instead is a client token: a short-lived credential your backend mints from POST /v1/client_tokens, scoped and capped so that leaking it costs you a few minutes of bounded usage, not your account.
The architecture
Two parts, one job each:- A token route on your backend calls
POST /v1/client_tokenswith your API key and returns the minted token to the browser. This is stateless, single-request work — a serverless function is fine here. - The browser connects directly to
wss://api.interhuman.ai/v1/stream/analyzewith the client token, streams recorded segments up as binary frames, and receives analysis events back. The caps embedded in the token (duration, bytes, concurrency, video budget, allowed origins) are enforced by the API itself.
Mint a client token
Use the TypeScript SDK (@interhumanai/sdk) in your token route, or call the endpoint directly:
You can also revoke a token early (
POST /v1/client_tokens/revoke, or auth.revokeClientToken(...) in the SDK) — new requests are rejected immediately and any live session is torn down on its next chunk. Useful when a token outlives the thing it was minted for, like a user logging out mid-session.
Connect from the browser
The SDK’sStreamClient handles the connection, authentication, typed events, and graceful shutdown:
Authorization header on a WebSocket, so pass the token via the subprotocol pair the endpoint accepts:
Send media the way the recorder produces it
This is where integrations lose the most time. The producer of the media —MediaRecorder in the browser — already emits self-contained, valid WebM segments when you record with a timeslice:
- One recording, one giant frame. The endpoint enforces a 32 MB maximum WebSocket message size; a 3-minute recording at typical bitrates exceeds it, and you get an
ih6002(“message too large”) error or the upstream resets the socket mid-send (close code1006, no close frame). Worse, large single messages fail unreliably even under the cap. Small and many beats big and one. - Re-slicing the media in transit. Parsing the WebM/EBML structure yourself and cutting your own chunk boundaries is fragile: dropped trailing metadata or a mis-cut boundary produces a truncated container and an
ih5004(“malformed segment”) error. Container parsers that pass tests against synthetic ffmpeg files still mis-cut real live-muxed browser output. - Concatenating timesliced segments later.
MediaRecorderonly writes the duration into the header onstop(), so stitching timeslice segments into one blob yields a broken file. Streaming each segment live and independently is fine; concatenation is not.
End the session cleanly
Analysis events stream in throughout the recording, so most results have already arrived by the time the user stops. Accumulate events client-side as they come — there is no end-of-session summary to wait for. When the user stops recording, request a graceful shutdown instead of closing the socket:session.closing (its data.max_drain_seconds is the longest you should wait), finishes analyzing the video it already accepted — emitting the remaining envelopes, plus signal.ended for still-active signals — then sends session.ended and closes with code 1000. Listen for session.ended (or close) rather than closing the socket yourself; closing early discards trailing analysis.
Debugging: symptom → cause
Next steps
- Client tokens API — full request/response schema, scopes, and caps.
- TypeScript SDK reference —
AuthClient,StreamClient, typed events, and upload support. - Stream analysis quickstart — the endpoint call itself: session config, media frames, and event envelopes.
- Stream & analyze API reference — full AsyncAPI channel, headers, and message schemas.
- Error handling — structured error codes, including
ih5004andih6002.