openai

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openai implements the OpenAI Realtime wire protocol boundary.

It preserves complete JSON messages, validates them against a pinned subset of OpenAI's official OpenAPI 3.1 specification, and classifies every event by protocol profile and direction. Unknown events can be retained for forward compatible proxying without being mistaken for conformant known events.

Index

Constants

This section is empty.

Variables

View Source
var SchemaBundle []byte

SchemaBundle is the pinned Realtime-only JSON Schema closure generated from OpenAI's official OpenAPI specification.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	Profile   Profile   `json:"profile"`
	Direction Direction `json:"direction"`
	Type      EventType `json:"type"`
	SchemaRef string    `json:"schema_ref"`
}

func Definitions

func Definitions() []Definition

func Lookup

func Lookup(profile Profile, direction Direction, eventType EventType) (Definition, bool)

type Direction

type Direction string
const (
	DirectionClient Direction = "client"
	DirectionServer Direction = "server"
)

type EventType

type EventType string
const (
	EventConversationCreated                              EventType = "conversation.created"
	EventConversationItemAdded                            EventType = "conversation.item.added"
	EventConversationItemCreate                           EventType = "conversation.item.create"
	EventConversationItemCreated                          EventType = "conversation.item.created"
	EventConversationItemDelete                           EventType = "conversation.item.delete"
	EventConversationItemDeleted                          EventType = "conversation.item.deleted"
	EventConversationItemDone                             EventType = "conversation.item.done"
	EventConversationItemInputAudioTranscriptionCompleted EventType = "conversation.item.input_audio_transcription.completed"
	EventConversationItemInputAudioTranscriptionDelta     EventType = "conversation.item.input_audio_transcription.delta"
	EventConversationItemInputAudioTranscriptionFailed    EventType = "conversation.item.input_audio_transcription.failed"
	EventConversationItemInputAudioTranscriptionSegment   EventType = "conversation.item.input_audio_transcription.segment"
	EventConversationItemRetrieve                         EventType = "conversation.item.retrieve"
	EventConversationItemRetrieved                        EventType = "conversation.item.retrieved"
	EventConversationItemTruncate                         EventType = "conversation.item.truncate"
	EventConversationItemTruncated                        EventType = "conversation.item.truncated"
	EventError                                            EventType = "error"
	EventInputAudioBufferAppend                           EventType = "input_audio_buffer.append"
	EventInputAudioBufferClear                            EventType = "input_audio_buffer.clear"
	EventInputAudioBufferCleared                          EventType = "input_audio_buffer.cleared"
	EventInputAudioBufferCommit                           EventType = "input_audio_buffer.commit"
	EventInputAudioBufferCommitted                        EventType = "input_audio_buffer.committed"
	EventInputAudioBufferDtmfEventReceived                EventType = "input_audio_buffer.dtmf_event_received"
	EventInputAudioBufferSpeechStarted                    EventType = "input_audio_buffer.speech_started"
	EventInputAudioBufferSpeechStopped                    EventType = "input_audio_buffer.speech_stopped"
	EventInputAudioBufferTimeoutTriggered                 EventType = "input_audio_buffer.timeout_triggered"
	EventMcpListToolsCompleted                            EventType = "mcp_list_tools.completed"
	EventMcpListToolsFailed                               EventType = "mcp_list_tools.failed"
	EventMcpListToolsInProgress                           EventType = "mcp_list_tools.in_progress"
	EventOutputAudioBufferClear                           EventType = "output_audio_buffer.clear"
	EventOutputAudioBufferCleared                         EventType = "output_audio_buffer.cleared"
	EventOutputAudioBufferStarted                         EventType = "output_audio_buffer.started"
	EventOutputAudioBufferStopped                         EventType = "output_audio_buffer.stopped"
	EventRateLimitsUpdated                                EventType = "rate_limits.updated"
	EventResponseCancel                                   EventType = "response.cancel"
	EventResponseContentPartAdded                         EventType = "response.content_part.added"
	EventResponseContentPartDone                          EventType = "response.content_part.done"
	EventResponseCreate                                   EventType = "response.create"
	EventResponseCreated                                  EventType = "response.created"
	EventResponseDone                                     EventType = "response.done"
	EventResponseFunctionCallArgumentsDelta               EventType = "response.function_call_arguments.delta"
	EventResponseFunctionCallArgumentsDone                EventType = "response.function_call_arguments.done"
	EventResponseMcpCallCompleted                         EventType = "response.mcp_call.completed"
	EventResponseMcpCallFailed                            EventType = "response.mcp_call.failed"
	EventResponseMcpCallInProgress                        EventType = "response.mcp_call.in_progress"
	EventResponseMcpCallArgumentsDelta                    EventType = "response.mcp_call_arguments.delta"
	EventResponseMcpCallArgumentsDone                     EventType = "response.mcp_call_arguments.done"
	EventResponseOutputAudioDelta                         EventType = "response.output_audio.delta"
	EventResponseOutputAudioDone                          EventType = "response.output_audio.done"
	EventResponseOutputAudioTranscriptDelta               EventType = "response.output_audio_transcript.delta"
	EventResponseOutputAudioTranscriptDone                EventType = "response.output_audio_transcript.done"
	EventResponseOutputItemAdded                          EventType = "response.output_item.added"
	EventResponseOutputItemDone                           EventType = "response.output_item.done"
	EventResponseOutputTextDelta                          EventType = "response.output_text.delta"
	EventResponseOutputTextDone                           EventType = "response.output_text.done"
	EventSessionClose                                     EventType = "session.close"
	EventSessionClosed                                    EventType = "session.closed"
	EventSessionCreated                                   EventType = "session.created"
	EventSessionInputAudioBufferAppend                    EventType = "session.input_audio_buffer.append"
	EventSessionInputTranscriptDelta                      EventType = "session.input_transcript.delta"
	EventSessionOutputAudioDelta                          EventType = "session.output_audio.delta"
	EventSessionOutputTranscriptDelta                     EventType = "session.output_transcript.delta"
	EventSessionUpdate                                    EventType = "session.update"
	EventSessionUpdated                                   EventType = "session.updated"
	EventTranscriptionSessionCreated                      EventType = "transcription_session.created"
	EventTranscriptionSessionUpdate                       EventType = "transcription_session.update"
	EventTranscriptionSessionUpdated                      EventType = "transcription_session.updated"
)

