Documentation
¶
Overview ¶
Package openai provides OpenAI LLM provider integration.
Package openai provides OpenAI LLM provider integration.
Package openai provides OpenAI LLM provider integration.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI LLM provider integration.
Package openai provides OpenAI Realtime API streaming support.
Package openai provides OpenAI Realtime API streaming support.
Index ¶
- Constants
- Variables
- func ParseServerEvent(data []byte) (interface{}, error)
- func RealtimeStreamingCapabilities() providers.StreamingCapabilities
- type APIMode
- type ClientEvent
- type ConversationContent
- type ConversationItem
- type ConversationItemCreateEvent
- type ConversationItemCreatedEvent
- type ConversationItemInputAudioTranscriptionCompletedEvent
- type ConversationItemInputAudioTranscriptionFailedEvent
- type EmbeddingOption
- func WithEmbeddingAPIKey(key string) EmbeddingOption
- func WithEmbeddingBaseURL(url string) EmbeddingOption
- func WithEmbeddingDimensions(dims int) EmbeddingOption
- func WithEmbeddingHTTPClient(client *http.Client) EmbeddingOption
- func WithEmbeddingModel(model string) EmbeddingOption
- func WithEmbeddingPlatformAuth() EmbeddingOption
- func WithEmbeddingWiring(w providers.EmbeddingWiring) EmbeddingOption
- type EmbeddingProvider
- type ErrorDetail
- type ErrorEvent
- type InputAudioBufferAppendEvent
- type InputAudioBufferClearEvent
- type InputAudioBufferClearedEvent
- type InputAudioBufferCommitEvent
- type InputAudioBufferCommittedEvent
- type InputAudioBufferSpeechStartedEvent
- type InputAudioBufferSpeechStoppedEvent
- type Provider
- func NewProvider(id, model, baseURL string, defaults providers.ProviderDefaults, ...) *Provider
- func NewProviderFromConfig(cfg *ProviderConfig) *Provider
- func NewProviderWithConfig(id, model, baseURL string, defaults providers.ProviderDefaults, ...) *Provider
- func NewProviderWithCredential(id, model, baseURL string, defaults providers.ProviderDefaults, ...) *Provider
- func NewProviderWithCredentialAndConfig(id, model, baseURL string, defaults providers.ProviderDefaults, ...) *Provider
- func (p *Provider) CalculateCost(tokensIn, tokensOut, cachedTokens int) types.CostInfo
- func (p *Provider) CreateStreamSession(ctx context.Context, req *providers.StreamingInputConfig) (providers.StreamInputSession, error)
- func (p *Provider) EmitsLateInputTranscription() bool
- func (p *Provider) GetMultimodalCapabilities() providers.MultimodalCapabilities
- func (p *Provider) GetStreamingCapabilities() providers.StreamingCapabilities
- func (p *Provider) MaxContextTokens() int
- func (p *Provider) Model() string
- func (p *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
- func (p *Provider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)
- func (p *Provider) SendableMultimodalCapabilities() providers.MultimodalCapabilities
- func (p *Provider) SupportsPromptCaching() bool
- func (p *Provider) SupportsStreamHistory() bool
- func (p *Provider) SupportsStreamInput() []string
- func (p *Provider) SupportsStreaming() bool
- func (p *Provider) WithMediaSettings(m providers.MediaSettings) providers.Provider
- type ProviderConfig
- type RateLimit
- type RateLimitsUpdatedEvent
- type RealtimeAudioConfig
- type RealtimeAudioFormat
- type RealtimeAudioInput
- type RealtimeAudioOutput
- type RealtimeSession
- func (s *RealtimeSession) AddContextNote(_ context.Context, text string) error
- func (s *RealtimeSession) CancelResponse() error
- func (s *RealtimeSession) ClearAudioBuffer() error
- func (s *RealtimeSession) Close() error
- func (s *RealtimeSession) CommitAudioBuffer() error
- func (s *RealtimeSession) Config() *RealtimeSessionConfig
- func (s *RealtimeSession) Done() <-chan struct{}
- func (s *RealtimeSession) EndInput()
- func (s *RealtimeSession) Error() error
- func (s *RealtimeSession) ForgetTurn(_ context.Context, inputID string) error
- func (s *RealtimeSession) HeldAudioDropped(generation int64)
- func (s *RealtimeSession) HeldAudioInterrupted(generation int64) bool
- func (s *RealtimeSession) HoldPlayout()
- func (s *RealtimeSession) InterruptResponse(_ context.Context, generation int64) error
- func (s *RealtimeSession) OutputAudio() (providers.OutputAudio, bool)
- func (s *RealtimeSession) ReleaseAudio(chunk *providers.StreamChunk) bool
- func (s *RealtimeSession) SeedHistory(_ context.Context, messages []types.Message) error
- func (s *RealtimeSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error
- func (s *RealtimeSession) SendSystemContext(ctx context.Context, text string) error
- func (s *RealtimeSession) SendText(ctx context.Context, text string) error
- func (s *RealtimeSession) SendToolResponse(ctx context.Context, toolCallID, result string) error
- func (s *RealtimeSession) SendToolResponses(ctx context.Context, responses []providers.ToolResponse) error
- func (s *RealtimeSession) SpeakOutOfBand(ctx context.Context, text string) (providers.OutOfBandSpeech, error)
- func (s *RealtimeSession) SupportsToolResponseParts() bool
- func (s *RealtimeSession) TriggerResponse(config *ResponseConfig) error
- func (s *RealtimeSession) UpdateTools(ctx context.Context, tools []providers.StreamingToolDefinition) error
- type RealtimeSessionConfig
- type RealtimeToolDef
- type RealtimeToolDefinition
- type RealtimeWebSocket
- func (ws *RealtimeWebSocket) Close() error
- func (ws *RealtimeWebSocket) Conn() *streaming.Conn
- func (ws *RealtimeWebSocket) ConnectWithRetry(ctx context.Context) error
- func (ws *RealtimeWebSocket) IsClosed() bool
- func (ws *RealtimeWebSocket) Receive(ctx context.Context) ([]byte, error)
- func (ws *RealtimeWebSocket) ReceiveLoop(ctx context.Context, msgCh chan<- []byte) error
- func (ws *RealtimeWebSocket) Send(msg interface{}) error
- func (ws *RealtimeWebSocket) StartHeartbeat(ctx context.Context, interval time.Duration)
- type ResponseAudioDeltaEvent
- type ResponseAudioDoneEvent
- type ResponseAudioTranscriptDeltaEvent
- type ResponseAudioTranscriptDoneEvent
- type ResponseCancelEvent
- type ResponseConfig
- type ResponseContentPartAddedEvent
- type ResponseContentPartDoneEvent
- type ResponseCreateEvent
- type ResponseCreatedEvent
- type ResponseDoneEvent
- type ResponseFunctionCallArgumentsDeltaEvent
- type ResponseFunctionCallArgumentsDoneEvent
- type ResponseInfo
- type ResponseOutputItemAddedEvent
- type ResponseOutputItemDoneEvent
- type ResponseTextDeltaEvent
- type ResponseTextDoneEvent
- type ServerEvent
- type SessionConfig
- type SessionCreatedEvent
- type SessionInfo
- type SessionUpdateEvent
- type SessionUpdatedEvent
- type ToolProvider
- func (p *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (providers.ProviderTools, error)
- func (p *ToolProvider) PredictStreamWithTools(ctx context.Context, req providers.PredictionRequest, tools any, ...) (<-chan providers.StreamChunk, error)
- func (p *ToolProvider) PredictWithTools(ctx context.Context, req providers.PredictionRequest, ...) (providers.PredictionResponse, []types.MessageToolCall, error)
- func (p *ToolProvider) WithMediaSettings(m providers.MediaSettings) providers.Provider
- type TranscriptionConfig
- type TurnDetectionConfig
- type UsageInfo
Constants ¶
const ( // DefaultEmbeddingModel is the default model for embeddings DefaultEmbeddingModel = "text-embedding-3-small" // EmbeddingModelAda002 is the legacy ada-002 model EmbeddingModelAda002 = "text-embedding-ada-002" // EmbeddingModel3Small is the newer small model with better performance EmbeddingModel3Small = "text-embedding-3-small" // EmbeddingModel3Large is the large model with highest quality EmbeddingModel3Large = "text-embedding-3-large" )
Embedding model constants
const ( APIModeResponses = "responses" // New Responses API (v1/responses) APIModeCompletions = "completions" // Legacy Chat Completions API (v1/chat/completions) )
API mode constants
const ( // RealtimeAPIEndpoint is the base WebSocket endpoint for OpenAI Realtime API. RealtimeAPIEndpoint = "wss://api.openai.com/v1/realtime" // RealtimeBetaHeader is required for the Realtime API. RealtimeBetaHeader = "realtime=v1" // Default audio configuration for OpenAI Realtime API. // OpenAI Realtime uses 24kHz 16-bit PCM mono audio. DefaultRealtimeSampleRate = 24000 DefaultRealtimeChannels = 1 DefaultRealtimeBitDepth = 16 )
Realtime API constants
Variables ¶
var ErrConnectionLost = errors.New("websocket connection lost")
ErrConnectionLost is the error type emitted on the Response channel when the WebSocket connection drops mid-session (network failure, heartbeat timeout, server-initiated close with a non-graceful code). Callers can check for this with errors.Is to distinguish recoverable connection loss from clean session termination or server-side errors.
Functions ¶
func ParseServerEvent ¶
ParseServerEvent parses a raw JSON message into the appropriate event type.
func RealtimeStreamingCapabilities ¶
func RealtimeStreamingCapabilities() providers.StreamingCapabilities
RealtimeStreamingCapabilities returns the streaming capabilities for OpenAI Realtime API.
Types ¶
type ClientEvent ¶
ClientEvent is the base structure for all client events.
type ConversationContent ¶
type ConversationContent struct {
Type string `json:"type"` // "input_text", "input_audio", "input_image", "text", "audio"
Text string `json:"text,omitempty"`
Audio string `json:"audio,omitempty"` // Base64-encoded
Transcript string `json:"transcript,omitempty"` // For audio content
ImageURL string `json:"image_url,omitempty"` // For input_image: a base64 data URI
}
ConversationContent represents content within a conversation item.
type ConversationItem ¶
type ConversationItem struct {
ID string `json:"id,omitempty"`
Type string `json:"type"` // "message", "function_call", "function_call_output"
Status string `json:"status,omitempty"`
Role string `json:"role,omitempty"` // "user", "assistant", "system"
Content []ConversationContent `json:"content,omitempty"`
CallID string `json:"call_id,omitempty"` // For function_call_output
Output string `json:"output,omitempty"` // For function_call_output
Name string `json:"name,omitempty"` // For function_call
Arguments string `json:"arguments,omitempty"` // For function_call
}
ConversationItem represents an item in the conversation.
type ConversationItemCreateEvent ¶
type ConversationItemCreateEvent struct {
ClientEvent
PreviousItemID string `json:"previous_item_id,omitempty"`
Item ConversationItem `json:"item"`
}
ConversationItemCreateEvent adds an item to the conversation.
type ConversationItemCreatedEvent ¶
type ConversationItemCreatedEvent struct {
ServerEvent
PreviousItemID string `json:"previous_item_id"`
Item ConversationItem `json:"item"`
}
ConversationItemCreatedEvent confirms an item was added.
type ConversationItemInputAudioTranscriptionCompletedEvent ¶
type ConversationItemInputAudioTranscriptionCompletedEvent struct {
ServerEvent
ItemID string `json:"item_id"`
ContentIndex int `json:"content_index"`
Transcript string `json:"transcript"`
}
ConversationItemInputAudioTranscriptionCompletedEvent provides transcription.
type ConversationItemInputAudioTranscriptionFailedEvent ¶
type ConversationItemInputAudioTranscriptionFailedEvent struct {
ServerEvent
ItemID string `json:"item_id"`
ContentIndex int `json:"content_index"`
Error ErrorDetail `json:"error"`
}
ConversationItemInputAudioTranscriptionFailedEvent indicates transcription failed.
type EmbeddingOption ¶
type EmbeddingOption func(*EmbeddingProvider)
EmbeddingOption configures the EmbeddingProvider.
func WithEmbeddingAPIKey ¶
func WithEmbeddingAPIKey(key string) EmbeddingOption
WithEmbeddingAPIKey sets the API key explicitly.
func WithEmbeddingBaseURL ¶
func WithEmbeddingBaseURL(url string) EmbeddingOption
WithEmbeddingBaseURL sets a custom base URL (for Azure or proxies).
func WithEmbeddingDimensions ¶ added in v2.7.0
func WithEmbeddingDimensions(dims int) EmbeddingOption
WithEmbeddingDimensions sets the output size. It is sent as the request's dimensions, which text-embedding-3-* honors by shortening the vector; a fixed-size model rejects it, which is the right outcome for a size it cannot produce.
func WithEmbeddingHTTPClient ¶
func WithEmbeddingHTTPClient(client *http.Client) EmbeddingOption
WithEmbeddingHTTPClient sets a custom HTTP client.
func WithEmbeddingModel ¶
func WithEmbeddingModel(model string) EmbeddingOption
WithEmbeddingModel sets the embedding model.
func WithEmbeddingPlatformAuth ¶
func WithEmbeddingPlatformAuth() EmbeddingOption
WithEmbeddingPlatformAuth marks the provider as authenticated by its HTTP client's transport (hyperscaler platform auth), so the empty-API-key guard in NewEmbeddingProvider is skipped.
func WithEmbeddingWiring ¶ added in v2.7.0
func WithEmbeddingWiring(w providers.EmbeddingWiring) EmbeddingOption
WithEmbeddingWiring applies the transport-derived settings the factory resolved, including a declared dimensions.
type EmbeddingProvider ¶
type EmbeddingProvider struct {
*providers.BaseEmbeddingProvider
// contains filtered or unexported fields
}
EmbeddingProvider implements embedding generation via OpenAI API.
func NewEmbeddingProvider ¶
func NewEmbeddingProvider(opts ...EmbeddingOption) (*EmbeddingProvider, error)
NewEmbeddingProvider creates an OpenAI embedding provider.
func (*EmbeddingProvider) Embed ¶
func (p *EmbeddingProvider) Embed( ctx context.Context, req providers.EmbeddingRequest, ) (providers.EmbeddingResponse, error)
Embed generates embeddings for the given texts.
func (*EmbeddingProvider) EstimateCost ¶
func (p *EmbeddingProvider) EstimateCost(tokens int) float64
EstimateCost estimates the cost for embedding the given number of tokens.
type ErrorDetail ¶
type ErrorDetail struct {
Type string `json:"type"`
Code string `json:"code"`
Message string `json:"message"`
Param string `json:"param,omitempty"`
EventID string `json:"event_id,omitempty"`
}
ErrorDetail contains error information.
type ErrorEvent ¶
type ErrorEvent struct {
ServerEvent
Error ErrorDetail `json:"error"`
}
ErrorEvent indicates an error occurred.
type InputAudioBufferAppendEvent ¶
type InputAudioBufferAppendEvent struct {
ClientEvent
Audio string `json:"audio"` // Base64-encoded audio data
}
InputAudioBufferAppendEvent appends audio to the input buffer.
type InputAudioBufferClearEvent ¶
type InputAudioBufferClearEvent struct {
ClientEvent
}
InputAudioBufferClearEvent clears the audio buffer.
type InputAudioBufferClearedEvent ¶
type InputAudioBufferClearedEvent struct {
ServerEvent
}
InputAudioBufferClearedEvent confirms audio buffer was cleared.
type InputAudioBufferCommitEvent ¶
type InputAudioBufferCommitEvent struct {
ClientEvent
}
InputAudioBufferCommitEvent commits the audio buffer for processing.
type InputAudioBufferCommittedEvent ¶
type InputAudioBufferCommittedEvent struct {
ServerEvent
PreviousItemID string `json:"previous_item_id"`
ItemID string `json:"item_id"`
}
InputAudioBufferCommittedEvent confirms audio buffer was committed.
type InputAudioBufferSpeechStartedEvent ¶
type InputAudioBufferSpeechStartedEvent struct {
ServerEvent
AudioStartMs int `json:"audio_start_ms"`
ItemID string `json:"item_id"`
}
InputAudioBufferSpeechStartedEvent indicates speech was detected.
type InputAudioBufferSpeechStoppedEvent ¶
type InputAudioBufferSpeechStoppedEvent struct {
ServerEvent
AudioEndMs int `json:"audio_end_ms"`
ItemID string `json:"item_id"`
}
InputAudioBufferSpeechStoppedEvent indicates speech ended.
type Provider ¶
type Provider struct {
providers.BaseProvider
// contains filtered or unexported fields
}
Provider implements the Provider interface for OpenAI
func NewProvider ¶
func NewProvider(id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool) *Provider
NewProvider creates a new OpenAI provider
func NewProviderFromConfig ¶
func NewProviderFromConfig(cfg *ProviderConfig) *Provider
NewProviderFromConfig creates a provider from a full config struct.
func NewProviderWithConfig ¶
func NewProviderWithConfig( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, additionalConfig map[string]any, ) *Provider
NewProviderWithConfig creates a new OpenAI provider with additional configuration
func NewProviderWithCredential ¶
func NewProviderWithCredential( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, cred providers.Credential, platform string, platformConfig *providers.PlatformConfig, ) *Provider
NewProviderWithCredential creates a new OpenAI provider with explicit credential.
func NewProviderWithCredentialAndConfig ¶
func NewProviderWithCredentialAndConfig( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, cred providers.Credential, additionalConfig map[string]any, platform string, platformConfig *providers.PlatformConfig, ) *Provider
NewProviderWithCredentialAndConfig creates a new OpenAI provider with explicit credential and config.
func (*Provider) CalculateCost ¶
CalculateCost calculates detailed cost breakdown including optional cached tokens. Thin wrapper over costFromUsage, kept for the Provider interface's legacy signature (cachedTokens here means cache reads only — callers that also have a reasoning-token count, e.g. wire openAIUsage, should call costFromUsage directly instead so reasoning tokens aren't dropped).
func (*Provider) CreateStreamSession ¶
func (p *Provider) CreateStreamSession( ctx context.Context, req *providers.StreamingInputConfig, ) (providers.StreamInputSession, error)
CreateStreamSession creates a new bidirectional streaming session with OpenAI Realtime API.
The session supports real-time audio input/output with the following features: - Bidirectional audio streaming (send and receive audio simultaneously) - Server-side voice activity detection (VAD) for automatic turn detection - Function/tool calling during the streaming session - Input and output audio transcription
Audio Format: OpenAI Realtime API uses 24kHz 16-bit PCM mono audio by default. The session automatically handles base64 encoding/decoding of audio data.
Concurrency bounds: If the provider has `stream_max_concurrent` configured, this call will block until a slot is available (respecting the caller's ctx) or return a rejection error recorded on promptkit_stream_concurrency_rejections_total. The slot is released when the session ends — whether via Close() or via the underlying Done() channel (e.g. context cancellation). This makes Realtime sessions subject to the same Phase 3 back-pressure as SSE streams.
Example usage:
session, err := provider.CreateStreamSession(ctx, &providers.StreamingInputConfig{
Config: types.StreamingMediaConfig{
Type: types.ContentTypeAudio,
SampleRate: 24000,
Encoding: "pcm16",
Channels: 1,
},
SystemInstruction: "You are a helpful assistant.",
})
func (*Provider) EmitsLateInputTranscription ¶
EmitsLateInputTranscription reports that OpenAI Realtime delivers the user's input transcription asynchronously (Whisper), after the assistant reply has begun — so the pipeline should reorder the transcript when transcription is enabled. Implements providers.LateInputTranscriber.
func (*Provider) GetMultimodalCapabilities ¶
func (p *Provider) GetMultimodalCapabilities() providers.MultimodalCapabilities
GetMultimodalCapabilities returns OpenAI's multimodal capabilities
func (*Provider) GetStreamingCapabilities ¶
func (p *Provider) GetStreamingCapabilities() providers.StreamingCapabilities
GetStreamingCapabilities returns detailed information about OpenAI's streaming support.
func (*Provider) MaxContextTokens ¶ added in v2.17.0
MaxContextTokens returns the model's context window in tokens: the additional_config.context_window override, else the built-in table, else 0 (unknown), which makes the compactor use its default budget.
func (*Provider) Predict ¶
func (p *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
Predict runs predictOnce, retrying without any sampling parameter the API rejects for this model (providers.BaseProvider.RetryRejectedParams), and on the Responses API if Chat Completions rejects the model as Responses-only.
func (*Provider) PredictStream ¶
func (p *Provider) PredictStream( ctx context.Context, req providers.PredictionRequest, ) (<-chan providers.StreamChunk, error)
PredictStream runs predictStreamOnce, retrying without any sampling parameter the API rejects for this model, and on the Responses API if Chat Completions rejects the model as Responses-only.
func (*Provider) SendableMultimodalCapabilities ¶ added in v2.17.0
func (p *Provider) SendableMultimodalCapabilities() providers.MultimodalCapabilities
SendableMultimodalCapabilities returns what the adapter sends: images always, whatever the config declares, and audio only where convertContentPartToOpenAI accepts it (an audio model on the Chat Completions API). Audio is gated by the adapter itself, so a config that leaves audio out of its capabilities makes the adapter refuse it too.
func (*Provider) SupportsPromptCaching ¶
SupportsPromptCaching reports that OpenAI applies automatic prompt caching (no cache_control needed) for prompts above its minimum, so the pipeline's caching-stall warning applies here. Caching engages only when the request prefix is stable across rounds (see the deterministic tool-order fix).
func (*Provider) SupportsStreamHistory ¶ added in v2.19.0
SupportsStreamHistory reports that OpenAI Realtime sessions take prior conversation (see RealtimeSession.SeedHistory).
func (*Provider) SupportsStreamInput ¶
SupportsStreamInput returns the media types supported for streaming input: audio when the platform can open a realtime session and the model is a realtime model (isRealtimeModel), else none.
func (*Provider) SupportsStreaming ¶
SupportsStreaming returns false for audio models on the Completions API because the Chat Completions streaming delta does not include audio data. Audio models only support non-streaming responses (Predict) or the Realtime API for bidirectional audio.
func (*Provider) WithMediaSettings ¶ added in v2.13.0
func (p *Provider) WithMediaSettings(m providers.MediaSettings) providers.Provider
WithMediaSettings returns a view of p that uses m's media settings and shares everything else (providers.MediaScoped).
type ProviderConfig ¶
type ProviderConfig struct {
ID string
Model string
BaseURL string
Defaults providers.ProviderDefaults
IncludeRawOutput bool
Credential providers.Credential
AdditionalConfig map[string]any
Platform string
PlatformConfig *providers.PlatformConfig
UnsupportedParams []string
Capabilities []string
}
ProviderConfig holds all configuration for creating an OpenAI provider. Used by CreateProviderFromSpec and other callers that need full control.
type RateLimit ¶
type RateLimit struct {
Name string `json:"name"`
Limit int `json:"limit"`
Remaining int `json:"remaining"`
ResetSeconds float64 `json:"reset_seconds"`
}
RateLimit contains rate limit details.
type RateLimitsUpdatedEvent ¶
type RateLimitsUpdatedEvent struct {
ServerEvent
RateLimits []RateLimit `json:"rate_limits"`
}
RateLimitsUpdatedEvent provides rate limit information.
type RealtimeAudioConfig ¶
type RealtimeAudioConfig struct {
Input *RealtimeAudioInput `json:"input,omitempty"`
Output *RealtimeAudioOutput `json:"output,omitempty"`
}
RealtimeAudioConfig groups the input and output audio configuration in the GA schema. Either side may be nil to leave server defaults in place.
type RealtimeAudioFormat ¶
RealtimeAudioFormat is the GA-shape codec descriptor. For PCM, type is "audio/pcm" and rate is the sample rate in Hz (24000 for gpt-realtime).
type RealtimeAudioInput ¶
type RealtimeAudioInput struct {
Format *RealtimeAudioFormat `json:"format,omitempty"`
TurnDetection *TurnDetectionConfig `json:"turn_detection"`
Transcription *TranscriptionConfig `json:"transcription,omitempty"`
}
RealtimeAudioInput configures the user-input side of the audio stream. TurnDetection uses a pointer-without-omitempty so the caller can send explicit null to disable server VAD (manual turn control).
type RealtimeAudioOutput ¶
type RealtimeAudioOutput struct {
Format *RealtimeAudioFormat `json:"format,omitempty"`
Voice string `json:"voice,omitempty"`
Speed float64 `json:"speed,omitempty"`
}
RealtimeAudioOutput configures the model-output side of the audio stream.
type RealtimeSession ¶
type RealtimeSession struct {
// StreamPump provides Response(), BargeIn(), and the barge-in audio drop,
// shared identically across providers. Embedded so those methods promote.
*providers.StreamPump
// contains filtered or unexported fields
}
RealtimeSession implements StreamInputSession for OpenAI Realtime API.
func NewRealtimeSession ¶
func NewRealtimeSession(ctx context.Context, apiKey string, config *RealtimeSessionConfig) (*RealtimeSession, error)
NewRealtimeSession creates a new OpenAI Realtime streaming session.
func (*RealtimeSession) AddContextNote ¶ added in v2.22.0
func (s *RealtimeSession) AddContextNote(_ context.Context, text string) error
AddContextNote implements providers.ContextNoter: it adds text to the conversation as a system message (conversation.item.create), which the model reads with the turns that follow. It asks for no response, so the model says nothing to it.
func (*RealtimeSession) CancelResponse ¶
func (s *RealtimeSession) CancelResponse() error
CancelResponse cancels the reply in progress, naming it by its response ID, so a response outside the conversation (SpeakOutOfBand) running beside it is never canceled. With no reply in progress it sends nothing.
func (*RealtimeSession) ClearAudioBuffer ¶
func (s *RealtimeSession) ClearAudioBuffer() error
ClearAudioBuffer clears the current audio buffer.
func (*RealtimeSession) CommitAudioBuffer ¶
func (s *RealtimeSession) CommitAudioBuffer() error
CommitAudioBuffer commits the current audio buffer for processing.
func (*RealtimeSession) Config ¶
func (s *RealtimeSession) Config() *RealtimeSessionConfig
Config returns the session configuration. Callers can use this to create a new session with the same settings after a connection loss:
if errors.Is(session.Error(), openai.ErrConnectionLost) {
newSession, _ := openai.NewRealtimeSession(ctx, apiKey, session.Config())
}
Note: server-side conversation state is lost on reconnection — this only preserves the client-side configuration.
func (*RealtimeSession) Done ¶
func (s *RealtimeSession) Done() <-chan struct{}
Done returns a channel that's closed when the session ends.
func (*RealtimeSession) EndInput ¶
func (s *RealtimeSession) EndInput()
EndInput signals the end of user input.
In server_vad mode the server auto-commits when it detects end-of-speech in the audio buffer and (with create_response: true) auto-creates a response. Sending manual input_audio_buffer.commit + response.create from the client races with that auto-handling and causes the server to reject audio chunks with a cryptic "Invalid 'audio'... got an invalid value" error (verified via integration bisection). Callers that want server_vad behavior must include trailing silence in the streamed audio so the VAD can detect end-of-speech — pumpTTSChunks already does this via streamSilenceTail.
In manual turn-control mode (TurnDetection == nil, i.e. vad_disabled), the client owns turn boundaries: commit the buffer and trigger a response.
func (*RealtimeSession) Error ¶
func (s *RealtimeSession) Error() error
Error returns any error that occurred during the session.
func (*RealtimeSession) ForgetTurn ¶ added in v2.22.0
func (s *RealtimeSession) ForgetTurn(_ context.Context, inputID string) error
ForgetTurn implements providers.TurnForgetter: it deletes, with conversation.item.delete, the caller's audio item inputID and the items of the response that answers it, so the model no longer has the turn in its context. The response that answers an item is one created while that item was the caller's latest, so a turn the caller started since is not touched.
The caller's item is deleted at once. Its reply, when completed, is deleted at once too; one in progress, or not created yet, when its response.done arrives. When the reply completed with tool calls, the reply to their results is the one deleted, and the tool round is left: the conversation keeps each call with its result. An item is deleted once; a delete the server rejects because the item is gone is not a session error, and any other rejection is. A delete that could not be sent is reported and may be retried.
func (*RealtimeSession) HeldAudioDropped ¶ added in v2.22.0
func (s *RealtimeSession) HeldAudioDropped(generation int64)
HeldAudioDropped implements providers.PlayoutHolder: nothing of a reply is held any longer, so none of it waits for the caller.
func (*RealtimeSession) HeldAudioInterrupted ¶ added in v2.22.0
func (s *RealtimeSession) HeldAudioInterrupted(generation int64) bool
HeldAudioInterrupted implements providers.PlayoutHolder: whether the caller began speaking over audio of response generation (any, for 0) the pipeline still held, since it dropped what it held of it.
func (*RealtimeSession) HoldPlayout ¶ added in v2.22.0
func (s *RealtimeSession) HoldPlayout()
HoldPlayout implements providers.PlayoutHolder: from now on a reply's audio counts toward the playout estimate only as the pipeline releases it to the caller (ReleaseAudio), not as it arrives.
func (*RealtimeSession) InterruptResponse ¶ added in v2.22.0
func (s *RealtimeSession) InterruptResponse(_ context.Context, generation int64) error
InterruptResponse stops the reply on the caller's behalf (providers.ResponseInterrupter), as a barge-in does: a response in progress is canceled with response.cancel and its audio still queued or arriving is dropped, and each audio item the caller had not fully heard is cut to what they heard with conversation.item.truncate (the playout estimate). The canceled response's response.done still ends the turn. No Interrupted chunk is sent: the caller reports the interruption.
It acts on the response numbered generation (StreamChunk.Generation) only. A response not created yet is canceled as soon as it is created, unless the caller starts a new turn first (speech_started, or a response.create the client sends, text or tool results). A response that has completed while a later one began is left alone, and so is the later one. Generation 0 is the response in progress, or the next one.
A cancel the server rejects because the response ended first is logged, not reported as a session error.
func (*RealtimeSession) OutputAudio ¶ added in v2.22.0
func (s *RealtimeSession) OutputAudio() (providers.OutputAudio, bool)
OutputAudio implements providers.OutputAudioReporter: the session's voice, at the Realtime PCM16 rate. ok is false for a text-only session, and for output in a format other than PCM16 (g711), which the pipeline cannot match.
func (*RealtimeSession) ReleaseAudio ¶ added in v2.22.0
func (s *RealtimeSession) ReleaseAudio(chunk *providers.StreamChunk) bool
ReleaseAudio implements providers.PlayoutHolder: chunk's audio, as the session delivered it, reaches the caller now, so it plays from now on, unless the caller already spoke over the held audio.
func (*RealtimeSession) SeedHistory ¶ added in v2.19.0
SeedHistory adds the prior conversation as conversation.item.create events, one per user or assistant message with text, without response.create.
func (*RealtimeSession) SendChunk ¶
func (s *RealtimeSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error
SendChunk sends an audio chunk to the server.
func (*RealtimeSession) SendSystemContext ¶
func (s *RealtimeSession) SendSystemContext(ctx context.Context, text string) error
SendSystemContext sends a partial session.update that only modifies instructions, leaving codec/voice/VAD untouched. The GA API merges partial session.update events; type is included because GA requires it on every session.update.
func (*RealtimeSession) SendText ¶
func (s *RealtimeSession) SendText(ctx context.Context, text string) error
SendText sends a text message and triggers a response.
func (*RealtimeSession) SendToolResponse ¶
func (s *RealtimeSession) SendToolResponse(ctx context.Context, toolCallID, result string) error
SendToolResponse sends the result of a tool execution back to the model.
func (*RealtimeSession) SendToolResponses ¶
func (s *RealtimeSession) SendToolResponses(ctx context.Context, responses []providers.ToolResponse) error
SendToolResponses sends a round of tool results (one, or several for parallel tool calls): a function_call_output per result, then a user message carrying each result's media (realtime_tool_media.go), then one response.create to continue the conversation.
func (*RealtimeSession) SpeakOutOfBand ¶ added in v2.22.0
func (s *RealtimeSession) SpeakOutOfBand(ctx context.Context, text string) (providers.OutOfBandSpeech, error)
SpeakOutOfBand implements providers.OutOfBandSpeaker: it has the model say text in the session's voice in a response outside the conversation, and returns its audio, transcript and cost. It waits for the server to apply the session's configuration (session.updated) first, and fails at once when the server rejected it. A text-only session asks for nothing.
When ctx ends first, the response is canceled (response.cancel naming it, sent once the server has named it), and SpeakOutOfBand waits up to oobCancelGrace for its end, to return what it cost with ctx's error.
func (*RealtimeSession) SupportsToolResponseParts ¶ added in v2.22.0
func (s *RealtimeSession) SupportsToolResponseParts() bool
SupportsToolResponseParts reports that the session sends a tool result's media (providers.ToolResponse.Parts). Implements providers.ToolResponsePartsSupport.
func (*RealtimeSession) TriggerResponse ¶
func (s *RealtimeSession) TriggerResponse(config *ResponseConfig) error
TriggerResponse manually triggers a response from the model.
func (*RealtimeSession) UpdateTools ¶ added in v2.22.0
func (s *RealtimeSession) UpdateTools(ctx context.Context, tools []providers.StreamingToolDefinition) error
UpdateTools replaces the live session's tools with a session.update, keeping the session's tool_choice where it still applies (see realtimeToolChoice) and resetting it to "auto" where it does not. A nil error means the update was sent: the server reports a rejection later, as an error on the response stream. A done ctx sends nothing. Implements providers.StreamToolUpdater.
type RealtimeSessionConfig ¶
type RealtimeSessionConfig struct {
// Model specifies the model to use (e.g., "gpt-realtime-2.1").
Model string
// Modalities specifies the input/output modalities.
// Valid values: "text", "audio"
// Default: ["text", "audio"]
Modalities []string
// Instructions is the system prompt for the session.
Instructions string
// Voice selects the voice for audio output.
// Options: "alloy", "echo", "fable", "onyx", "nova", "shimmer"
// Default: "alloy"
Voice string
// InputAudioFormat specifies the format for input audio.
// Options: "pcm16", "g711_ulaw", "g711_alaw"
// Default: "pcm16"
InputAudioFormat string
// OutputAudioFormat specifies the format for output audio.
// Options: "pcm16", "g711_ulaw", "g711_alaw"
// Default: "pcm16"
OutputAudioFormat string
// InputAudioTranscription configures transcription of input audio.
// If nil, input transcription is disabled.
InputAudioTranscription *TranscriptionConfig
// TurnDetection configures server-side voice activity detection.
// If nil, VAD is disabled and turn management is manual.
TurnDetection *TurnDetectionConfig
// Tools defines available functions for the session.
Tools []RealtimeToolDefinition
// ToolChoice is the session's tool_choice: "auto", "required", "none",
// or a function name. Empty leaves the server default.
ToolChoice string
// OutputSampleRate is the sample rate in Hz for output audio.
// Default: 24000 (OpenAI Realtime API outputs 24kHz PCM).
OutputSampleRate int
// Temperature controls randomness (0.6-1.2, default 0.8).
Temperature float64
// MaxResponseOutputTokens limits response length.
// Use "inf" for unlimited, or a specific number.
MaxResponseOutputTokens interface{}
}
RealtimeSessionConfig configures a new OpenAI Realtime streaming session.
func DefaultRealtimeSessionConfig ¶
func DefaultRealtimeSessionConfig() RealtimeSessionConfig
DefaultRealtimeSessionConfig returns sensible defaults for a Realtime session.
type RealtimeToolDef ¶
type RealtimeToolDef struct {
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
RealtimeToolDef is the tool definition format for session config.
type RealtimeToolDefinition ¶
type RealtimeToolDefinition struct {
// Type is always "function" for function tools.
Type string `json:"type"`
// Name is the function name.
Name string `json:"name"`
// Description explains what the function does.
Description string `json:"description,omitempty"`
// Parameters is the JSON Schema for function parameters.
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
RealtimeToolDefinition defines a function available in the session.
type RealtimeWebSocket ¶
type RealtimeWebSocket struct {
// contains filtered or unexported fields
}
RealtimeWebSocket manages WebSocket connections for OpenAI Realtime API. It delegates transport concerns to the shared streaming.Conn.
func NewRealtimeWebSocket ¶
func NewRealtimeWebSocket(model, apiKey string) *RealtimeWebSocket
NewRealtimeWebSocket creates a new WebSocket manager for OpenAI Realtime API.
func (*RealtimeWebSocket) Close ¶
func (ws *RealtimeWebSocket) Close() error
Close closes the WebSocket connection gracefully.
func (*RealtimeWebSocket) Conn ¶
func (ws *RealtimeWebSocket) Conn() *streaming.Conn
Conn returns the underlying streaming.Conn for use by the session layer.
func (*RealtimeWebSocket) ConnectWithRetry ¶
func (ws *RealtimeWebSocket) ConnectWithRetry(ctx context.Context) error
ConnectWithRetry attempts to connect with exponential backoff.
func (*RealtimeWebSocket) IsClosed ¶
func (ws *RealtimeWebSocket) IsClosed() bool
IsClosed returns whether the WebSocket is closed.
func (*RealtimeWebSocket) Receive ¶
func (ws *RealtimeWebSocket) Receive(ctx context.Context) ([]byte, error)
Receive reads a message from the WebSocket with context support.
func (*RealtimeWebSocket) ReceiveLoop ¶
func (ws *RealtimeWebSocket) ReceiveLoop(ctx context.Context, msgCh chan<- []byte) error
ReceiveLoop continuously reads messages and sends them to the provided channel.
func (*RealtimeWebSocket) Send ¶
func (ws *RealtimeWebSocket) Send(msg interface{}) error
Send sends a message to the WebSocket.
func (*RealtimeWebSocket) StartHeartbeat ¶
func (ws *RealtimeWebSocket) StartHeartbeat(ctx context.Context, interval time.Duration)
StartHeartbeat starts a goroutine that sends ping messages periodically.
type ResponseAudioDeltaEvent ¶
type ResponseAudioDeltaEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Delta string `json:"delta"` // Base64-encoded audio
}
ResponseAudioDeltaEvent provides streaming audio.
type ResponseAudioDoneEvent ¶
type ResponseAudioDoneEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
}
ResponseAudioDoneEvent indicates audio streaming completed.
type ResponseAudioTranscriptDeltaEvent ¶
type ResponseAudioTranscriptDeltaEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Delta string `json:"delta"`
}
ResponseAudioTranscriptDeltaEvent provides streaming transcript.
type ResponseAudioTranscriptDoneEvent ¶
type ResponseAudioTranscriptDoneEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Transcript string `json:"transcript"`
}
ResponseAudioTranscriptDoneEvent indicates transcript completed.
type ResponseCancelEvent ¶
type ResponseCancelEvent struct {
ClientEvent
// ResponseID names the response to cancel; empty cancels the one in
// progress.
ResponseID string `json:"response_id,omitempty"`
}
ResponseCancelEvent cancels an in-progress response.
type ResponseConfig ¶
type ResponseConfig struct {
Modalities []string `json:"modalities,omitempty"`
Instructions string `json:"instructions,omitempty"`
Voice string `json:"voice,omitempty"`
OutputAudioFormat string `json:"output_audio_format,omitempty"`
Tools []RealtimeToolDef `json:"tools,omitempty"`
ToolChoice interface{} `json:"tool_choice,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
MaxOutputTokens interface{} `json:"max_output_tokens,omitempty"`
// Metadata is echoed on the response (response.created); the session tags
// each request with it (realtime_response_queue.go).
Metadata map[string]string `json:"metadata,omitempty"`
// Conversation "none" asks for a response outside the conversation: its
// output joins no conversation (realtime_out_of_band.go).
Conversation string `json:"conversation,omitempty"`
// OutputModalities is the GA output_modalities of this response alone.
OutputModalities []string `json:"output_modalities,omitempty"`
}
ResponseConfig configures a response.
type ResponseContentPartAddedEvent ¶
type ResponseContentPartAddedEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Part ConversationContent `json:"part"`
}
ResponseContentPartAddedEvent indicates content was added.
type ResponseContentPartDoneEvent ¶
type ResponseContentPartDoneEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Part ConversationContent `json:"part"`
}
ResponseContentPartDoneEvent indicates content part completed.
type ResponseCreateEvent ¶
type ResponseCreateEvent struct {
ClientEvent
Response *ResponseConfig `json:"response,omitempty"`
}
ResponseCreateEvent triggers a response from the model.
type ResponseCreatedEvent ¶
type ResponseCreatedEvent struct {
ServerEvent
Response ResponseInfo `json:"response"`
}
ResponseCreatedEvent indicates a response is starting.
type ResponseDoneEvent ¶
type ResponseDoneEvent struct {
ServerEvent
Response ResponseInfo `json:"response"`
}
ResponseDoneEvent indicates a response completed.
type ResponseFunctionCallArgumentsDeltaEvent ¶
type ResponseFunctionCallArgumentsDeltaEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
CallID string `json:"call_id"`
Delta string `json:"delta"`
}
ResponseFunctionCallArgumentsDeltaEvent provides streaming function args.
type ResponseFunctionCallArgumentsDoneEvent ¶
type ResponseFunctionCallArgumentsDoneEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
CallID string `json:"call_id"`
Name string `json:"name"`
Arguments string `json:"arguments"`
}
ResponseFunctionCallArgumentsDoneEvent indicates function args completed.
type ResponseInfo ¶
type ResponseInfo struct {
ID string `json:"id"`
Object string `json:"object"`
Status string `json:"status"`
StatusDetails interface{} `json:"status_details"`
Output []ConversationItem `json:"output"`
Usage *UsageInfo `json:"usage"`
// Metadata is the metadata its response.create carried, if any.
Metadata map[string]string `json:"metadata,omitempty"`
}
ResponseInfo contains response details.
type ResponseOutputItemAddedEvent ¶
type ResponseOutputItemAddedEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
OutputIndex int `json:"output_index"`
Item ConversationItem `json:"item"`
}
ResponseOutputItemAddedEvent indicates an output item was added.
type ResponseOutputItemDoneEvent ¶
type ResponseOutputItemDoneEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
OutputIndex int `json:"output_index"`
Item ConversationItem `json:"item"`
}
ResponseOutputItemDoneEvent indicates an output item completed.
type ResponseTextDeltaEvent ¶
type ResponseTextDeltaEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Delta string `json:"delta"`
}
ResponseTextDeltaEvent provides streaming text.
type ResponseTextDoneEvent ¶
type ResponseTextDoneEvent struct {
ServerEvent
ResponseID string `json:"response_id"`
ItemID string `json:"item_id"`
OutputIndex int `json:"output_index"`
ContentIndex int `json:"content_index"`
Text string `json:"text"`
}
ResponseTextDoneEvent indicates text streaming completed.
type ServerEvent ¶
ServerEvent is the base structure for all server events.
type SessionConfig ¶
type SessionConfig struct {
// Type distinguishes a speech-to-speech session ("realtime") from a
// transcription-only session ("transcription"). Required by GA.
Type string `json:"type,omitempty"`
Instructions string `json:"instructions,omitempty"`
OutputModalities []string `json:"output_modalities,omitempty"`
Audio *RealtimeAudioConfig `json:"audio,omitempty"`
Tools []RealtimeToolDef `json:"tools,omitempty"`
ToolChoice interface{} `json:"tool_choice,omitempty"`
MaxOutputTokens interface{} `json:"max_output_tokens,omitempty"`
}
SessionConfig is the session configuration sent in session.update. Shape matches the GA Realtime API: output_modalities replaces modalities; codec, voice, VAD, and transcription all moved into a nested audio.{input,output} object; the legacy beta-flat shape (with top-level voice, input_audio_format, etc.) is no longer accepted by gpt-realtime and other GA models.
type SessionCreatedEvent ¶
type SessionCreatedEvent struct {
ServerEvent
Session SessionInfo `json:"session"`
}
SessionCreatedEvent is sent when the session is established.
type SessionInfo ¶
type SessionInfo struct {
ID string `json:"id"`
Object string `json:"object"`
Model string `json:"model"`
Modalities []string `json:"modalities"`
Instructions string `json:"instructions"`
Voice string `json:"voice"`
InputAudioFormat string `json:"input_audio_format"`
OutputAudioFormat string `json:"output_audio_format"`
InputAudioTranscription *TranscriptionConfig `json:"input_audio_transcription"`
TurnDetection *TurnDetectionConfig `json:"turn_detection"`
Tools []RealtimeToolDef `json:"tools"`
Temperature float64 `json:"temperature"`
MaxResponseOutputTokens interface{} `json:"max_response_output_tokens"`
}
SessionInfo contains session details.
type SessionUpdateEvent ¶
type SessionUpdateEvent struct {
ClientEvent
Session SessionConfig `json:"session"`
}
SessionUpdateEvent updates session configuration.
type SessionUpdatedEvent ¶
type SessionUpdatedEvent struct {
ServerEvent
Session SessionInfo `json:"session"`
}
SessionUpdatedEvent confirms a session update.
type ToolProvider ¶
type ToolProvider struct {
*Provider
}
ToolProvider extends OpenAIProvider with tool support
func NewToolProvider ¶
func NewToolProvider( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, additionalConfig map[string]any, unsupportedParams []string, ) *ToolProvider
NewToolProvider creates a new OpenAI provider with tool support
func NewToolProviderWithCredential ¶
func NewToolProviderWithCredential( id, model, baseURL string, defaults providers.ProviderDefaults, includeRawOutput bool, additionalConfig map[string]any, cred providers.Credential, platform string, platformConfig *providers.PlatformConfig, unsupportedParams []string, ) *ToolProvider
NewToolProviderWithCredential creates an OpenAI tool provider with explicit credential.
func (*ToolProvider) BuildTooling ¶
func (p *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (providers.ProviderTools, error)
BuildTooling converts tool descriptors to OpenAI format. By default, strict mode is enabled for reliable argument generation. Set additional_config.strict_tools: false in provider config to disable.
func (*ToolProvider) PredictStreamWithTools ¶
func (p *ToolProvider) PredictStreamWithTools( ctx context.Context, req providers.PredictionRequest, tools any, toolChoice string, ) (<-chan providers.StreamChunk, error)
PredictStreamWithTools runs predictStreamWithToolsOnce, retrying without any sampling parameter the API rejects for this model, and on the Responses API if Chat Completions rejects the model as Responses-only.
func (*ToolProvider) PredictWithTools ¶
func (p *ToolProvider) PredictWithTools( ctx context.Context, req providers.PredictionRequest, tools providers.ProviderTools, toolChoice string, ) (providers.PredictionResponse, []types.MessageToolCall, error)
PredictWithTools runs predictWithToolsOnce, retrying without any sampling parameter the API rejects for this model, and on the Responses API if Chat Completions rejects the model as Responses-only.
func (*ToolProvider) WithMediaSettings ¶ added in v2.13.0
func (p *ToolProvider) WithMediaSettings(m providers.MediaSettings) providers.Provider
WithMediaSettings returns a view of p, and of the Provider it wraps, that uses m's media settings (providers.MediaScoped).
type TranscriptionConfig ¶
type TranscriptionConfig struct {
// Model specifies the transcription model.
// Default: "whisper-1"
Model string `json:"model,omitempty"`
}
TranscriptionConfig configures audio transcription.
type TurnDetectionConfig ¶
type TurnDetectionConfig struct {
// Type specifies the VAD type.
// Options: "server_vad", "semantic_vad"
Type string `json:"type"`
// Threshold is the activation threshold (0.0-1.0).
// Default: 0.5
Threshold float64 `json:"threshold,omitempty"`
// PrefixPaddingMs is audio padding before speech in milliseconds.
// Default: 300
PrefixPaddingMs int `json:"prefix_padding_ms,omitempty"`
// SilenceDurationMs is silence duration to detect end of speech.
// Default: 500
SilenceDurationMs int `json:"silence_duration_ms,omitempty"`
// CreateResponse determines if a response is automatically created
// when speech ends. Default: true
CreateResponse bool `json:"create_response,omitempty"`
}
TurnDetectionConfig configures server-side VAD.
type UsageInfo ¶
type UsageInfo struct {
TotalTokens int `json:"total_tokens"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
InputTokenDetails struct {
CachedTokens int `json:"cached_tokens"`
TextTokens int `json:"text_tokens"`
AudioTokens int `json:"audio_tokens"`
} `json:"input_token_details"`
OutputTokenDetails struct {
TextTokens int `json:"text_tokens"`
AudioTokens int `json:"audio_tokens"`
} `json:"output_token_details"`
}
UsageInfo contains token usage information.
Source Files
¶
- context_window_table.go
- embedding.go
- embedding_register.go
- openai.go
- openai_multimodal.go
- openai_responses_integration.go
- openai_tools.go
- pricing_table.go
- realtime_config.go
- realtime_context_note.go
- realtime_cost.go
- realtime_finish_reason.go
- realtime_forget.go
- realtime_history.go
- realtime_interrupt.go
- realtime_out_of_band.go
- realtime_output_audio.go
- realtime_platform.go
- realtime_playout.go
- realtime_protocol.go
- realtime_response_queue.go
- realtime_session_integration.go
- realtime_tool_media.go
- realtime_tools_integration.go
- realtime_types.go
- realtime_websocket_integration.go
- responses_convert.go
- responses_learning.go
- streaming_support.go
- streaming_support_integration.go
- tool_result_media.go