Skip to main content
WS /v1/ws reads every frame you send with one model and method, and returns the model’s reply as a result event. The reply is what Chat Completions returns for the same image. You name the model and method once, in session.create, then send each frame as one binary message of raw image bytes. The session reads one frame at a time by default. A frame that arrives while a read is outstanding is dropped with reason: "busy", and a frame that arrives faster than the model’s max_fps is dropped with reason: "rate". The lifecycle, close codes, and models are on Realtime.

Example

The sample opens a pose session on usyd-community/vitpose-plus-large, sends one photo 20 times at the model’s max_fps, and prints each result, frame.dropped, and error. It then sends session.close and prints session.stats. Before session.created, the Gateway can send session.queued while a session cap is full, or session.redirect to move the session to an edge cluster. The sample waits through the first and follows the second. The fallback for an edge that fails is in the reference.

The result event

content is the pose method’s output as a JSON string: an img.pose.kpts container with one item per person. response.usage.cost is null. The socket does not bill per frame: it bills the session by the second, as session.stats.cost. Each result also carries session_id, and received_at_ms and response_at_ms on the server’s clock, in Unix epoch milliseconds.

Session stats

Of the 20 frames, 5 were read and 15 arrived while a read was outstanding. The session was open about 1.8 seconds, which is $0.0015 at $3 / hour. The frame count does not change the price. Read the row back with GET /openai/completions/{id}.

Read more of the frames

Backpressure drops. It never queues. A queued frame would answer for a moment you have already moved past. Each dropped frame is reported, so you can count what you skipped.
  • Raise max_inflight. Set it in session.create, up to 8. The session keeps that many reads outstanding, and a slot frees when its read returns.
  • Pace at max_fps. session.created returns the model’s rate. Sending faster only adds rate drops.
  • Close the session when you stop. A session bills every second it is open, with or without frames. Send session.close instead of leaving it to the 30 second idle close.

Pick the model and method

session.create takes the same method and method_params as a Chat Completions request. See Methods. prompt is optional text that goes with every frame.
geopavlakos/hamer returns an img.pose.hands3d container with one item per hand: its side, 2D joints on the image, and 3D joints rooted at the wrist. See Hand Tracking. facebook/sam3.1 segment_box needs method_params.bbox_xywh, and segment_point needs points_xy and point_labels, clicks as fractions of the frame. The box and the clicks stay fixed for the session. track reads the session’s frames as one video from the first frame, so it reads one frame at a time and max_inflight is 1. See Track objects across frames. A model without realtime support is refused at session.create. The models that stream on this socket are listed in Supported models.

Ask a question of every frame

qwen/qwen3.5-0.8b:realtime and google/gemma4-e2b-it:realtime answer one prompt per frame. Set response_format to a JSON schema to get typed JSON back, and max_tokens to cap each answer. Both apply to every frame of the session.
Each result carries the answer in response.choices[0].message.content, as a JSON string that matches the schema. These two models run only on the socket and need an API key from a signed-in organization. A POST /chat/completions call to either returns 400 with code socket_only.

Errors

An error event with a frame applies to that frame only, and the session stays open. A frame that is not JPEG, PNG, WebP, or GIF, or is larger than max_frame_bytes, returns invalid_request_error. A model failure returns overloaded_error or api_error with retry_after. An error at open, or when the session reaches its spend ceiling, ends the session, and a close follows. The error types are in the reference. What to do after each close code is in Close codes.

Limits and cost

A session lasts up to 10 minutes from session.created, closes after 30 seconds idle, and stops at $5 of spend. Frames are capped at 2 MiB. Sessions per plan are on Rate Limits, and the price of each model on the socket is in Supported models.

Next steps

WS /v1/ws reference

Every client and server event, with its fields.

Response Types

The keypoint payload each result carries.

Realtime System One

Typed decisions per frame instead of a model reply.

Rate Limits

Sessions per plan and per-session bounds.