realtime/realtime.go (package realtime)
Source: sdks/go/realtime/realtime.go. Back to the Go SDK reference index.
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:
| Name | Type | Required | Description |
|---|---|---|---|
Type (type) | string | yes | Type of the event, for example transcript.delta or error. |
Event.Decode
Decode(v any) error
Decode unmarshals the full frame into v.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
v | any | yes | Pointer 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:
| Name | Type | Required | Description |
|---|---|---|---|
Code (code) | string | yes | Machine code of the error sent by the server. |
Message (message) | string | yes | Message 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
pcm | []byte | yes | Raw 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}.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
eventType | string | yes | Type of the event, for example session.update; it overrides a type key of fields. | |
fields | map[string]any | yes | Other 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
session | map[string]any | yes | Session 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
ctx | context.Context | yes | Context of the call: cancellation and deadline. | |
c | *eai.Client | yes | Configured eai client; its base URL, credentials and headers are used. | |
sessionID | string | yes | Identifier of a session created with Client.Realtime.CreateSession. | |
opts | ...eai.CallOption | no | Per 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error returned by Recv. |
Returns: bool. true when err is or wraps a *ServerError.