type Message

type Message struct {
	// contains filtered or unexported fields
}

func Decode

func Decode(data []byte) (Message, error)

func (Message) EventID

func (message Message) EventID() (string, bool)

func (Message) Raw

func (message Message) Raw() []byte

func (Message) Type

func (message Message) Type() EventType

func (Message) Unmarshal

func (message Message) Unmarshal(target any) error

type Profile

type Profile string
const (
	ProfileRealtime      Profile = "realtime"
	ProfileTranscription Profile = "transcription"
	ProfileTranslation   Profile = "translation"
	ProfileBeta          Profile = "beta"
)

type Validator

type Validator struct{}

Validator checks complete events against the pinned OpenAI Realtime schema.

The zero value is usable and every instance shares the process-wide compiled bundle. It remains a named type with a constructor because callers hold one per connection and a future per-connection option - a profile restriction, a strictness level - belongs on it rather than on a package-level function.

func NewValidator

func NewValidator() *Validator

func (*Validator) Validate

func (validator *Validator) Validate(
	profile Profile,
	direction Direction,
	message Message,
) error

func (*Validator) ValidateEncoded

func (validator *Validator) ValidateEncoded(
	profile Profile,
	direction Direction,
	raw []byte,
) error

ValidateEncoded checks one complete encoded event without decoding it twice.

It is the form a sender has, and the reason it exists is that the other form made the same bytes into JSON twice: Decode parsed the envelope and copied the payload so that Validate could parse the whole document again. A response.output_audio.delta is a base64 audio frame every twenty milliseconds for the life of every session, so the second parse was a per-frame copy and re-parse of the audio itself.

The type comes out of the same decoded document rather than a separate envelope pass, which is where Decode was reading it from anyway.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL