Skip to main content

realtime/realtime.go (package realtime)

Source: sdks/go/realtime/realtime.go. Back to the Go SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Class Event​

Event is one realtime event; Raw keeps the full frame.

Fields:

NameTypeRequiredDescription
Type (type)stringyesType of the event, for example transcript.delta or error.

Event.Decode​

Decode(v any) error

Decode unmarshals the full frame into v.

NameTypeDefaultRequiredDescription
vanyyesPointer the JSON of the full frame is decoded into.

Returns: error. Error of the call (a typed error of the SDK), nil on success.

Raises: error.

Class ServerError​

ServerError is an "error" event received from the server.

Fields:

NameTypeRequiredDescription
Code (code)stringyesMachine code of the error sent by the server.
Message (message)stringyesMessage of the error sent by the server.

ServerError.Error​

Error() string

Error formats the event as realtime: <code>: <message>.

This element takes no parameter.

Returns: string. The error text with code and message.

Class Conn​

Conn is an open realtime connection. Send is safe for concurrent use; call Recv from one goroutine.

Conn.AppendAudio​

AppendAudio(pcm []byte) error

AppendAudio sends input_audio.append with base64 encoded PCM audio.

NameTypeDefaultRequiredDescription
pcm[]byteyesRaw PCM audio bytes, sent base64 encoded in the audio field.

Returns: error. Error of the call (a typed error of the SDK), nil on success.

Raises: error.

Conn.Close​

Close() error

Close closes the connection.

This element takes no parameter.

Returns: error. Error of the call (a typed error of the SDK), nil on success.

Raises: error.

Conn.Recv​

Recv() (Event, error)

Recv reads the next event. An "error" event is returned as the event plus a *ServerError.

This element takes no parameter.

Returns: (Event, error). A Event: Event is one realtime event; Raw keeps the full frame. The error is a typed error of the SDK, nil on success.

Raises: error.

Conn.Send​

Send(eventType string, fields map[string]any) error

Send writes an event: fields are merged with {"type": eventType}.

NameTypeDefaultRequiredDescription
eventTypestringyesType of the event, for example session.update; it overrides a type key of fields.
fieldsmap[string]anyyesOther fields of the JSON frame.

Returns: error. Error of the call (a typed error of the SDK), nil on success.

Raises: error.

Conn.UpdateSession​

UpdateSession(session map[string]any) error

UpdateSession sends session.update.

NameTypeDefaultRequiredDescription
sessionmap[string]anyyesSession settings, sent in the session field of the event.

Returns: error. Error of the call (a typed error of the SDK), nil on success.

Raises: error.

Functions​

Dial​

Dial(ctx context.Context, c *eai.Client, sessionID string, opts ...eai.CallOption) (*Conn, error)

Dial requests a new single use ws_token for the session, then opens the WebSocket with it and the client credentials, tenancy, language and trace headers.

NameTypeDefaultRequiredDescription
ctxcontext.ContextyesContext of the call: cancellation and deadline.
c*eai.ClientyesConfigured eai client; its base URL, credentials and headers are used.
sessionIDstringyesIdentifier of a session created with Client.Realtime.CreateSession.
opts...eai.CallOptionnoPer call options (query, idempotency key, traceparent, headers).

Returns: (*Conn, error). A Conn: Conn is an open realtime connection. Send is safe for concurrent use; call Recv from one goroutine. The error is a typed error of the SDK, nil on success.

Raises: error.

IsServerError​

IsServerError(err error) bool

IsServerError reports an error event.

NameTypeDefaultRequiredDescription
errerroryesError returned by Recv.

Returns: bool. true when err is or wraps a *ServerError.