Versions in this module Expand all Collapse all v1 v1.0.0 Jul 18, 2026 Changes in this version + const GPT4oMiniRealtimePreview + const GPT4oMiniRealtimePreview20241217 + const GPT4oRealtimePreview + const GPT4oRealtimePreview20241001 + const GPT4oRealtimePreview20241217 + const OpenaiAPIURLv1 + const OpenaiRealtimeAPIURLv1 + var ErrUnsupportedMessageType = errors.New("unsupported message type") + func GenerateID(prefix string, length int) string + func HTTPDo[Q any, R any](ctx context.Context, url string, req *Q, opts ...HTTPOption) (*R, error) + func MarshalClientEvent(event ClientEvent) ([]byte, error) + func Permanent(err error) error + type APIType string + const APITypeAzure + const APITypeOpenAI + type AudioFormat string + const AudioFormatG711Alaw + const AudioFormatG711Ulaw + const AudioFormatPcm16 + type CachedTokensDetails struct + AudioTokens int + TextTokens int + type Client struct + func NewClient(authToken string) *Client + func NewClientWithConfig(config ClientConfig) *Client + func (c *Client) Connect(ctx context.Context, opts ...ConnectOption) (*Conn, error) + func (c *Client) CreateSession(ctx context.Context, req *CreateSessionRequest) (*CreateSessionResponse, error) + type ClientConfig struct + APIBaseURL string + APIType APIType + APIVersion string + BaseURL string + HTTPClient *http.Client + func DefaultAzureConfig(apiKey, baseURL string) ClientConfig + func DefaultConfig(authToken string) ClientConfig + func (c ClientConfig) String() string + type ClientEvent interface + ClientEventType func() ClientEventType + type ClientEventType string + const ClientEventTypeConversationItemCreate + const ClientEventTypeConversationItemDelete + const ClientEventTypeConversationItemTruncate + const ClientEventTypeInputAudioBufferAppend + const ClientEventTypeInputAudioBufferClear + const ClientEventTypeInputAudioBufferCommit + const ClientEventTypeResponseCancel + const ClientEventTypeResponseCreate + const ClientEventTypeSessionUpdate + type ClientSecret struct + ExpiresAt int64 + Value string + type ClientSession struct + InputAudioFormat AudioFormat + InputAudioTranscription *InputAudioTranscription + Instructions string + MaxOutputTokens IntOrInf + Modalities []Modality + OutputAudioFormat AudioFormat + Temperature *float32 + ToolChoice ToolChoiceInterface + Tools []Tool + TurnDetection *ClientTurnDetection + Voice Voice + type ClientTurnDetection struct + Type ClientTurnDetectionType + type ClientTurnDetectionType string + const ClientTurnDetectionTypeServerVad + type CoderWebSocketConn struct + func (c *CoderWebSocketConn) Close() error + func (c *CoderWebSocketConn) Ping(ctx context.Context) error + func (c *CoderWebSocketConn) ReadMessage(ctx context.Context) (MessageType, []byte, error) + func (c *CoderWebSocketConn) Response() *http.Response + func (c *CoderWebSocketConn) WriteMessage(ctx context.Context, messageType MessageType, data []byte) error + type CoderWebSocketDialer struct + func NewCoderWebSocketDialer(options CoderWebSocketOptions) *CoderWebSocketDialer + func (d *CoderWebSocketDialer) Dial(ctx context.Context, url string, header http.Header) (WebSocketConn, error) + type CoderWebSocketOptions struct + DialOptions *websocket.DialOptions + ReadLimit int64 + type Conn struct + func (c *Conn) Close() error + func (c *Conn) Ping(ctx context.Context) error + func (c *Conn) ReadMessage(ctx context.Context) (ServerEvent, error) + func (c *Conn) ReadMessageRaw(ctx context.Context) ([]byte, error) + func (c *Conn) SendMessage(ctx context.Context, msg ClientEvent) error + func (c *Conn) SendMessageRaw(ctx context.Context, data []byte) error + type ConnHandler struct + func NewConnHandler(ctx context.Context, conn *Conn, handlers ...ServerEventHandler) *ConnHandler + func (c *ConnHandler) Err() <-chan error + func (c *ConnHandler) Start() + type ConnectOption func(*connectOption) + func WithDialer(dialer WebSocketDialer) ConnectOption + func WithLogger(logger Logger) ConnectOption + func WithModel(model string) ConnectOption + type Conversation struct + ID string + Object string + type ConversationCreatedEvent struct + Conversation Conversation + type ConversationItemCreateEvent struct + Item MessageItem + PreviousItemID string + func (m ConversationItemCreateEvent) ClientEventType() ClientEventType + func (m ConversationItemCreateEvent) MarshalJSON() ([]byte, error) + type ConversationItemCreatedEvent struct + Item ResponseMessageItem + PreviousItemID string + type ConversationItemDeleteEvent struct + ItemID string + func (m ConversationItemDeleteEvent) ClientEventType() ClientEventType + func (m ConversationItemDeleteEvent) MarshalJSON() ([]byte, error) + type ConversationItemDeletedEvent struct + ItemID string + type ConversationItemInputAudioTranscriptionCompletedEvent struct + ContentIndex int + ItemID string + Transcript string + type ConversationItemInputAudioTranscriptionFailedEvent struct + ContentIndex int + Error Error + ItemID string + type ConversationItemTruncateEvent struct + AudioEndMs int + ContentIndex int + ItemID string + func (m ConversationItemTruncateEvent) ClientEventType() ClientEventType + func (m ConversationItemTruncateEvent) MarshalJSON() ([]byte, error) + type ConversationItemTruncatedEvent struct + AudioEndMs int + ContentIndex int + ItemID string + type CreateSessionRequest struct + Model string + type CreateSessionResponse struct + ClientSecret ClientSecret + type Error struct + Code string + EventID string + Message string + Param string + Type string + type ErrorEvent struct + Error Error + type EventBase struct + EventID string + type HTTPOption func(*httpOption) + func WithClient(client *http.Client) HTTPOption + func WithHeaders(headers http.Header) HTTPOption + func WithMethod(method string) HTTPOption + type InputAudioBufferAppendEvent struct + Audio string + func (m InputAudioBufferAppendEvent) ClientEventType() ClientEventType + func (m InputAudioBufferAppendEvent) MarshalJSON() ([]byte, error) + type InputAudioBufferClearEvent struct + func (m InputAudioBufferClearEvent) ClientEventType() ClientEventType + func (m InputAudioBufferClearEvent) MarshalJSON() ([]byte, error) + type InputAudioBufferClearedEvent struct + type InputAudioBufferCommitEvent struct + func (m InputAudioBufferCommitEvent) ClientEventType() ClientEventType + func (m InputAudioBufferCommitEvent) MarshalJSON() ([]byte, error) + type InputAudioBufferCommittedEvent struct + ItemID string + PreviousItemID string + type InputAudioBufferSpeechStartedEvent struct + AudioStartMs int64 + ItemID string + type InputAudioBufferSpeechStoppedEvent struct + AudioEndMs int64 + ItemID string + type InputAudioTranscription struct + Model string + type InputTokenDetails struct + AudioTokens int + CachedTokens int + CachedTokensDetails CachedTokensDetails + TextTokens int + type IntOrInf int + const Inf + func (m *IntOrInf) UnmarshalJSON(data []byte) error + func (m IntOrInf) IsInf() bool + func (m IntOrInf) MarshalJSON() ([]byte, error) + type ItemStatus string + const ItemStatusCompleted + const ItemStatusInProgress + const ItemStatusIncomplete + type Logger interface + Debugf func(format string, v ...any) + Errorf func(format string, v ...any) + Infof func(format string, v ...any) + Warnf func(format string, v ...any) + type MessageContentPart struct + Audio string + Text string + Transcript string + Type MessageContentType + type MessageContentType string + const MessageContentTypeAudio + const MessageContentTypeInputAudio + const MessageContentTypeInputText + const MessageContentTypeText + const MessageContentTypeTranscript + type MessageItem struct + Arguments string + CallID string + Content []MessageContentPart + ID string + Name string + Output string + Role MessageRole + Status ItemStatus + Type MessageItemType + type MessageItemType string + const MessageItemTypeFunctionCall + const MessageItemTypeFunctionCallOutput + const MessageItemTypeMessage + type MessageRole string + const MessageRoleAssistant + const MessageRoleSystem + const MessageRoleUser + type MessageType int + const MessageBinary + const MessageText + type Modality string + const ModalityAudio + const ModalityText + type NopLogger struct + func (l NopLogger) Debugf(_ string, _ ...any) + func (l NopLogger) Errorf(_ string, _ ...any) + func (l NopLogger) Infof(_ string, _ ...any) + func (l NopLogger) Warnf(_ string, _ ...any) + type OutputTokenDetails struct + AudioTokens int + TextTokens int + type PermanentError struct + Err error + func (e *PermanentError) Error() string + func (e *PermanentError) Is(target error) bool + func (e *PermanentError) Unwrap() error + type RateLimit struct + Limit int + Name string + Remaining int + ResetSeconds float64 + type RateLimitsUpdatedEvent struct + RateLimits []RateLimit + type Response struct + ID string + Object string + Output []ResponseMessageItem + Status ResponseStatus + StatusDetails any + Usage *Usage + type ResponseAudioDeltaEvent struct + ContentIndex int + Delta string + ItemID string + OutputIndex int + ResponseID string + type ResponseAudioDoneEvent struct + ContentIndex int + ItemID string + OutputIndex int + ResponseID string + type ResponseAudioTranscriptDeltaEvent struct + ContentIndex int + Delta string + ItemID string + OutputIndex int + ResponseID string + type ResponseAudioTranscriptDoneEvent struct + ContentIndex int + ItemID string + OutputIndex int + ResponseID string + Transcript string + type ResponseCancelEvent struct + ResponseID string + func (m ResponseCancelEvent) ClientEventType() ClientEventType + func (m ResponseCancelEvent) MarshalJSON() ([]byte, error) + type ResponseContentPartAddedEvent struct + ContentIndex int + ItemID string + OutputIndex int + Part MessageContentPart + ResponseID string + type ResponseContentPartDoneEvent struct + ContentIndex int + ItemID string + OutputIndex int + Part MessageContentPart + ResponseID string + type ResponseCreateEvent struct + Response ResponseCreateParams + func (m ResponseCreateEvent) ClientEventType() ClientEventType + func (m ResponseCreateEvent) MarshalJSON() ([]byte, error) + type ResponseCreateParams struct + Instructions string + MaxOutputTokens IntOrInf + Modalities []Modality + OutputAudioFormat AudioFormat + Temperature *float32 + ToolChoice ToolChoiceInterface + Tools []Tool + Voice Voice + type ResponseCreatedEvent struct + Response Response + type ResponseDoneEvent struct + Response Response + type ResponseFunctionCallArgumentsDeltaEvent struct + CallID string + Delta string + ItemID string + OutputIndex int + ResponseID string + type ResponseFunctionCallArgumentsDoneEvent struct + Arguments string + CallID string + ItemID string + Name string + OutputIndex int + ResponseID string + type ResponseMessageItem struct + Object string + type ResponseOutputItemAddedEvent struct + Item ResponseMessageItem + OutputIndex int + ResponseID string + type ResponseOutputItemDoneEvent struct + Item ResponseMessageItem + OutputIndex int + ResponseID string + type ResponseStatus string + const ResponseStatusCancelled + const ResponseStatusCompleted + const ResponseStatusFailed + const ResponseStatusInProgress + const ResponseStatusIncomplete + type ResponseTextDeltaEvent struct + ContentIndex int + Delta string + ItemID string + OutputIndex int + ResponseID string + type ResponseTextDoneEvent struct + ContentIndex int + ItemID string + OutputIndex int + ResponseID string + Text string + type ServerEvent interface + ServerEventType func() ServerEventType + func UnmarshalServerEvent(data []byte) (ServerEvent, error) + type ServerEventBase struct + EventID string + Type ServerEventType + func (m ServerEventBase) ServerEventType() ServerEventType + type ServerEventHandler func(ctx context.Context, event ServerEvent) + type ServerEventInterface interface + type ServerEventType string + const ServerEventTypeConversationCreated + const ServerEventTypeConversationItemCreated + const ServerEventTypeConversationItemDeleted + const ServerEventTypeConversationItemInputAudioTranscriptionCompleted + const ServerEventTypeConversationItemInputAudioTranscriptionFailed + const ServerEventTypeConversationItemTruncated + const ServerEventTypeError + const ServerEventTypeInputAudioBufferCleared + const ServerEventTypeInputAudioBufferCommitted + const ServerEventTypeInputAudioBufferSpeechStarted + const ServerEventTypeInputAudioBufferSpeechStopped + const ServerEventTypeRateLimitsUpdated + const ServerEventTypeResponseAudioDelta + const ServerEventTypeResponseAudioDone + const ServerEventTypeResponseAudioTranscriptDelta + const ServerEventTypeResponseAudioTranscriptDone + const ServerEventTypeResponseContentPartAdded + const ServerEventTypeResponseContentPartDone + const ServerEventTypeResponseCreated + const ServerEventTypeResponseDone + const ServerEventTypeResponseFunctionCallArgumentsDelta + const ServerEventTypeResponseFunctionCallArgumentsDone + const ServerEventTypeResponseOutputItemAdded + const ServerEventTypeResponseOutputItemDone + const ServerEventTypeResponseTextDelta + const ServerEventTypeResponseTextDone + const ServerEventTypeSessionCreated + const ServerEventTypeSessionUpdated + type ServerSession struct + ID string + InputAudioFormat AudioFormat + InputAudioTranscription *InputAudioTranscription + Instructions string + MaxOutputTokens IntOrInf + Modalities []Modality + Model string + Object string + OutputAudioFormat AudioFormat + Temperature *float32 + ToolChoice ServerToolChoice + Tools []Tool + TurnDetection *ServerTurnDetection + Voice Voice + type ServerToolChoice struct + Function ToolChoice + String ToolChoiceString + func (m *ServerToolChoice) IsFunction() bool + func (m *ServerToolChoice) UnmarshalJSON(data []byte) error + func (m ServerToolChoice) Get() ToolChoiceInterface + type ServerTurnDetection struct + Type ServerTurnDetectionType + type ServerTurnDetectionType string + const ServerTurnDetectionTypeNone + const ServerTurnDetectionTypeServerVad + type SessionCreatedEvent struct + Session ServerSession + type SessionUpdateEvent struct + Session ClientSession + func (m SessionUpdateEvent) ClientEventType() ClientEventType + func (m SessionUpdateEvent) MarshalJSON() ([]byte, error) + type SessionUpdatedEvent struct + Session ServerSession + type StdLogger struct + func (l StdLogger) Debugf(format string, v ...any) + func (l StdLogger) Errorf(format string, v ...any) + func (l StdLogger) Infof(format string, v ...any) + func (l StdLogger) Warnf(format string, v ...any) + type Tool struct + Description string + Name string + Parameters any + Type ToolType + type ToolChoice struct + Function ToolFunction + Type ToolType + func (t ToolChoice) ToolChoice() + type ToolChoiceInterface interface + ToolChoice func() + type ToolChoiceString string + const ToolChoiceAuto + const ToolChoiceNone + const ToolChoiceRequired + func (ToolChoiceString) ToolChoice() + type ToolFunction struct + Name string + type ToolType string + const ToolTypeFunction + type TurnDetectionParams struct + CreateResponse *bool + PrefixPaddingMs int + SilenceDurationMs int + Threshold float64 + type TurnDetectionType string + const TurnDetectionTypeNone + const TurnDetectionTypeServerVad + type Usage struct + InputTokenDetails InputTokenDetails + InputTokens int + OutputTokenDetails OutputTokenDetails + OutputTokens int + TotalTokens int + type Voice string + const VoiceAlloy + const VoiceAsh + const VoiceBallad + const VoiceCoral + const VoiceEcho + const VoiceSage + const VoiceShimmer + const VoiceVerse + type WebSocketConn interface + Close func() error + Ping func(ctx context.Context) error + ReadMessage func(ctx context.Context) (messageType MessageType, p []byte, err error) + Response func() *http.Response + WriteMessage func(ctx context.Context, messageType MessageType, data []byte) error + type WebSocketDialer interface + Dial func(ctx context.Context, url string, header http.Header) (WebSocketConn, error) + func DefaultDialer() WebSocketDialer