Documentation
¶
Overview ¶
Package openrealtime implements the OpenRealtime Protocol, version 1.
The OpenAI Realtime API is large and mature, so the additions here are few, orthogonal, and strictly compatible. Five principles hold:
- Strict superset. Every valid Realtime GA session is a valid OpenRealtime session. A voice-only client written against the base API works here with no changes and no awareness that the extension exists.
- Namespaced. New events are prefixed "openrealtime."; new fields live under an "openrealtime" key inside existing objects. No existing event changes shape and no existing field changes meaning.
- Negotiated, never assumed. Extensions activate only after the client declares support and the server confirms. Absent negotiation, behaviour is exactly the base protocol - which makes backward compatibility a property of the negotiation rather than of client discipline.
- Minimal. Three events and two object extensions, on a protocol with 66 wire names.
- Actions are not new protocol. Computer use rides existing function calling; the result of an action is the next screen, and the screen already arrives through the video stream.
The protocol has no abbreviation. The wire namespace is "openrealtime.", the project is OpenRealtime, and the protocol is the OpenRealtime Protocol - one name to learn rather than a name plus an acronym.
Index ¶
- Constants
- type ClientEffectCall
- type ClientEffectDeclaration
- type DebugCategory
- type DebugEvent
- type DebugRequest
- type DebugResponse
- type Feature
- type InspectionAccess
- type Limits
- type ObservationAdded
- type Request
- type Response
- type SourceState
- type ToolExtension
- type VideoFrameAppend
- type VideoSourceUpdate
Constants ¶
const ( // EventVideoSourceUpdate declares or updates a video source. It is // required before frames, and it exists mainly for geometry: a click at // (x, y) is meaningless without the coordinate space the model saw. EventVideoSourceUpdate = "openrealtime.input_video_source.update" // EventVideoFrameAppend carries one frame. EventVideoFrameAppend = "openrealtime.input_video_frame.append" // EventObservationAdded reports what an observer perceived. Observations // are already committed to the trajectory; this event exists so a client // can display and audit them, and it is purely outbound. EventObservationAdded = "openrealtime.observation.added" // EventDebug is an opt-in developer event. It is not an application // capability and is never emitted unless session.openrealtime.debug was // explicitly enabled. EventDebug = "openrealtime.debug.event" )
Event type names. The three of them are the entire wire addition.
const Version = 1
Version is the protocol version this implementation speaks. It lives inside the "openrealtime" key, so it carries the number and nothing else: repeating the name inside a field already named for it would be noise.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientEffectCall ¶
type ClientEffectCall struct {
Version int `json:"version"`
DeclarationDigest string `json:"declaration_digest"`
Authority string `json:"authority"`
}
ClientEffectCall is the server-only extension on response.function_call_arguments.done. Authority is an opaque, bounded, short-lived receipt; clients forward it to the effect host unchanged.
func (ClientEffectCall) Validate ¶
func (call ClientEffectCall) Validate() error
Validate rejects a call extension that could not be forwarded as one canonical receipt. Cryptographic validation belongs to the host provider.
type ClientEffectDeclaration ¶
type ClientEffectDeclaration struct {
Version int `json:"version"`
DeclarationDigest string `json:"declaration_digest"`
}
ClientEffectDeclaration is the additive extension on a function tool. Its digest is computed by the independently mounted effect host and commits the schema, consequence policy, target, channel, and permission resource.
func (ClientEffectDeclaration) Validate ¶
func (declaration ClientEffectDeclaration) Validate() error
Validate rejects a declaration the server could not bind exactly.
type DebugCategory ¶
type DebugCategory string
DebugCategory names one subsystem in the optional developer trace stream.
Debugging is deliberately configured separately from Features. The three portable v1 capabilities describe application behaviour; the debug stream describes this implementation and is useful precisely because it can name implementation details such as its acoustic gate and cognition phases.
const ( DebugVAD DebugCategory = "vad" DebugASR DebugCategory = "asr" DebugVideo DebugCategory = "video" DebugCognition DebugCategory = "cognition" DebugPolicy DebugCategory = "policy" DebugTTS DebugCategory = "tts" DebugTool DebugCategory = "tool" DebugSession DebugCategory = "session" DebugError DebugCategory = "error" // DebugGraph carries element-graph execution traces. Graph-native // deployments were already producing these and naming them "graph", which // no client could select, so every one of them was dropped by the category // filter on the way out. A category a client cannot ask for is an emitter // that does not exist. DebugGraph DebugCategory = "graph" // DebugTimeline is the turn's story in five lanes - recogniser, policy, // model, speech, background passes - projected by the server from the // events above. A client that wants to draw a turn subscribes to this // alone: the graph category carries every element's bookkeeping, tens of // events per second, and a client-side reducer that logs each inbound // event has a bounded log. DebugTimeline DebugCategory = "timeline" )
func DebugCategories ¶
func DebugCategories() []DebugCategory
DebugCategories is every category this implementation may emit.
type DebugEvent ¶
type DebugEvent struct {
Type string `json:"type"`
EventID string `json:"event_id"`
TimestampMS int64 `json:"timestamp_ms"`
Category DebugCategory `json:"category"`
Name string `json:"name"`
Phase string `json:"phase,omitempty"`
DurationMS float64 `json:"duration_ms,omitempty"`
CorrelationID string `json:"correlation_id,omitempty"`
Message string `json:"message,omitempty"`
Attributes map[string]any `json:"attributes,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
}
DebugEvent is one timestamped implementation trace entry. Attributes are safe operational metadata. Payload is present only when the client opted in to potentially sensitive content.
type DebugRequest ¶
type DebugRequest struct {
Enabled bool `json:"enabled"`
Categories []DebugCategory `json:"categories,omitempty"`
IncludePayloads bool `json:"include_payloads,omitempty"`
}
DebugRequest opts a developer client into timestamped implementation events. Payloads are separate because transcripts, tool arguments, and tool results may contain secrets; a client has to ask for them explicitly.
type DebugResponse ¶
type DebugResponse struct {
Enabled bool `json:"enabled"`
Categories []DebugCategory `json:"categories,omitempty"`
IncludePayloads bool `json:"include_payloads,omitempty"`
TimestampResolution string `json:"timestamp_resolution"`
// Inspection is an ephemeral, session-bound capability for the read-only
// management snapshot. It is returned only when session debugging was
// explicitly negotiated and the mounted runtime actually exports live
// graph evidence. The token belongs in a header, never a URL.
Inspection *InspectionAccess `json:"inspection,omitempty"`
}
DebugResponse states the trace configuration actually in force.
type Feature ¶
type Feature string
Feature is a negotiable capability.
const ( // FeatureVideoInput enables the two video events. FeatureVideoInput Feature = "video.input" // FeatureObservations enables the outbound observation event. FeatureObservations Feature = "observations" // FeatureComputerUse enables the computer.* tool namespace. It adds no // events at all; it is negotiated so a client can discover whether the // server will honour the namespace before declaring the tools. FeatureComputerUse Feature = "computer_use" // FeatureClientEffects enables server-authorized client/host-owned tool // execution. Negotiation alone grants nothing: every emitted call also // carries a short-lived receipt bound to its exact session, call, // declaration, arguments, and target. FeatureClientEffects Feature = "client.effects" )
func Features ¶
func Features() []Feature
Features is every capability this implementation can offer.
func ParseFeature ¶
ParseFeature validates a declared capability name.
type InspectionAccess ¶
type InspectionAccess struct {
SessionID string `json:"session_id"`
Path string `json:"path"`
Token string `json:"token"`
ExpiresAtMS int64 `json:"expires_at_ms"`
}
InspectionAccess grants one client read-only access to the exact graph mount backing its current session. SessionID remains human-operable and may be guessable; Token is the unguessable authority bound to it.
type Limits ¶
type Limits struct {
Format string `json:"format"`
FPSCap int `json:"fps_cap"`
MaxDimension int `json:"max_dimension"`
MaxFrameBytes int `json:"max_frame_bytes,omitempty"`
}
Limits are the server's declared bounds on video input. They are stated at negotiation so a client can conform rather than discover them by being rejected.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits are the shipped bounds: baseline JPEG, three frames a second, and 1280 on the long edge.
func (Limits) MaxTransportBytes ¶
MaxTransportBytes is the largest wire message a legal frame event occupies: the image base64-encoded, plus the envelope around it.
It exists because a transport that bounds an inbound message below this number does not reject an oversized frame, it drops the connection - the bound is enforced before any of the protocol's own validation runs, so the client gets a closed socket where it should have got an error it could act on. Every transport that carries this protocol sizes its own limit from here rather than from a constant that has to be kept in step by hand.
type ObservationAdded ¶
type ObservationAdded struct {
Type string `json:"type"`
EventID string `json:"event_id"`
ObservationID string `json:"observation_id"`
// Observer names which observer produced it: "video", "audio", or an
// opaque identifier.
Observer string `json:"observer"`
Source string `json:"source,omitempty"`
Text string `json:"text"`
ItemID string `json:"item_id,omitempty"`
// Authority is the provenance that decides what the text may do. Content
// an observer read off the world is data forever and can never become an
// instruction, and stating that on the wire lets a client show it.
Authority string `json:"authority"`
TimestampMS int64 `json:"timestamp_ms,omitempty"`
}
ObservationAdded reports one committed observation.
type Request ¶
type Request struct {
Version int `json:"version"`
Supports []Feature `json:"supports,omitempty"`
// Observers selects the session's perception, by observer name. Empty
// selects the binding's documented default set.
//
// It lives inside the extension object that already exists rather than
// becoming a fourth event, so the wire surface is unchanged: three events
// and two extended objects. And it is per session rather than per
// deployment because that is what makes the observer set a measurable
// factor - two sessions against one server can differ in exactly this and
// nothing else, which is the shape every cell of the matrix needs.
Observers []string `json:"observers,omitempty"`
// Debug opts this session into implementation traces. Nil means no trace
// and preserves the v1 wire surface for every existing client.
Debug *DebugRequest `json:"debug,omitempty"`
}
Request is what a client declares inside session.update.
type Response ¶
type Response struct {
Version int `json:"version"`
Enabled []Feature `json:"enabled"`
Video *Limits `json:"video,omitempty"`
// Observers is the perception this session will actually run. It is
// answered rather than echoed: a client that asked for an observer this
// deployment does not have gets a working session and a list it can read,
// exactly as it does for a capability it asked for and did not get.
Observers []string `json:"observers,omitempty"`
// AvailableObservers is everything this deployment could select from, so a
// client can choose without guessing at names.
AvailableObservers []string `json:"available_observers,omitempty"`
Debug *DebugResponse `json:"debug,omitempty"`
}
Response is what the server echoes inside session.updated.
A base-protocol server ignores the unknown key and never echoes it, so the client sees no enabled list and stays voice-only. A base-protocol client sends nothing and gets an ordinary session.
func Negotiate ¶
Negotiate resolves what a session will actually run.
A capability the server cannot provide is simply absent from the enabled list rather than being an error: a client that asked for video against a binding with no video observer gets a working voice session and can see that video is not enabled.
func NegotiateSession ¶
func NegotiateSession( request Request, supported []Feature, limits Limits, available []string, ) (Response, error)
NegotiateSession resolves capabilities and perception together.
Observers are resolved the same way capabilities are: what the deployment has and the client asked for is enabled, what it asked for and the deployment does not have is absent from the answer rather than fatal. A client that names nothing gets the binding's default set, which is every observer the deployment configured.
Asking for observers where there are none is fatal, not empty. A binding that offers no selectable perception - which is every binding whose model owns its own - cannot honour a selection, and answering one back would confirm a set that nothing will ever act on. The client would believe it had turned something on.
func NegotiateWithLimits ¶
NegotiateWithLimits resolves a session against a deployment's own video bounds rather than the shipped ones.
A deployment that carries larger frames than the default has to advertise the number it will actually accept: a client conforms to what negotiation told it, so a limit that lives anywhere other than the negotiated response is a limit the client discovers by being rejected.
type SourceState ¶
type SourceState string
SourceState is the lifecycle of a declared video source.
const ( SourceActive SourceState = "active" SourcePaused SourceState = "paused" SourceClosed SourceState = "closed" )
type ToolExtension ¶
type ToolExtension struct {
Confirm string `json:"confirm,omitempty"`
// Target names the declared context an action applies to - a browser
// context or a virtual display, never an ambient desktop by default.
Target string `json:"target,omitempty"`
// Background declares that the call may start even if user speech newer
// than the model prefix has arrived. The action plane still applies normal
// authority and confirmation checks.
Background bool `json:"background,omitempty"`
// ClientEffect commits a host-owned declaration to this ordinary function
// tool. It is inert unless client.effects was explicitly negotiated, and it
// never carries authority: only the server's emitted call extension does.
ClientEffect *ClientEffectDeclaration `json:"client_effect,omitempty"`
}
ToolExtension is the additive field on a tool definition.
There is no reversibility class. Every output - speech, text, tool call, click - is irreversible once emitted, so the runtime does not grade them; it applies one commit boundary to all of them. Confirm is a developer's declaration about consequence, not an inference the runtime makes, and it applies to any tool rather than only to computer use.
type VideoFrameAppend ¶
type VideoFrameAppend struct {
Type string `json:"type"`
Source string `json:"source"`
// Frame is base64 of the encoded image.
Frame string `json:"frame"`
TimestampMS int64 `json:"timestamp_ms,omitempty"`
}
VideoFrameAppend carries one frame.
func (VideoFrameAppend) Decode ¶
func (append VideoFrameAppend) Decode(limits Limits) ([]byte, error)
Decode validates the frame and returns its bytes.
The gate that decides which frames matter runs on the server, always. That is not a performance trade - it is the product boundary. Selective perception is what this system is for, and a client that had to implement pixel-change gating at a specific threshold is a client nobody writes.
type VideoSourceUpdate ¶
type VideoSourceUpdate struct {
Type string `json:"type"`
// Source is mandatory because screen and camera are simultaneously live
// and semantically different: you act on the screen, you observe the
// camera. "screen", "camera", or an opaque client-declared identifier.
Source string `json:"source"`
State SourceState `json:"state"`
Width int `json:"width"`
Height int `json:"height"`
}
VideoSourceUpdate declares or updates a source.
func (VideoSourceUpdate) Validate ¶
func (update VideoSourceUpdate) Validate() error
Validate rejects a declaration that could not ground a coordinate.