schemas

package
v0.0.0-...-98427c6 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Package schemas defines the core schemas and types used by the Bifrost system.

Index

Constants

View Source
const (
	// AsyncHeaderResultTTL is the header containing the result TTL for async job retrieval.
	AsyncHeaderResultTTL = "x-bf-async-job-result-ttl"
	// AsyncHeaderCreate is the header that triggers async job creation on integration routes.
	AsyncHeaderCreate = "x-bf-async"
	// AsyncHeaderGetID is the header containing the job ID for async job retrieval on integration routes.
	AsyncHeaderGetID = "x-bf-async-id"
)
View Source
const (
	RoutingEngineGovernance    = "governance"
	RoutingEngineRoutingRule   = "routing-rule"
	RoutingEngineLoadbalancing = "loadbalancing"
)

RoutingEngine constants

View Source
const (
	RequestCancelled = "request_cancelled"
	RequestTimedOut  = "request_timed_out"
)
View Source
const (
	DefaultMaxAgentDepth        = 10
	DefaultToolExecutionTimeout = 30 * time.Second
)
View Source
const (
	PluginStatusActive        = "active"
	PluginStatusError         = "error"
	PluginStatusDisabled      = "disabled"
	PluginStatusLoading       = "loading"
	PluginStatusUninitialized = "uninitialized"
	PluginStatusUnloaded      = "unloaded"
	PluginStatusLoaded        = "loaded"
)

PluginStatus constants

View Source
const (
	DefaultMaxRetries              = 0
	DefaultRetryBackoffInitial     = 500 * time.Millisecond
	DefaultRetryBackoffMax         = 5 * time.Second
	DefaultRequestTimeoutInSeconds = 30
	DefaultBufferSize              = 5000
	DefaultConcurrency             = 1000
	DefaultStreamBufferSize        = 5000
)
View Source
const (
	ErrProviderRequestTimedOut      = "" /* 189-byte string literal not displayed */
	ErrRequestCancelled             = "request cancelled by caller"
	ErrRequestBodyConversion        = "failed to convert bifrost request to the expected provider request body"
	ErrProviderRequestMarshal       = "failed to marshal request body to JSON"
	ErrProviderCreateRequest        = "failed to create HTTP request to provider API"
	ErrProviderDoRequest            = "failed to execute HTTP request to provider API"
	ErrProviderNetworkError         = "network error occurred while connecting to provider API (DNS lookup, connection refused, etc.)"
	ErrProviderResponseDecode       = "failed to decode response body from provider API"
	ErrProviderResponseUnmarshal    = "failed to unmarshal response from provider API"
	ErrProviderResponseEmpty        = "empty response received from provider"
	ErrProviderResponseHTML         = "HTML response received from provider"
	ErrProviderRawRequestUnmarshal  = "failed to unmarshal raw request from provider API"
	ErrProviderRawResponseUnmarshal = "failed to unmarshal raw response from provider API"
	ErrProviderResponseDecompress   = "failed to decompress provider's response"
)

Pre-defined errors for provider operations

View Source
const (
	// Provider and Model Attributes
	AttrProviderName = "gen_ai.provider.name"
	AttrRequestModel = "gen_ai.request.model"

	// Request Parameter Attributes
	AttrMaxTokens        = "gen_ai.request.max_tokens"
	AttrTemperature      = "gen_ai.request.temperature"
	AttrTopP             = "gen_ai.request.top_p"
	AttrStopSequences    = "gen_ai.request.stop_sequences"
	AttrPresencePenalty  = "gen_ai.request.presence_penalty"
	AttrFrequencyPenalty = "gen_ai.request.frequency_penalty"
	AttrParallelToolCall = "gen_ai.request.parallel_tool_calls"
	AttrRequestUser      = "gen_ai.request.user"
	AttrBestOf           = "gen_ai.request.best_of"
	AttrEcho             = "gen_ai.request.echo"
	AttrLogitBias        = "gen_ai.request.logit_bias"
	AttrLogProbs         = "gen_ai.request.logprobs"
	AttrN                = "gen_ai.request.n"
	AttrSeed             = "gen_ai.request.seed"
	AttrSuffix           = "gen_ai.request.suffix"
	AttrDimensions       = "gen_ai.request.dimensions"
	AttrEncodingFormat   = "gen_ai.request.encoding_format"
	AttrLanguage         = "gen_ai.request.language"
	AttrPrompt           = "gen_ai.request.prompt"
	AttrResponseFormat   = "gen_ai.request.response_format"
	AttrFormat           = "gen_ai.request.format"
	AttrVoice            = "gen_ai.request.voice"
	AttrMultiVoiceConfig = "gen_ai.request.multi_voice_config"
	AttrInstructions     = "gen_ai.request.instructions"
	AttrSpeed            = "gen_ai.request.speed"
	AttrMessageCount     = "gen_ai.request.message_count"

	// Response Attributes
	AttrResponseID       = "gen_ai.response.id"
	AttrResponseModel    = "gen_ai.response.model"
	AttrFinishReason     = "gen_ai.response.finish_reason"
	AttrSystemFprint     = "gen_ai.response.system_fingerprint"
	AttrServiceTier      = "gen_ai.response.service_tier"
	AttrCreated          = "gen_ai.response.created"
	AttrObject           = "gen_ai.response.object"
	AttrTimeToFirstToken = "gen_ai.response.time_to_first_token"
	AttrTotalChunks      = "gen_ai.response.total_chunks"

	// Plugin Attributes (for aggregated streaming post-hook spans)
	AttrPluginInvocations     = "plugin.invocation_count"
	AttrPluginAvgDurationMs   = "plugin.avg_duration_ms"
	AttrPluginTotalDurationMs = "plugin.total_duration_ms"
	AttrPluginErrorCount      = "plugin.error_count"

	// Usage Attributes
	AttrPromptTokens     = "gen_ai.usage.prompt_tokens"
	AttrCompletionTokens = "gen_ai.usage.completion_tokens"
	AttrTotalTokens      = "gen_ai.usage.total_tokens"
	AttrInputTokens      = "gen_ai.usage.input_tokens"
	AttrOutputTokens     = "gen_ai.usage.output_tokens"
	AttrUsageCost        = "gen_ai.usage.cost"

	// Error Attributes
	AttrError     = "gen_ai.error"
	AttrErrorType = "gen_ai.error.type"
	AttrErrorCode = "gen_ai.error.code"

	// Input/Output Attributes
	AttrInputText      = "gen_ai.input.text"
	AttrInputMessages  = "gen_ai.input.messages"
	AttrInputSpeech    = "gen_ai.input.speech"
	AttrInputEmbedding = "gen_ai.input.embedding"
	AttrOutputMessages = "gen_ai.output.messages"

	// Bifrost Context Attributes
	AttrVirtualKeyID    = "gen_ai.virtual_key_id"
	AttrVirtualKeyName  = "gen_ai.virtual_key_name"
	AttrSelectedKeyID   = "gen_ai.selected_key_id"
	AttrSelectedKeyName = "gen_ai.selected_key_name"
	AttrRoutingRuleID   = "gen_ai.routing_rule_id"
	AttrRoutingRuleName = "gen_ai.routing_rule_name"
	AttrTeamID          = "gen_ai.team_id"
	AttrTeamName        = "gen_ai.team_name"
	AttrCustomerID      = "gen_ai.customer_id"
	AttrCustomerName    = "gen_ai.customer_name"
	AttrNumberOfRetries = "gen_ai.number_of_retries"
	AttrFallbackIndex   = "gen_ai.fallback_index"

	// Responses API Request Attributes
	AttrPromptCacheKey      = "gen_ai.request.prompt_cache_key"
	AttrReasoningEffort     = "gen_ai.request.reasoning_effort"
	AttrReasoningSummary    = "gen_ai.request.reasoning_summary"
	AttrReasoningGenSummary = "gen_ai.request.reasoning_generate_summary"
	AttrSafetyIdentifier    = "gen_ai.request.safety_identifier"
	AttrStore               = "gen_ai.request.store"
	AttrTextVerbosity       = "gen_ai.request.text_verbosity"
	AttrTextFormatType      = "gen_ai.request.text_format_type"
	AttrTopLogProbs         = "gen_ai.request.top_logprobs"
	AttrToolChoiceType      = "gen_ai.request.tool_choice_type"
	AttrToolChoiceName      = "gen_ai.request.tool_choice_name"
	AttrTools               = "gen_ai.request.tools"
	AttrTruncation          = "gen_ai.request.truncation"

	// Responses API Response Attributes
	AttrRespInclude          = "gen_ai.responses.include"
	AttrRespMaxOutputTokens  = "gen_ai.responses.max_output_tokens"
	AttrRespMaxToolCalls     = "gen_ai.responses.max_tool_calls"
	AttrRespMetadata         = "gen_ai.responses.metadata"
	AttrRespPreviousRespID   = "gen_ai.responses.previous_response_id"
	AttrRespPromptCacheKey   = "gen_ai.responses.prompt_cache_key"
	AttrRespReasoningText    = "gen_ai.responses.reasoning"
	AttrRespReasoningEffort  = "gen_ai.responses.reasoning_effort"
	AttrRespReasoningGenSum  = "gen_ai.responses.reasoning_generate_summary"
	AttrRespSafetyIdentifier = "gen_ai.responses.safety_identifier"
	AttrRespStore            = "gen_ai.responses.store"
	AttrRespTemperature      = "gen_ai.responses.temperature"
	AttrRespTextVerbosity    = "gen_ai.responses.text_verbosity"
	AttrRespTextFormatType   = "gen_ai.responses.text_format_type"
	AttrRespTopLogProbs      = "gen_ai.responses.top_logprobs"
	AttrRespTopP             = "gen_ai.responses.top_p"
	AttrRespToolChoiceType   = "gen_ai.responses.tool_choice_type"
	AttrRespToolChoiceName   = "gen_ai.responses.tool_choice_name"
	AttrRespTruncation       = "gen_ai.responses.truncation"
	AttrRespTools            = "gen_ai.responses.tools"

	// Batch Operation Attributes
	AttrBatchID             = "gen_ai.batch.id"
	AttrBatchStatus         = "gen_ai.batch.status"
	AttrBatchObject         = "gen_ai.batch.object"
	AttrBatchEndpoint       = "gen_ai.batch.endpoint"
	AttrBatchInputFileID    = "gen_ai.batch.input_file_id"
	AttrBatchOutputFileID   = "gen_ai.batch.output_file_id"
	AttrBatchErrorFileID    = "gen_ai.batch.error_file_id"
	AttrBatchCompletionWin  = "gen_ai.batch.completion_window"
	AttrBatchCreatedAt      = "gen_ai.batch.created_at"
	AttrBatchExpiresAt      = "gen_ai.batch.expires_at"
	AttrBatchRequestsCount  = "gen_ai.batch.requests_count"
	AttrBatchDataCount      = "gen_ai.batch.data_count"
	AttrBatchResultsCount   = "gen_ai.batch.results_count"
	AttrBatchHasMore        = "gen_ai.batch.has_more"
	AttrBatchMetadata       = "gen_ai.batch.metadata"
	AttrBatchLimit          = "gen_ai.batch.limit"
	AttrBatchAfter          = "gen_ai.batch.after"
	AttrBatchBeforeID       = "gen_ai.batch.before_id"
	AttrBatchAfterID        = "gen_ai.batch.after_id"
	AttrBatchPageToken      = "gen_ai.batch.page_token"
	AttrBatchPageSize       = "gen_ai.batch.page_size"
	AttrBatchCountTotal     = "gen_ai.batch.request_counts.total"
	AttrBatchCountCompleted = "gen_ai.batch.request_counts.completed"
	AttrBatchCountFailed    = "gen_ai.batch.request_counts.failed"
	AttrBatchFirstID        = "gen_ai.batch.first_id"
	AttrBatchLastID         = "gen_ai.batch.last_id"
	AttrBatchInProgressAt   = "gen_ai.batch.in_progress_at"
	AttrBatchFinalizingAt   = "gen_ai.batch.finalizing_at"
	AttrBatchCompletedAt    = "gen_ai.batch.completed_at"
	AttrBatchFailedAt       = "gen_ai.batch.failed_at"
	AttrBatchExpiredAt      = "gen_ai.batch.expired_at"
	AttrBatchCancellingAt   = "gen_ai.batch.cancelling_at"
	AttrBatchCancelledAt    = "gen_ai.batch.cancelled_at"
	AttrBatchNextCursor     = "gen_ai.batch.next_cursor"

	// Transcription Response Attributes
	AttrInputTokenDetailsText  = "gen_ai.usage.input_token_details.text_tokens"
	AttrInputTokenDetailsAudio = "gen_ai.usage.input_token_details.audio_tokens"

	// File Operation Attributes
	AttrFileID             = "gen_ai.file.id"
	AttrFileObject         = "gen_ai.file.object"
	AttrFileFilename       = "gen_ai.file.filename"
	AttrFilePurpose        = "gen_ai.file.purpose"
	AttrFileBytes          = "gen_ai.file.bytes"
	AttrFileCreatedAt      = "gen_ai.file.created_at"
	AttrFileStatus         = "gen_ai.file.status"
	AttrFileStorageBackend = "gen_ai.file.storage_backend"
	AttrFileDataCount      = "gen_ai.file.data_count"
	AttrFileHasMore        = "gen_ai.file.has_more"
	AttrFileDeleted        = "gen_ai.file.deleted"
	AttrFileContentType    = "gen_ai.file.content_type"
	AttrFileContentBytes   = "gen_ai.file.content_bytes"
	AttrFileLimit          = "gen_ai.file.limit"
	AttrFileAfter          = "gen_ai.file.after"
	AttrFileOrder          = "gen_ai.file.order"
)

LLM Attribute Keys (gen_ai.* namespace) These follow the OpenTelemetry semantic conventions for GenAI and are compatible with both OTEL and Datadog backends.

View Source
const (
	DefaultInitialPoolSize = 5000
)
View Source
const DefaultPageSize = 1000

DefaultPageSize is the default page size for listing models

View Source
const MaxPaginationRequests = 20

MaxPaginationRequests is the maximum number of pagination requests to make

Variables

View Source
var (
	ErrOAuth2ConfigNotFound       = errors.New("oauth2 config not found")
	ErrOAuth2ProviderNotAvailable = errors.New("oauth2 provider not available")
	ErrOAuth2TokenExpired         = errors.New("oauth2 token expired")
	ErrOAuth2TokenInvalid         = errors.New("oauth2 token invalid")
	ErrOAuth2RefreshFailed        = errors.New("oauth2 token refresh failed")
)

OAuth-related errors

View Source
var DefaultConcurrencyAndBufferSize = ConcurrencyAndBufferSize{
	Concurrency: DefaultConcurrency,
	BufferSize:  DefaultBufferSize,
}

DefaultConcurrencyAndBufferSize is the default concurrency and buffer size for provider operations.

DefaultNetworkConfig is the default network configuration for provider connections.

View Source
var NoDeadline time.Time

StandardProviders is the list of all built-in (non-custom) providers.

SupportedBaseProviders is the list of base providers allowed for custom providers.

Functions

func AppendToContextList

func AppendToContextList[T any](ctx *BifrostContext, key BifrostContextKey, value T)

AppendToContext appends a value to the context list value. Parameters:

  • ctx: The Bifrost context
  • key: The key to append the value to
  • value: The value to append

func BaseModelName

func BaseModelName(id string) string

BaseModelName returns the model id with any recognized version suffix stripped.

This is your "model name without version".

func DeepCopy

func DeepCopy(in interface{}) interface{}

func EncodeSerialCursor

func EncodeSerialCursor(cursor *SerialCursor) string

EncodeSerialCursor encodes a SerialCursor to a base64 string for transport.

func ExtractTopLevelKeyOrder

func ExtractTopLevelKeyOrder(data []byte) []string

ExtractTopLevelKeyOrder parses a JSON object and returns its top-level keys in document order. Useful for capturing key order before struct deserialization loses it, so that re-serialization can preserve the original order.

func GetRandomString

func GetRandomString(length int) string

GetRandomString generates a random alphanumeric string of the given length.

func IsAllDigitsASCII

func IsAllDigitsASCII(s string) bool

IsAllDigitsASCII checks if a string contains only ASCII digits (0-9).

func IsAnthropicModel

func IsAnthropicModel(model string) bool

IsAnthropicModel checks if the model is an Anthropic model.

func IsGeminiModel

func IsGeminiModel(model string) bool

func IsGrokReasoningModel

func IsGrokReasoningModel(model string) bool

IsGrokReasoningModel checks if the given model is a grok reasoning model

func IsImagenModel

func IsImagenModel(model string) bool

IsImagenModel checks if the model is an Imagen model.

func IsKnownProvider

func IsKnownProvider(provider string) bool

IsKnownProvider checks if a provider string is known.

func IsMistralModel

func IsMistralModel(model string) bool

IsMistralModel checks if the model is a Mistral or Codestral model.

func IsNovaModel

func IsNovaModel(model string) bool

IsNovaModel checks if the model is a Nova model.

func IsVeoModel

func IsVeoModel(model string) bool

func JsonifyInput

func JsonifyInput(input interface{}) string

JsonifyInput converts an interface{} to a JSON string

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal encodes v to JSON bytes using the high-performance sonic library.

func MarshalString

func MarshalString(v interface{}) (string, error)

MarshalString encodes v to a JSON string using sonic.

func Ptr

func Ptr[T any](v T) *T

Ptr creates a pointer to any value. This is a helper function for creating pointers to values.

func RegisterKnownProvider

func RegisterKnownProvider(provider ModelProvider)

RegisterKnownProvider adds a provider to the known providers set. This allows ParseModelString to correctly parse model strings with custom provider prefixes (e.g., "my-custom-provider/gpt-4").

func ReleaseChatToResponsesStreamState

func ReleaseChatToResponsesStreamState(state *ChatToResponsesStreamState)

ReleaseChatToResponsesStreamState returns a ChatToResponsesStreamState to the pool.

func ReleaseHTTPRequest

func ReleaseHTTPRequest(req *HTTPRequest)

ReleaseHTTPRequest returns an HTTPRequest to the pool. The HTTPRequest is reset before being returned to the pool. Do not use the HTTPRequest after calling this function.

func ReleaseHTTPResponse

func ReleaseHTTPResponse(resp *HTTPResponse)

ReleaseHTTPResponse returns an HTTPResponse to the pool. The HTTPResponse is reset before being returned to the pool. Do not use the HTTPResponse after calling this function.

func ReorderJSONKeys

func ReorderJSONKeys(data []byte, order []string) ([]byte, error)

ReorderJSONKeys takes serialized JSON and a desired key order, and returns the same JSON with top-level keys reordered. Keys present in `order` are emitted first in that order; any remaining keys follow in their original order. This is a general-purpose utility for preserving client-specified key order through struct serialization/deserialization round-trips.

func SafeExtractBool

func SafeExtractBool(value interface{}) (bool, bool)

SafeExtractBool safely extracts a bool value from an interface{} with type checking

func SafeExtractBoolPointer

func SafeExtractBoolPointer(value interface{}) (*bool, bool)

SafeExtractBoolPointer safely extracts a *bool value from an interface{} with type checking

func SafeExtractFloat64

func SafeExtractFloat64(value interface{}) (float64, bool)

SafeExtractFloat64 safely extracts a float64 value from an interface{} with type checking

func SafeExtractFloat64Pointer

func SafeExtractFloat64Pointer(value interface{}) (*float64, bool)

SafeExtractFloat64Pointer safely extracts a *float64 value from an interface{} with type checking

func SafeExtractFromMap

func SafeExtractFromMap(m map[string]interface{}, key string) (interface{}, bool)

SafeExtractFromMap safely extracts a value from a map[string]interface{} with type checking

func SafeExtractInt

func SafeExtractInt(value interface{}) (int, bool)

SafeExtractInt safely extracts an int value from an interface{} with type checking

func SafeExtractIntPointer

func SafeExtractIntPointer(value interface{}) (*int, bool)

SafeExtractIntPointer safely extracts an *int value from an interface{} with type checking

func SafeExtractString

func SafeExtractString(value interface{}) (string, bool)

SafeExtractString safely extracts a string value from an interface{} with type checking

func SafeExtractStringMap

func SafeExtractStringMap(value interface{}) (map[string]string, bool)

SafeExtractStringMap safely extracts a map[string]string from an interface{} with type checking. Handles both direct map[string]string and JSON-deserialized map[string]interface{} cases.

func SafeExtractStringPointer

func SafeExtractStringPointer(value interface{}) (*string, bool)

SafeExtractStringPointer safely extracts a *string value from an interface{} with type checking

func SafeExtractStringSlice

func SafeExtractStringSlice(value interface{}) ([]string, bool)

SafeExtractStringSlice safely extracts a []string value from an interface{} with type checking

func SameBaseModel

func SameBaseModel(a, b string) bool

SameBaseModel reports whether two model ids refer to the same base model, ignoring any recognized version suffixes.

This works even if both sides are versioned, or both unversioned.

func SanitizeImageURL

func SanitizeImageURL(rawURL string) (string, error)

SanitizeImageURL sanitizes and validates an image URL. It handles both data URLs and regular HTTP/HTTPS URLs. It also detects raw base64 image data and adds proper data URL headers.

func SplitModelAndVersion

func SplitModelAndVersion(id string) (base, version string)

SplitModelAndVersion splits a model id into (base, versionSuffix). If no known version suffix is found, versionSuffix will be empty and base will be the original id.

Examples:

"claude-sonnet-4"                 -> ("claude-sonnet-4", "")
"claude-sonnet-4-20250514"        -> ("claude-sonnet-4", "20250514")
"gpt-4.1-2024-09-12"              -> ("gpt-4.1", "2024-09-12")
"gpt-4.1-mini-2024-09-12"         -> ("gpt-4.1-mini", "2024-09-12")
"some-model-v2"                   -> ("some-model", "v2")
"text-embedding-3-large-beta"     -> ("text-embedding-3-large", "beta")
"claude-sonnet-4.5"               -> ("claude-sonnet-4.5", "")

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal decodes JSON data into v using sonic.

func UnregisterKnownProvider

func UnregisterKnownProvider(provider ModelProvider)

UnregisterKnownProvider removes a custom provider from the known providers set. Standard providers cannot be unregistered.

Types

type Account

type Account interface {
	// GetConfiguredProviders returns a list of providers that are configured
	// in the account. This is used to determine which providers are available for use.
	GetConfiguredProviders() ([]ModelProvider, error)

	// GetKeysForProvider returns the API keys configured for a specific provider.
	// The keys include their values, supported models, and weights for load balancing.
	// The context can carry data from any source that sets values before the Bifrost request,
	// including but not limited to plugin pre-hooks, application logic, or any in app middleware sharing the context.
	// This enables dynamic key selection based on any context values present during the request.
	GetKeysForProvider(ctx context.Context, providerKey ModelProvider) ([]Key, error)

	// GetConfigForProvider returns the configuration for a specific provider.
	// This includes network settings, authentication details, and other provider-specific
	// configurations.
	GetConfigForProvider(providerKey ModelProvider) (*ProviderConfig, error)
}

Account defines the interface for managing provider accounts and their configurations. It provides methods to access provider-specific settings, API keys, and configurations.

type AdditionalPropertiesStruct

type AdditionalPropertiesStruct struct {
	AdditionalPropertiesBool *bool
	AdditionalPropertiesMap  *OrderedMap
}

func (AdditionalPropertiesStruct) MarshalJSON

func (a AdditionalPropertiesStruct) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for AdditionalPropertiesStruct. It marshals either AdditionalPropertiesBool or AdditionalPropertiesMap based on which is set.

func (*AdditionalPropertiesStruct) UnmarshalJSON

func (a *AdditionalPropertiesStruct) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for AdditionalPropertiesStruct. It handles both boolean and object types for additionalProperties.

type AllowedRequests

type AllowedRequests struct {
	ListModels            bool `json:"list_models"`
	TextCompletion        bool `json:"text_completion"`
	TextCompletionStream  bool `json:"text_completion_stream"`
	ChatCompletion        bool `json:"chat_completion"`
	ChatCompletionStream  bool `json:"chat_completion_stream"`
	Responses             bool `json:"responses"`
	ResponsesStream       bool `json:"responses_stream"`
	CountTokens           bool `json:"count_tokens"`
	Embedding             bool `json:"embedding"`
	Rerank                bool `json:"rerank"`
	Speech                bool `json:"speech"`
	SpeechStream          bool `json:"speech_stream"`
	Transcription         bool `json:"transcription"`
	TranscriptionStream   bool `json:"transcription_stream"`
	ImageGeneration       bool `json:"image_generation"`
	ImageGenerationStream bool `json:"image_generation_stream"`
	ImageEdit             bool `json:"image_edit"`
	ImageEditStream       bool `json:"image_edit_stream"`
	ImageVariation        bool `json:"image_variation"`
	VideoGeneration       bool `json:"video_generation"`
	VideoRetrieve         bool `json:"video_retrieve"`
	VideoDownload         bool `json:"video_download"`
	VideoDelete           bool `json:"video_delete"`
	VideoList             bool `json:"video_list"`
	VideoRemix            bool `json:"video_remix"`
	BatchCreate           bool `json:"batch_create"`
	BatchList             bool `json:"batch_list"`
	BatchRetrieve         bool `json:"batch_retrieve"`
	BatchCancel           bool `json:"batch_cancel"`
	BatchResults          bool `json:"batch_results"`
	FileUpload            bool `json:"file_upload"`
	FileList              bool `json:"file_list"`
	FileRetrieve          bool `json:"file_retrieve"`
	FileDelete            bool `json:"file_delete"`
	FileContent           bool `json:"file_content"`
	ContainerCreate       bool `json:"container_create"`
	ContainerList         bool `json:"container_list"`
	ContainerRetrieve     bool `json:"container_retrieve"`
	ContainerDelete       bool `json:"container_delete"`
	ContainerFileCreate   bool `json:"container_file_create"`
	ContainerFileList     bool `json:"container_file_list"`
	ContainerFileRetrieve bool `json:"container_file_retrieve"`
	ContainerFileContent  bool `json:"container_file_content"`
	ContainerFileDelete   bool `json:"container_file_delete"`
}

AllowedRequests controls which operations are permitted. A nil *AllowedRequests means "all operations allowed." A non-nil value only allows fields set to true; omitted or false fields are disallowed.

func (*AllowedRequests) IsOperationAllowed

func (ar *AllowedRequests) IsOperationAllowed(operation RequestType) bool

IsOperationAllowed checks if a specific operation is allowed

type Architecture

type Architecture struct {
	Modality         *string  `json:"modality,omitempty"`
	Tokenizer        *string  `json:"tokenizer,omitempty"`
	InstructType     *string  `json:"instruct_type,omitempty"`
	InputModalities  []string `json:"input_modalities,omitempty"`
	OutputModalities []string `json:"output_modalities,omitempty"`
}

type AsyncJobResponse

type AsyncJobResponse struct {
	ID          string         `json:"id"`
	Status      AsyncJobStatus `json:"status"`
	ExpiresAt   *time.Time     `json:"expires_at,omitempty"`
	CreatedAt   time.Time      `json:"created_at"`
	CompletedAt *time.Time     `json:"completed_at,omitempty"`
	StatusCode  int            `json:"status_code,omitempty"`
	Result      interface{}    `json:"result,omitempty"`
	Error       *BifrostError  `json:"error,omitempty"`
}

AsyncJobResponse is the JSON response returned when creating or polling an async job

type AsyncJobStatus

type AsyncJobStatus string

AsyncJobStatus represents the status of an async job

const (
	AsyncJobStatusPending    AsyncJobStatus = "pending"
	AsyncJobStatusProcessing AsyncJobStatus = "processing"
	AsyncJobStatusCompleted  AsyncJobStatus = "completed"
	AsyncJobStatusFailed     AsyncJobStatus = "failed"
)

type AzureKeyConfig

type AzureKeyConfig struct {
	Endpoint    EnvVar            `json:"endpoint"`              // Azure service endpoint URL
	Deployments map[string]string `json:"deployments,omitempty"` // Mapping of model names to deployment names
	APIVersion  *EnvVar           `json:"api_version,omitempty"` // Azure API version to use; defaults to "2024-10-21"

	ClientID     *EnvVar  `json:"client_id,omitempty"`     // Azure client ID for authentication
	ClientSecret *EnvVar  `json:"client_secret,omitempty"` // Azure client secret for authentication
	TenantID     *EnvVar  `json:"tenant_id,omitempty"`     // Azure tenant ID for authentication
	Scopes       []string `json:"scopes,omitempty"`
}

AzureKeyConfig represents the Azure-specific configuration. It contains Azure-specific settings required for service access and deployment management.

type BasePlugin

type BasePlugin interface {
	// GetName returns the name of the plugin.
	GetName() string

	// Cleanup is called on bifrost shutdown.
	// It allows plugins to clean up any resources they have allocated.
	// Returns any error that occurred during cleanup, which will be logged as a warning by the Bifrost instance.
	Cleanup() error
}

type BatchEndpoint

type BatchEndpoint string

BatchEndpoint represents supported batch API endpoints.

const (
	BatchEndpointChatCompletions BatchEndpoint = "/v1/chat/completions"
	BatchEndpointEmbeddings      BatchEndpoint = "/v1/embeddings"
	BatchEndpointCompletions     BatchEndpoint = "/v1/completions"
	BatchEndpointResponses       BatchEndpoint = "/v1/responses"
	BatchEndpointMessages        BatchEndpoint = "/v1/messages" // Anthropic
)

type BatchError

type BatchError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	Param   string `json:"param,omitempty"`
	Line    *int   `json:"line,omitempty"`
}

BatchError represents a single error in batch processing.

type BatchErrors

type BatchErrors struct {
	Object string       `json:"object,omitempty"`
	Data   []BatchError `json:"data,omitempty"`
}

BatchErrors represents errors encountered during batch processing.

type BatchExpiresAfter

type BatchExpiresAfter struct {
	Anchor  string `json:"anchor"`  // e.g., "created_at"
	Seconds int    `json:"seconds"` // 3600-2592000 (1 hour to 30 days)
}

BatchExpiresAfter represents an expiration configuration for batch output.

type BatchRequestCounts

type BatchRequestCounts struct {
	Total     int `json:"total"`
	Completed int `json:"completed"`
	Failed    int `json:"failed"`
	Succeeded int `json:"succeeded,omitempty"` // Anthropic-specific
	Expired   int `json:"expired,omitempty"`   // Anthropic-specific
	Canceled  int `json:"canceled,omitempty"`  // Anthropic-specific
	Pending   int `json:"pending,omitempty"`   // Anthropic-specific
}

BatchRequestCounts tracks the counts of requests in different states.

type BatchRequestItem

type BatchRequestItem struct {
	CustomID string                 `json:"custom_id"`        // User-provided unique ID for this request
	Method   string                 `json:"method,omitempty"` // HTTP method (typically "POST")
	URL      string                 `json:"url,omitempty"`    // Endpoint URL (e.g., "/v1/chat/completions")
	Body     map[string]interface{} `json:"body,omitempty"`   // Request body parameters
	Params   map[string]interface{} `json:"params,omitempty"` // Alternative to Body for Anthropic
}

BatchRequestItem represents a single request in a batch (for inline requests).

type BatchResultData

type BatchResultData struct {
	Type    string                 `json:"type"` // "succeeded", "errored", "expired", "canceled"
	Message map[string]interface{} `json:"message,omitempty"`
}

BatchResultData represents Anthropic-style result data.

type BatchResultError

type BatchResultError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

BatchResultError represents an error for a single batch request.

type BatchResultItem

type BatchResultItem struct {
	CustomID string `json:"custom_id"`

	// Result data (varies by request type)
	Response *BatchResultResponse `json:"response,omitempty"` // OpenAI format
	Result   *BatchResultData     `json:"result,omitempty"`   // Anthropic format

	// Error if the individual request failed
	Error *BatchResultError `json:"error,omitempty"`
}

BatchResultItem represents a single result from a batch request.

type BatchResultResponse

type BatchResultResponse struct {
	StatusCode int                    `json:"status_code"`
	RequestID  string                 `json:"request_id,omitempty"`
	Body       map[string]interface{} `json:"body,omitempty"`
}

BatchResultResponse represents OpenAI-style result response.

type BatchS3Config

type BatchS3Config struct {
	Buckets []S3BucketConfig `json:"buckets,omitempty"` // List of S3 bucket configurations
}

BatchS3Config holds S3 bucket configurations for Bedrock batch operations. Supports multiple buckets to allow flexible batch job routing.

type BatchStatus

type BatchStatus string

BatchStatus represents the status of a batch job.

const (
	BatchStatusValidating BatchStatus = "validating"
	BatchStatusFailed     BatchStatus = "failed"
	BatchStatusInProgress BatchStatus = "in_progress"
	BatchStatusFinalizing BatchStatus = "finalizing"
	BatchStatusCompleted  BatchStatus = "completed"
	BatchStatusExpired    BatchStatus = "expired"
	BatchStatusCancelling BatchStatus = "cancelling"
	BatchStatusCancelled  BatchStatus = "cancelled"
	BatchStatusEnded      BatchStatus = "ended" // Anthropic-specific
)

type BedrockKeyConfig

type BedrockKeyConfig struct {
	AccessKey     EnvVar            `json:"access_key,omitempty"`      // AWS access key for authentication
	SecretKey     EnvVar            `json:"secret_key,omitempty"`      // AWS secret access key for authentication
	SessionToken  *EnvVar           `json:"session_token,omitempty"`   // AWS session token for temporary credentials
	Region        *EnvVar           `json:"region,omitempty"`          // AWS region for service access
	ARN           *EnvVar           `json:"arn,omitempty"`             // Amazon Resource Name for resource identification
	Deployments   map[string]string `json:"deployments,omitempty"`     // Mapping of model identifiers to inference profiles
	BatchS3Config *BatchS3Config    `json:"batch_s3_config,omitempty"` // S3 bucket configuration for batch operations
}

BedrockKeyConfig represents the AWS Bedrock-specific configuration. It contains AWS-specific settings required for authentication and service access.

type BifrostBatchCancelRequest

type BifrostBatchCancelRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`
	BatchID  string        `json:"batch_id"` // ID of the batch to cancel

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostBatchCancelRequest represents a request to cancel a batch job.

func (*BifrostBatchCancelRequest) GetRawRequestBody

func (request *BifrostBatchCancelRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostBatchCancelResponse

type BifrostBatchCancelResponse struct {
	ID            string             `json:"id"`
	Object        string             `json:"object,omitempty"`
	Status        BatchStatus        `json:"status"`
	RequestCounts BatchRequestCounts `json:"request_counts,omitempty"`
	CancellingAt  *int64             `json:"cancelling_at,omitempty"`
	CancelledAt   *int64             `json:"cancelled_at,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostBatchCancelResponse represents the response from cancelling a batch job.

type BifrostBatchCreateRequest

type BifrostBatchCreateRequest struct {
	Provider       ModelProvider `json:"provider"`
	Model          *string       `json:"model,omitempty"` // Model hint for routing (optional for file-based) it may or may not present depending on the provider and usage of integration vs direct API
	RawRequestBody []byte        `json:"-"`               // Raw request body (not serialized)

	// OpenAI-style: file-based batching
	InputFileID string `json:"input_file_id,omitempty"` // ID of uploaded JSONL file

	// Anthropic-style: inline requests
	Requests []BatchRequestItem `json:"requests,omitempty"` // Inline request items

	// Common fields
	Endpoint           BatchEndpoint      `json:"endpoint,omitempty"`             // Target endpoint for batch requests
	CompletionWindow   string             `json:"completion_window,omitempty"`    // Time window (e.g., "24h")
	Metadata           map[string]string  `json:"metadata,omitempty"`             // User-provided metadata
	OutputExpiresAfter *BatchExpiresAfter `json:"output_expires_after,omitempty"` // Expiration for batch output (OpenAI only)

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostBatchCreateRequest represents a request to create a batch job.

func (*BifrostBatchCreateRequest) GetRawRequestBody

func (request *BifrostBatchCreateRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostBatchCreateResponse

type BifrostBatchCreateResponse struct {
	ID               string             `json:"id"`
	Object           string             `json:"object,omitempty"` // "batch" for OpenAI
	Endpoint         string             `json:"endpoint,omitempty"`
	InputFileID      string             `json:"input_file_id,omitempty"`
	CompletionWindow string             `json:"completion_window,omitempty"`
	Status           BatchStatus        `json:"status"`
	RequestCounts    BatchRequestCounts `json:"request_counts,omitempty"`
	Metadata         map[string]string  `json:"metadata,omitempty"`
	CreatedAt        int64              `json:"created_at,omitempty"`
	ExpiresAt        *int64             `json:"expires_at,omitempty"`

	// Output file references (OpenAI)
	OutputFileID *string `json:"output_file_id,omitempty"`
	ErrorFileID  *string `json:"error_file_id,omitempty"`

	// Anthropic-specific
	ProcessingStatus *string `json:"processing_status,omitempty"`
	ResultsURL       *string `json:"results_url,omitempty"`

	// Gemini-specific (operation response)
	OperationName *string `json:"operation_name,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostBatchCreateResponse represents the response from creating a batch job.

type BifrostBatchListRequest

type BifrostBatchListRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`

	// Pagination
	Limit      int     `json:"limit,omitempty"`       // Max results to return
	After      *string `json:"after,omitempty"`       // Cursor for pagination (OpenAI)
	BeforeID   *string `json:"before_id,omitempty"`   // Pagination cursor (Anthropic)
	AfterID    *string `json:"after_id,omitempty"`    // Pagination cursor (Anthropic)
	PageToken  *string `json:"page_token,omitempty"`  // For Gemini pagination
	PageSize   int     `json:"page_size,omitempty"`   // For Gemini pagination
	NextCursor *string `json:"next_cursor,omitempty"` // For Gemini pagination

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostBatchListRequest represents a request to list batch jobs.

type BifrostBatchListResponse

type BifrostBatchListResponse struct {
	Object  string                         `json:"object,omitempty"` // "list"
	Data    []BifrostBatchRetrieveResponse `json:"data"`
	FirstID *string                        `json:"first_id,omitempty"`
	LastID  *string                        `json:"last_id,omitempty"`
	HasMore bool                           `json:"has_more,omitempty"`

	// Anthropic pagination
	NextCursor *string `json:"next_cursor,omitempty"` // For cursor-based pagination

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostBatchListResponse represents the response from listing batch jobs.

type BifrostBatchResultsRequest

type BifrostBatchResultsRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`
	BatchID  string        `json:"batch_id"` // ID of the batch to get results for

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostBatchResultsRequest represents a request to retrieve batch results.

func (*BifrostBatchResultsRequest) GetRawRequestBody

func (request *BifrostBatchResultsRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostBatchResultsResponse

type BifrostBatchResultsResponse struct {
	BatchID string            `json:"batch_id"`
	Results []BatchResultItem `json:"results"`

	// For streaming results (Anthropic)
	HasMore    bool    `json:"has_more,omitempty"`
	NextCursor *string `json:"next_cursor,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostBatchResultsResponse represents the response from retrieving batch results.

type BifrostBatchRetrieveRequest

type BifrostBatchRetrieveRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`
	BatchID  string        `json:"batch_id"` // ID of the batch to retrieve

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostBatchRetrieveRequest represents a request to retrieve a batch job.

func (*BifrostBatchRetrieveRequest) GetRawRequestBody

func (request *BifrostBatchRetrieveRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostBatchRetrieveResponse

type BifrostBatchRetrieveResponse struct {
	ID               string             `json:"id"`
	Object           string             `json:"object,omitempty"`
	Endpoint         string             `json:"endpoint,omitempty"`
	InputFileID      string             `json:"input_file_id,omitempty"`
	CompletionWindow string             `json:"completion_window,omitempty"`
	Status           BatchStatus        `json:"status"`
	RequestCounts    BatchRequestCounts `json:"request_counts,omitempty"`
	Metadata         map[string]string  `json:"metadata,omitempty"`
	CreatedAt        int64              `json:"created_at,omitempty"`
	ExpiresAt        *int64             `json:"expires_at,omitempty"`
	InProgressAt     *int64             `json:"in_progress_at,omitempty"`
	FinalizingAt     *int64             `json:"finalizing_at,omitempty"`
	CompletedAt      *int64             `json:"completed_at,omitempty"`
	FailedAt         *int64             `json:"failed_at,omitempty"`
	ExpiredAt        *int64             `json:"expired_at,omitempty"`
	CancellingAt     *int64             `json:"cancelling_at,omitempty"`
	CancelledAt      *int64             `json:"cancelled_at,omitempty"`

	// Output references
	OutputFileID *string      `json:"output_file_id,omitempty"`
	ErrorFileID  *string      `json:"error_file_id,omitempty"`
	Errors       *BatchErrors `json:"errors,omitempty"`

	// Anthropic-specific
	ProcessingStatus *string `json:"processing_status,omitempty"`
	ResultsURL       *string `json:"results_url,omitempty"`
	ArchivedAt       *int64  `json:"archived_at,omitempty"`

	// Gemini-specific
	OperationName *string `json:"operation_name,omitempty"`
	Done          *bool   `json:"done,omitempty"`
	Progress      *int    `json:"progress,omitempty"` // Percentage progress

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostBatchRetrieveResponse represents the response from retrieving a batch job.

type BifrostCacheDebug

type BifrostCacheDebug struct {
	CacheHit bool `json:"cache_hit"`

	CacheID *string `json:"cache_id,omitempty"`
	HitType *string `json:"hit_type,omitempty"`

	// Semantic cache only (provider, model, and input tokens will be present for semantic cache, even if cache is not hit)
	ProviderUsed *string `json:"provider_used,omitempty"`
	ModelUsed    *string `json:"model_used,omitempty"`
	InputTokens  *int    `json:"input_tokens,omitempty"`

	// Semantic cache only (only when cache is hit)
	Threshold  *float64 `json:"threshold,omitempty"`
	Similarity *float64 `json:"similarity,omitempty"`
}

BifrostCacheDebug represents debug information about the cache.

type BifrostChatRequest

type BifrostChatRequest struct {
	Provider       ModelProvider   `json:"provider"`
	Model          string          `json:"model"`
	Input          []ChatMessage   `json:"input,omitempty"`
	Params         *ChatParameters `json:"params,omitempty"`
	Fallbacks      []Fallback      `json:"fallbacks,omitempty"`
	RawRequestBody []byte          `json:"-"` // set bifrost-use-raw-request-body to true in ctx to use the raw request body. Bifrost will directly send this to the downstream provider.
}

BifrostChatRequest is the request struct for chat completion requests

func (*BifrostChatRequest) GetExtraParams

func (cr *BifrostChatRequest) GetExtraParams() map[string]interface{}

func (*BifrostChatRequest) GetRawRequestBody

func (cr *BifrostChatRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body

func (*BifrostChatRequest) ToResponsesRequest

func (cr *BifrostChatRequest) ToResponsesRequest() *BifrostResponsesRequest

ToResponsesRequest converts a BifrostChatRequest to BifrostResponsesRequest format

type BifrostChatResponse

type BifrostChatResponse struct {
	ID                string                     `json:"id"`
	Choices           []BifrostResponseChoice    `json:"choices"`
	Created           int                        `json:"created"` // The Unix timestamp (in seconds).
	Model             string                     `json:"model"`
	Object            string                     `json:"object"` // "chat.completion" or "chat.completion.chunk"
	ServiceTier       *string                    `json:"service_tier,omitempty"`
	SystemFingerprint string                     `json:"system_fingerprint"`
	Usage             *BifrostLLMUsage           `json:"usage"`
	ExtraFields       BifrostResponseExtraFields `json:"extra_fields"`
	ExtraParams       map[string]interface{}     `json:"-"`

	// Perplexity-specific fields
	SearchResults []SearchResult `json:"search_results,omitempty"`
	Videos        []VideoResult  `json:"videos,omitempty"`
	Citations     []string       `json:"citations,omitempty"`
}

BifrostChatResponse represents the complete result from a chat completion request.

func (*BifrostChatResponse) ToBifrostResponsesResponse

func (cr *BifrostChatResponse) ToBifrostResponsesResponse() *BifrostResponsesResponse

ToBifrostResponsesResponse converts the BifrostChatResponse to BifrostResponsesResponse format This converts Chat-style fields (Choices) to Responses API format

func (*BifrostChatResponse) ToBifrostResponsesStreamResponse

func (cr *BifrostChatResponse) ToBifrostResponsesStreamResponse(state *ChatToResponsesStreamState) []*BifrostResponsesStreamResponse

ToBifrostResponsesStreamResponse converts the BifrostChatResponse from Chat streaming format to Responses streaming format This converts Chat stream chunks (Choices with Deltas) to BifrostResponsesStreamResponse format Returns a slice of responses to support cases where a single event produces multiple responses

func (*BifrostChatResponse) ToTextCompletionResponse

func (cr *BifrostChatResponse) ToTextCompletionResponse() *BifrostTextCompletionResponse

ToTextCompletionResponse converts a BifrostChatResponse to a BifrostTextCompletionResponse

type BifrostConfig

type BifrostConfig struct {
	Account            Account
	LLMPlugins         []LLMPlugin
	MCPPlugins         []MCPPlugin
	OAuth2Provider     OAuth2Provider
	Logger             Logger
	Tracer             Tracer      // Tracer for distributed tracing (nil = NoOpTracer)
	InitialPoolSize    int         // Initial pool size for sync pools in Bifrost. Higher values will reduce memory allocations but will increase memory usage.
	DropExcessRequests bool        // If true, in cases where the queue is full, requests will not wait for the queue to be empty and will be dropped instead.
	MCPConfig          *MCPConfig  // MCP (Model Context Protocol) configuration for tool integration
	KeySelector        KeySelector // Custom key selector function
}

BifrostConfig represents the configuration for initializing a Bifrost instance. It contains the necessary components for setting up the system including account details, plugins, logging, and initial pool size.

type BifrostContainerCreateRequest

type BifrostContainerCreateRequest struct {
	Provider ModelProvider `json:"provider"`

	// Required fields
	Name string `json:"name"` // Name of the container

	// Optional fields
	ExpiresAfter *ContainerExpiresAfter `json:"expires_after,omitempty"` // Expiration configuration
	FileIDs      []string               `json:"file_ids,omitempty"`      // IDs of existing files to copy into this container
	MemoryLimit  string                 `json:"memory_limit,omitempty"`  // Memory limit (e.g., "1g", "4g")
	Metadata     map[string]string      `json:"metadata,omitempty"`      // User-provided metadata

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerCreateRequest represents a request to create a container.

type BifrostContainerCreateResponse

type BifrostContainerCreateResponse struct {
	ID           string                 `json:"id"`
	Object       string                 `json:"object,omitempty"` // "container"
	Name         string                 `json:"name"`
	CreatedAt    int64                  `json:"created_at"`
	Status       ContainerStatus        `json:"status,omitempty"`
	ExpiresAfter *ContainerExpiresAfter `json:"expires_after,omitempty"`
	LastActiveAt *int64                 `json:"last_active_at,omitempty"`
	MemoryLimit  string                 `json:"memory_limit,omitempty"`
	Metadata     map[string]string      `json:"metadata,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerCreateResponse represents the response from creating a container.

type BifrostContainerDeleteRequest

type BifrostContainerDeleteRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container to delete

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerDeleteRequest represents a request to delete a container.

type BifrostContainerDeleteResponse

type BifrostContainerDeleteResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object,omitempty"` // "container.deleted"
	Deleted bool   `json:"deleted"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerDeleteResponse represents the response from deleting a container.

type BifrostContainerFileContentRequest

type BifrostContainerFileContentRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container
	FileID      string        `json:"file_id"`      // ID of the file

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerFileContentRequest represents a request to retrieve the content of a container file.

type BifrostContainerFileContentResponse

type BifrostContainerFileContentResponse struct {
	Content     []byte `json:"content"`      // Raw file content
	ContentType string `json:"content_type"` // MIME type of the content

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerFileContentResponse represents the response from retrieving container file content.

type BifrostContainerFileCreateRequest

type BifrostContainerFileCreateRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container

	// One of these must be provided
	File   []byte  `json:"-"`                   // File content (for multipart upload)
	FileID *string `json:"file_id,omitempty"`   // Reference to existing file
	Path   *string `json:"file_path,omitempty"` // Path for the file in the container

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerFileCreateRequest represents a request to create a file in a container.

type BifrostContainerFileCreateResponse

type BifrostContainerFileCreateResponse struct {
	ID          string `json:"id"`
	Object      string `json:"object,omitempty"` // "container.file"
	Bytes       int64  `json:"bytes"`
	CreatedAt   int64  `json:"created_at"`
	ContainerID string `json:"container_id"`
	Path        string `json:"path"`
	Source      string `json:"source"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerFileCreateResponse represents the response from creating a container file.

type BifrostContainerFileDeleteRequest

type BifrostContainerFileDeleteRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container
	FileID      string        `json:"file_id"`      // ID of the file to delete

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerFileDeleteRequest represents a request to delete a container file.

type BifrostContainerFileDeleteResponse

type BifrostContainerFileDeleteResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object,omitempty"` // "container.file.deleted"
	Deleted bool   `json:"deleted"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerFileDeleteResponse represents the response from deleting a container file.

type BifrostContainerFileListRequest

type BifrostContainerFileListRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container

	// Pagination
	Limit int     `json:"limit,omitempty"` // Max results to return (1-100, default 20)
	After *string `json:"after,omitempty"` // Cursor for pagination
	Order *string `json:"order,omitempty"` // Sort order (asc/desc), default desc

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerFileListRequest represents a request to list files in a container.

type BifrostContainerFileListResponse

type BifrostContainerFileListResponse struct {
	Object  string                `json:"object,omitempty"` // "list"
	Data    []ContainerFileObject `json:"data"`
	FirstID *string               `json:"first_id,omitempty"`
	LastID  *string               `json:"last_id,omitempty"`
	HasMore bool                  `json:"has_more,omitempty"`
	After   *string               `json:"after,omitempty"` // Encoded cursor for next page (includes key index for multi-key pagination)

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerFileListResponse represents the response from listing container files.

type BifrostContainerFileRetrieveRequest

type BifrostContainerFileRetrieveRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container
	FileID      string        `json:"file_id"`      // ID of the file to retrieve

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerFileRetrieveRequest represents a request to retrieve a container file.

type BifrostContainerFileRetrieveResponse

type BifrostContainerFileRetrieveResponse struct {
	ID          string `json:"id"`
	Object      string `json:"object,omitempty"` // "container.file"
	Bytes       int64  `json:"bytes"`
	CreatedAt   int64  `json:"created_at"`
	ContainerID string `json:"container_id"`
	Path        string `json:"path"`
	Source      string `json:"source"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerFileRetrieveResponse represents the response from retrieving a container file.

type BifrostContainerListRequest

type BifrostContainerListRequest struct {
	Provider ModelProvider `json:"provider"`

	// Pagination
	Limit int     `json:"limit,omitempty"` // Max results to return (1-100, default 20)
	After *string `json:"after,omitempty"` // Cursor for pagination
	Order *string `json:"order,omitempty"` // Sort order (asc/desc), default desc

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerListRequest represents a request to list containers.

type BifrostContainerListResponse

type BifrostContainerListResponse struct {
	Object  string            `json:"object,omitempty"` // "list"
	Data    []ContainerObject `json:"data"`
	FirstID *string           `json:"first_id,omitempty"`
	LastID  *string           `json:"last_id,omitempty"`
	HasMore bool              `json:"has_more,omitempty"`
	After   *string           `json:"after,omitempty"` // Encoded cursor for next page (includes key index for multi-key pagination)

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerListResponse represents the response from listing containers.

type BifrostContainerRetrieveRequest

type BifrostContainerRetrieveRequest struct {
	Provider    ModelProvider `json:"provider"`
	ContainerID string        `json:"container_id"` // ID of the container to retrieve

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostContainerRetrieveRequest represents a request to retrieve a container.

type BifrostContainerRetrieveResponse

type BifrostContainerRetrieveResponse struct {
	ID           string                 `json:"id"`
	Object       string                 `json:"object,omitempty"` // "container"
	Name         string                 `json:"name"`
	CreatedAt    int64                  `json:"created_at"`
	Status       ContainerStatus        `json:"status,omitempty"`
	ExpiresAfter *ContainerExpiresAfter `json:"expires_after,omitempty"`
	LastActiveAt *int64                 `json:"last_active_at,omitempty"`
	MemoryLimit  string                 `json:"memory_limit,omitempty"`
	Metadata     map[string]string      `json:"metadata,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostContainerRetrieveResponse represents the response from retrieving a container.

type BifrostContext

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

BifrostContext is a custom context.Context implementation that tracks user-set values. It supports deadlines, can be derived from other contexts, and provides layered value inheritance when derived from another BifrostContext.

func NewBifrostContext

func NewBifrostContext(parent context.Context, deadline time.Time) *BifrostContext

NewBifrostContext creates a new BifrostContext with the given parent context and deadline. If the deadline is zero, no deadline is set on this context (though the parent may have one). The context will be cancelled when the deadline expires or when the parent context is cancelled.

func NewBifrostContextWithCancel

func NewBifrostContextWithCancel(parent context.Context) (*BifrostContext, context.CancelFunc)

NewBifrostContextWithCancel creates a new BifrostContext with a cancel function. This is a convenience wrapper around NewBifrostContext. Returns the context and a cancel function that should be called to release resources.

func NewBifrostContextWithTimeout

func NewBifrostContextWithTimeout(parent context.Context, timeout time.Duration) (*BifrostContext, context.CancelFunc)

NewBifrostContextWithTimeout creates a new BifrostContext with a timeout duration. This is a convenience wrapper around NewBifrostContext. Returns the context and a cancel function that should be called to release resources.

func NewBifrostContextWithValue

func NewBifrostContextWithValue(parent context.Context, deadline time.Time, key any, value any) *BifrostContext

NewBifrostContextWithValue creates a new BifrostContext with the given value set.

func (*BifrostContext) AppendRoutingEngineLog

func (bc *BifrostContext) AppendRoutingEngineLog(engineName string, message string)

AppendRoutingEngineLog appends a routing engine log entry to the context. Parameters:

  • ctx: The Bifrost context
  • engineName: Name of the routing engine (e.g., "governance", "routing-rule")
  • message: Human-readable log message describing the decision/action

func (*BifrostContext) BlockRestrictedWrites

func (bc *BifrostContext) BlockRestrictedWrites()

BlockRestrictedWrites returns true if restricted writes are blocked.

func (*BifrostContext) Cancel

func (bc *BifrostContext) Cancel()

Cancel cancels the context, closing the Done channel and setting the error to context.Canceled.

func (*BifrostContext) Deadline

func (bc *BifrostContext) Deadline() (time.Time, bool)

Deadline returns the deadline for this context. If both this context and the parent have deadlines, the earlier one is returned.

func (*BifrostContext) Done

func (bc *BifrostContext) Done() <-chan struct{}

Done returns a channel that is closed when the context is cancelled.

func (*BifrostContext) Err

func (bc *BifrostContext) Err() error

Err returns the error explaining why the context was cancelled. Returns nil if the context has not been cancelled.

func (*BifrostContext) GetAndSetValue

func (bc *BifrostContext) GetAndSetValue(key any, value any) any

GetAndSetValue gets a value from the internal userValues map and sets it

func (*BifrostContext) GetParentCtxWithUserValues

func (bc *BifrostContext) GetParentCtxWithUserValues() context.Context

GetParentCtxWithUserValues returns a copy of the parent context with all user-set values merged in.

func (*BifrostContext) GetRoutingEngineLogs

func (bc *BifrostContext) GetRoutingEngineLogs() []RoutingEngineLogEntry

GetRoutingEngineLogs retrieves all routing engine logs from the context. Parameters:

  • ctx: The Bifrost context

Returns:

  • []RoutingEngineLogEntry: Slice of routing engine log entries (nil if none)

func (*BifrostContext) GetUserValues

func (bc *BifrostContext) GetUserValues() map[any]any

GetUserValues returns a copy of all user-set values in this context. If the parent is also a PluginContext, the values are merged with parent values (this context's values take precedence over parent values).

func (*BifrostContext) SetValue

func (bc *BifrostContext) SetValue(key, value any)

SetValue sets a value in the internal userValues map. This is thread-safe and can be called concurrently.

func (*BifrostContext) UnblockRestrictedWrites

func (bc *BifrostContext) UnblockRestrictedWrites()

UnblockRestrictedWrites unblocks restricted writes.

func (*BifrostContext) Value

func (bc *BifrostContext) Value(key any) any

Value returns the value associated with the key. It first checks the internal userValues map, then delegates to the parent context.

func (*BifrostContext) WithValue

func (bc *BifrostContext) WithValue(key any, value any) *BifrostContext

WithValue returns a new context with the given value set.

type BifrostContextKey

type BifrostContextKey string

BifrostContextKey is a type for context keys used in Bifrost.

const (
	BifrostContextKeyVirtualKey                          BifrostContextKey = "x-bf-vk"                              // string
	BifrostContextKeyAPIKeyName                          BifrostContextKey = "x-bf-api-key"                         // string (explicit key name selection)
	BifrostContextKeyRequestID                           BifrostContextKey = "request-id"                           // string
	BifrostContextKeyFallbackRequestID                   BifrostContextKey = "fallback-request-id"                  // string
	BifrostContextKeyDirectKey                           BifrostContextKey = "bifrost-direct-key"                   // Key struct
	BifrostContextKeySelectedKeyID                       BifrostContextKey = "bifrost-selected-key-id"              // string (to store the selected key ID (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeySelectedKeyName                     BifrostContextKey = "bifrost-selected-key-name"            // string (to store the selected key name (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceVirtualKeyID              BifrostContextKey = "bifrost-governance-virtual-key-id"    // string (to store the virtual key ID (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceVirtualKeyName            BifrostContextKey = "bifrost-governance-virtual-key-name"  // string (to store the virtual key name (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceTeamID                    BifrostContextKey = "bifrost-governance-team-id"           // string (to store the team ID (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceTeamName                  BifrostContextKey = "bifrost-governance-team-name"         // string (to store the team name (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceCustomerID                BifrostContextKey = "bifrost-governance-customer-id"       // string (to store the customer ID (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceCustomerName              BifrostContextKey = "bifrost-governance-customer-name"     // string (to store the customer name (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceUserID                    BifrostContextKey = "bifrost-governance-user-id"           // string (to store the user ID (set by enterprise governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceRoutingRuleID             BifrostContextKey = "bifrost-governance-routing-rule-id"   // string (to store the routing rule ID (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceRoutingRuleName           BifrostContextKey = "bifrost-governance-routing-rule-name" // string (to store the routing rule name (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernanceIncludeOnlyKeys           BifrostContextKey = "bf-governance-include-only-keys"      // []string (to store the include-only key IDs for provider config routing (set by bifrost governance plugin - DO NOT SET THIS MANUALLY))
	BifrostContextKeyNumberOfRetries                     BifrostContextKey = "bifrost-number-of-retries"            // int (to store the number of retries (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyFallbackIndex                       BifrostContextKey = "bifrost-fallback-index"               // int (to store the fallback index (set by bifrost - DO NOT SET THIS MANUALLY)) 0 for primary, 1 for first fallback, etc.
	BifrostContextKeyStreamEndIndicator                  BifrostContextKey = "bifrost-stream-end-indicator"         // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeySkipKeySelection                    BifrostContextKey = "bifrost-skip-key-selection"           // bool (will pass an empty key to the provider)
	BifrostContextKeyExtraHeaders                        BifrostContextKey = "bifrost-extra-headers"                // map[string][]string
	BifrostContextKeyURLPath                             BifrostContextKey = "bifrost-extra-url-path"               // string
	BifrostContextKeyUseRawRequestBody                   BifrostContextKey = "bifrost-use-raw-request-body"
	BifrostContextKeySendBackRawRequest                  BifrostContextKey = "bifrost-send-back-raw-request"                    // bool
	BifrostContextKeySendBackRawResponse                 BifrostContextKey = "bifrost-send-back-raw-response"                   // bool
	BifrostContextKeyIntegrationType                     BifrostContextKey = "bifrost-integration-type"                         // integration used in gateway (e.g. openai, anthropic, bedrock, etc.)
	BifrostContextKeyIsResponsesToChatCompletionFallback BifrostContextKey = "bifrost-is-responses-to-chat-completion-fallback" // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostMCPAgentOriginalRequestID                     BifrostContextKey = "bifrost-mcp-agent-original-request-id"            // string (to store the original request ID for MCP agent mode)
	BifrostContextKeyParentMCPRequestID                  BifrostContextKey = "bf-parent-mcp-request-id"                         // string (parent request ID for nested tool calls from executeCode)
	BifrostContextKeyStructuredOutputToolName            BifrostContextKey = "bifrost-structured-output-tool-name"              // string (to store the name of the structured output tool (set by bifrost))
	BifrostContextKeyUserAgent                           BifrostContextKey = "bifrost-user-agent"                               // string (set by bifrost)
	BifrostContextKeyTraceID                             BifrostContextKey = "bifrost-trace-id"                                 // string (trace ID for distributed tracing - set by tracing middleware)
	BifrostContextKeySpanID                              BifrostContextKey = "bifrost-span-id"                                  // string (current span ID for child span creation - set by tracer)
	BifrostContextKeyParentSpanID                        BifrostContextKey = "bifrost-parent-span-id"                           // string (parent span ID from W3C traceparent header - set by tracing middleware)
	BifrostContextKeyStreamStartTime                     BifrostContextKey = "bifrost-stream-start-time"                        // time.Time (start time for streaming TTFT calculation - set by bifrost)
	BifrostContextKeyTracer                              BifrostContextKey = "bifrost-tracer"                                   // Tracer (tracer instance for completing deferred spans - set by bifrost)
	BifrostContextKeyDeferTraceCompletion                BifrostContextKey = "bifrost-defer-trace-completion"                   // bool (signals trace completion should be deferred for streaming - set by streaming handlers)
	BifrostContextKeyTraceCompleter                      BifrostContextKey = "bifrost-trace-completer"                          // func() (callback to complete trace after streaming - set by tracing middleware)
	BifrostContextKeyPostHookSpanFinalizer               BifrostContextKey = "bifrost-posthook-span-finalizer"                  // func(context.Context) (callback to finalize post-hook spans after streaming - set by bifrost)
	BifrostContextKeyAccumulatorID                       BifrostContextKey = "bifrost-accumulator-id"                           // string (ID for streaming accumulator lookup - set by tracer for accumulator operations)
	BifrostContextKeySkipDBUpdate                        BifrostContextKey = "bifrost-skip-db-update"                           // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyGovernancePluginName                BifrostContextKey = "governance-plugin-name"                           // string (name of the governance plugin that processed the request - set by bifrost)
	BifrostContextKeyIsEnterprise                        BifrostContextKey = "is-enterprise"                                    // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyAvailableProviders                  BifrostContextKey = "available-providers"                              // []ModelProvider (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyRawRequestResponseForLogging        BifrostContextKey = "bifrost-raw-request-response-for-logging"         // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyRetryDBFetch                        BifrostContextKey = "bifrost-retry-db-fetch"                           // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyIsCustomProvider                    BifrostContextKey = "bifrost-is-custom-provider"                       // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyHTTPRequestType                     BifrostContextKey = "bifrost-http-request-type"                        // RequestType (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeyPassthroughExtraParams              BifrostContextKey = "bifrost-passthrough-extra-params"                 // bool
	BifrostContextKeyRoutingEnginesUsed                  BifrostContextKey = "bifrost-routing-engines-used"                     // []string (set by bifrost - DO NOT SET THIS MANUALLY) - list of routing engines used ("routing-rule", "governance", "loadbalancing", etc.)
	BifrostContextKeyRoutingEngineLogs                   BifrostContextKey = "bifrost-routing-engine-logs"                      // []RoutingEngineLogEntry (set by bifrost - DO NOT SET THIS MANUALLY) - list of routing engine log entries
	BifrostContextKeySkipPluginPipeline                  BifrostContextKey = "bifrost-skip-plugin-pipeline"                     // bool - skip plugin pipeline for the request
	BifrostIsAsyncRequest                                BifrostContextKey = "bifrost-is-async-request"                         // bool (set by bifrost - DO NOT SET THIS MANUALLY)) - whether the request is an async request (only used in gateway)
	BifrostContextKeyRequestHeaders                      BifrostContextKey = "bifrost-request-headers"                          // map[string]string (all request headers with lowercased keys)
	BifrostContextKeySkipListModelsGovernanceFiltering   BifrostContextKey = "bifrost-skip-list-models-governance-filtering"    // bool (set by bifrost - DO NOT SET THIS MANUALLY))
	BifrostContextKeySCIMClaims                          BifrostContextKey = "scim_claims"
	BifrostContextKeyUserID                              BifrostContextKey = "user_id"
	BifrostContextKeyTargetUserID                        BifrostContextKey = "target_user_id"
	BifrostContextKeyIsAzureUserAgent                    BifrostContextKey = "bifrost-is-azure-user-agent" // bool (set by bifrost - DO NOT SET THIS MANUALLY)) - whether the request is an Azure user agent (only used in gateway)
	BifrostContextKeyVideoOutputRequested                BifrostContextKey = "bifrost-video-output-requested"
)

BifrostContextKeyRequestType is a context key for the request type.

type BifrostCost

type BifrostCost struct {
	InputTokensCost     float64 `json:"input_tokens_cost,omitempty"`
	OutputTokensCost    float64 `json:"output_tokens_cost,omitempty"`
	ReasoningTokensCost float64 `json:"reasoning_tokens_cost,omitempty"`
	CitationTokensCost  float64 `json:"citation_tokens_cost,omitempty"`
	SearchQueriesCost   float64 `json:"search_queries_cost,omitempty"`
	RequestCost         float64 `json:"request_cost,omitempty"`
	TotalCost           float64 `json:"total_cost,omitempty"`
}

func (*BifrostCost) UnmarshalJSON

func (bc *BifrostCost) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for BifrostCost.

type BifrostCountTokensResponse

type BifrostCountTokensResponse struct {
	Object             string                        `json:"object,omitempty"`
	Model              string                        `json:"model"`
	InputTokens        int                           `json:"input_tokens"`
	InputTokensDetails *ResponsesResponseInputTokens `json:"input_tokens_details,omitempty"`
	Tokens             []int                         `json:"tokens"`
	TokenStrings       []string                      `json:"token_strings,omitempty"`
	OutputTokens       *int                          `json:"output_tokens,omitempty"`
	TotalTokens        *int                          `json:"total_tokens"`
	ExtraFields        BifrostResponseExtraFields    `json:"extra_fields"`
}

BifrostCountTokensResponse captures token counts for a provided input.

type BifrostEmbeddingRequest

type BifrostEmbeddingRequest struct {
	Provider       ModelProvider        `json:"provider"`
	Model          string               `json:"model"`
	Input          *EmbeddingInput      `json:"input,omitempty"`
	Params         *EmbeddingParameters `json:"params,omitempty"`
	Fallbacks      []Fallback           `json:"fallbacks,omitempty"`
	RawRequestBody []byte               `json:"-"` // set bifrost-use-raw-request-body to true in ctx to use the raw request body. Bifrost will directly send this to the downstream provider.
}

func (*BifrostEmbeddingRequest) GetRawRequestBody

func (r *BifrostEmbeddingRequest) GetRawRequestBody() []byte

type BifrostEmbeddingResponse

type BifrostEmbeddingResponse struct {
	Data        []EmbeddingData            `json:"data"` // Maps to "data" field in provider responses (e.g., OpenAI embedding format)
	Model       string                     `json:"model"`
	Object      string                     `json:"object"` // "list"
	Usage       *BifrostLLMUsage           `json:"usage"`
	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostError

type BifrostError struct {
	EventID        *string                 `json:"event_id,omitempty"`
	Type           *string                 `json:"type,omitempty"`
	IsBifrostError bool                    `json:"is_bifrost_error"`
	StatusCode     *int                    `json:"status_code,omitempty"`
	Error          *ErrorField             `json:"error"`
	AllowFallbacks *bool                   `json:"-"` // Optional: Controls fallback behavior (nil = true by default)
	StreamControl  *StreamControl          `json:"-"` // Optional: Controls stream behavior
	ExtraFields    BifrostErrorExtraFields `json:"extra_fields"`
}

BifrostError represents an error from the Bifrost system.

PLUGIN DEVELOPERS: When creating BifrostError in PreLLMHook or PostLLMHook, you can set AllowFallbacks: - AllowFallbacks = &true: Bifrost will try fallback providers if available - AllowFallbacks = &false: Bifrost will return this error immediately, no fallbacks - AllowFallbacks = nil: Treated as true by default (fallbacks allowed for resilience)

type BifrostErrorExtraFields

type BifrostErrorExtraFields struct {
	Provider       ModelProvider `json:"provider,omitempty"`
	ModelRequested string        `json:"model_requested,omitempty"`
	RequestType    RequestType   `json:"request_type,omitempty"`
	RawRequest     interface{}   `json:"raw_request,omitempty"`
	RawResponse    interface{}   `json:"raw_response,omitempty"`
	LiteLLMCompat  bool          `json:"litellm_compat,omitempty"`
	KeyStatuses    []KeyStatus   `json:"key_statuses,omitempty"`
}

BifrostErrorExtraFields contains additional fields in an error response.

type BifrostFileContentRequest

type BifrostFileContentRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`
	FileID   string        `json:"file_id"` // ID of the file to download

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	// Storage configuration (for S3/GCS backends)
	StorageConfig *FileStorageConfig `json:"storage_config,omitempty"`

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostFileContentRequest represents a request to download file content.

func (*BifrostFileContentRequest) GetRawRequestBody

func (request *BifrostFileContentRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostFileContentResponse

type BifrostFileContentResponse struct {
	FileID      string `json:"file_id"`
	Content     []byte `json:"-"`                      // Raw file content (not serialized)
	ContentType string `json:"content_type,omitempty"` // MIME type

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostFileContentResponse represents the response from downloading file content.

type BifrostFileDeleteRequest

type BifrostFileDeleteRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`
	FileID   string        `json:"file_id"` // ID of the file to delete

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	// Storage configuration (for S3/GCS backends)
	StorageConfig *FileStorageConfig `json:"storage_config,omitempty"`

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostFileDeleteRequest represents a request to delete a file.

func (*BifrostFileDeleteRequest) GetRawRequestBody

func (request *BifrostFileDeleteRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostFileDeleteResponse

type BifrostFileDeleteResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object,omitempty"` // "file"
	Deleted bool   `json:"deleted"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostFileDeleteResponse represents the response from deleting a file.

type BifrostFileListRequest

type BifrostFileListRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	// Filters
	Purpose FilePurpose `json:"purpose,omitempty"` // Filter by purpose

	// Pagination
	Limit int     `json:"limit,omitempty"` // Max results to return
	After *string `json:"after,omitempty"` // Cursor for pagination
	Order *string `json:"order,omitempty"` // Sort order (asc/desc)

	// Storage configuration (for S3/GCS backends)
	StorageConfig *FileStorageConfig `json:"storage_config,omitempty"`

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostFileListRequest represents a request to list files.

func (*BifrostFileListRequest) GetRawRequestBody

func (request *BifrostFileListRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostFileListResponse

type BifrostFileListResponse struct {
	Object  string       `json:"object,omitempty"` // "list"
	Data    []FileObject `json:"data"`
	HasMore bool         `json:"has_more,omitempty"`
	After   *string      `json:"after,omitempty"` // Continuation token for pagination

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostFileListResponse represents the response from listing files.

type BifrostFileRetrieveRequest

type BifrostFileRetrieveRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`

	RawRequestBody []byte `json:"-"` // Raw request body (not serialized)

	FileID string `json:"file_id"` // ID of the file to retrieve

	// Storage configuration (for S3/GCS backends)
	StorageConfig *FileStorageConfig `json:"storage_config,omitempty"`

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostFileRetrieveRequest represents a request to retrieve file metadata.

func (*BifrostFileRetrieveRequest) GetRawRequestBody

func (request *BifrostFileRetrieveRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body.

type BifrostFileRetrieveResponse

type BifrostFileRetrieveResponse struct {
	ID            string      `json:"id"`
	Object        string      `json:"object,omitempty"` // "file"
	Bytes         int64       `json:"bytes"`
	CreatedAt     int64       `json:"created_at"`
	Filename      string      `json:"filename"`
	Purpose       FilePurpose `json:"purpose"`
	Status        FileStatus  `json:"status,omitempty"`
	StatusDetails *string     `json:"status_details,omitempty"`
	ExpiresAt     *int64      `json:"expires_at,omitempty"`

	// Storage backend info
	StorageBackend FileStorageBackend `json:"storage_backend,omitempty"`
	StorageURI     string             `json:"storage_uri,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostFileRetrieveResponse represents the response from retrieving file metadata.

type BifrostFileUploadRequest

type BifrostFileUploadRequest struct {
	Provider ModelProvider `json:"provider"`
	Model    *string       `json:"model"`

	// File content
	File        []byte      `json:"-"`                      // Raw file content (not serialized)
	Filename    string      `json:"filename"`               // Original filename
	Purpose     FilePurpose `json:"purpose"`                // Purpose of the file (e.g., "batch")
	ContentType *string     `json:"content_type,omitempty"` // MIME type of the file

	// Storage configuration (for S3/GCS backends)
	StorageConfig *FileStorageConfig `json:"storage_config,omitempty"`

	// Expiration configuration (OpenAI only)
	ExpiresAfter *FileExpiresAfter `json:"expires_after,omitempty"`

	// Extra parameters for provider-specific features
	ExtraParams map[string]interface{} `json:"-"`
}

BifrostFileUploadRequest represents a request to upload a file.

type BifrostFileUploadResponse

type BifrostFileUploadResponse struct {
	ID            string      `json:"id"`
	Object        string      `json:"object,omitempty"` // "file"
	Bytes         int64       `json:"bytes"`
	CreatedAt     int64       `json:"created_at"`
	Filename      string      `json:"filename"`
	Purpose       FilePurpose `json:"purpose"`
	Status        FileStatus  `json:"status,omitempty"`
	StatusDetails *string     `json:"status_details,omitempty"`
	ExpiresAt     *int64      `json:"expires_at,omitempty"`

	// Storage backend info
	StorageBackend FileStorageBackend `json:"storage_backend,omitempty"`
	StorageURI     string             `json:"storage_uri,omitempty"` // S3/GCS URI if applicable

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostFileUploadResponse represents the response from uploading a file.

type BifrostFinishReason

type BifrostFinishReason string

BifrostFinishReason represents the reason why the model stopped generating.

const (
	BifrostFinishReasonStop      BifrostFinishReason = "stop"
	BifrostFinishReasonLength    BifrostFinishReason = "length"
	BifrostFinishReasonToolCalls BifrostFinishReason = "tool_calls"
)

BifrostFinishReason values

type BifrostHTTPMiddleware

type BifrostHTTPMiddleware func(next fasthttp.RequestHandler) fasthttp.RequestHandler

BifrostHTTPMiddleware is a middleware function for the Bifrost HTTP transport. It follows the standard pattern: receives the next handler and returns a new handler. Used internally for CORS, Auth, Tracing middleware. Plugins use HTTPTransportIntercept instead.

type BifrostImageEditRequest

type BifrostImageEditRequest struct {
	Provider       ModelProvider        `json:"provider"`
	Model          string               `json:"model"`
	Input          *ImageEditInput      `json:"input"`
	Params         *ImageEditParameters `json:"params,omitempty"`
	Fallbacks      []Fallback           `json:"fallbacks,omitempty"`
	RawRequestBody []byte               `json:"-"`
}

BifrostImageEditRequest represents an image edit request in bifrost format

func (*BifrostImageEditRequest) GetRawRequestBody

func (b *BifrostImageEditRequest) GetRawRequestBody() []byte

GetRawRequestBody implements [utils.RequestBodyGetter].

type BifrostImageGenerationRequest

type BifrostImageGenerationRequest struct {
	Provider       ModelProvider              `json:"provider"`
	Model          string                     `json:"model"`
	Input          *ImageGenerationInput      `json:"input"`
	Params         *ImageGenerationParameters `json:"params,omitempty"`
	Fallbacks      []Fallback                 `json:"fallbacks,omitempty"`
	RawRequestBody []byte                     `json:"-"`
}

BifrostImageGenerationRequest represents an image generation request in bifrost format

func (*BifrostImageGenerationRequest) GetRawRequestBody

func (b *BifrostImageGenerationRequest) GetRawRequestBody() []byte

GetRawRequestBody implements utils.RequestBodyGetter.

type BifrostImageGenerationResponse

type BifrostImageGenerationResponse struct {
	ID      string      `json:"id,omitempty"`
	Created int64       `json:"created,omitempty"`
	Model   string      `json:"model,omitempty"`
	Data    []ImageData `json:"data"`

	*ImageGenerationResponseParameters

	Usage       *ImageUsage                `json:"usage,omitempty"`
	ExtraFields BifrostResponseExtraFields `json:"extra_fields,omitempty"`
}

BifrostImageGenerationResponse represents the image generation response in bifrost format

type BifrostImageGenerationStreamResponse

type BifrostImageGenerationStreamResponse struct {
	ID                string                     `json:"id,omitempty"`
	Type              ImageEventType             `json:"type,omitempty"`
	Index             int                        `json:"-"` // Which image (0-N)
	ChunkIndex        int                        `json:"-"` // Chunk order within image
	PartialImageIndex *int                       `json:"partial_image_index,omitempty"`
	SequenceNumber    int                        `json:"sequence_number,omitempty"`
	B64JSON           string                     `json:"b64_json,omitempty"`
	URL               string                     `json:"url,omitempty"`
	CreatedAt         int64                      `json:"created_at,omitempty"`
	Size              string                     `json:"size,omitempty"`
	Quality           string                     `json:"quality,omitempty"`
	Background        string                     `json:"background,omitempty"`
	OutputFormat      string                     `json:"output_format,omitempty"`
	RevisedPrompt     string                     `json:"revised_prompt,omitempty"`
	Usage             *ImageUsage                `json:"usage,omitempty"`
	Error             *BifrostError              `json:"error,omitempty"`
	RawRequest        string                     `json:"-"`
	RawResponse       string                     `json:"-"`
	ExtraFields       BifrostResponseExtraFields `json:"extra_fields,omitempty"`
}

Streaming Response

type BifrostImageVariationRequest

type BifrostImageVariationRequest struct {
	Provider       ModelProvider             `json:"provider"`
	Model          string                    `json:"model"`
	Input          *ImageVariationInput      `json:"input"`
	Params         *ImageVariationParameters `json:"params,omitempty"`
	Fallbacks      []Fallback                `json:"fallbacks,omitempty"`
	RawRequestBody []byte                    `json:"-"`
}

BifrostImageVariationRequest represents an image variation request in bifrost format

func (*BifrostImageVariationRequest) GetRawRequestBody

func (b *BifrostImageVariationRequest) GetRawRequestBody() []byte

GetRawRequestBody implements [utils.RequestBodyGetter].

type BifrostImageVariationResponse

type BifrostImageVariationResponse = BifrostImageGenerationResponse

BifrostImageVariationResponse represents the image variation response in bifrost format It uses the same structure as image generation response

type BifrostLLMUsage

type BifrostLLMUsage struct {
	PromptTokens            int                          `json:"prompt_tokens,omitempty"`
	PromptTokensDetails     *ChatPromptTokensDetails     `json:"prompt_tokens_details,omitempty"`
	CompletionTokens        int                          `json:"completion_tokens,omitempty"`
	CompletionTokensDetails *ChatCompletionTokensDetails `json:"completion_tokens_details,omitempty"`
	TotalTokens             int                          `json:"total_tokens"`
	Cost                    *BifrostCost                 `json:"cost,omitempty"` //Only for the providers which support cost calculation
}

BifrostLLMUsage represents token usage information

func (*BifrostLLMUsage) ToResponsesResponseUsage

func (cu *BifrostLLMUsage) ToResponsesResponseUsage() *ResponsesResponseUsage

type BifrostListModelsRequest

type BifrostListModelsRequest struct {
	Provider ModelProvider `json:"provider"`

	PageSize int `json:"page_size"`

	// PageToken: Token received from previous request to retrieve next page
	PageToken string `json:"page_token"`

	// Unfiltered: If true, the response will include all models for the provider, regardless of the allowed models (internal bifrost use only, not sent to the provider)
	Unfiltered bool `json:"-"`

	// ExtraParams: Additional provider-specific query parameters
	// This allows for flexibility to pass any custom parameters that specific providers might support
	ExtraParams map[string]interface{} `json:"-"`
}

type BifrostListModelsResponse

type BifrostListModelsResponse struct {
	Data          []Model                    `json:"data"`
	ExtraFields   BifrostResponseExtraFields `json:"extra_fields"`
	NextPageToken string                     `json:"next_page_token,omitempty"` // Token to retrieve next page

	// Key-level status tracking for multi-key providers
	KeyStatuses []KeyStatus `json:"key_statuses,omitempty"`

	// Anthropic specific fields
	FirstID *string `json:"-"`
	LastID  *string `json:"-"`
	HasMore *bool   `json:"-"`
}

func (*BifrostListModelsResponse) ApplyPagination

func (response *BifrostListModelsResponse) ApplyPagination(pageSize int, pageToken string) *BifrostListModelsResponse

ApplyPagination applies offset-based pagination to a BifrostListModelsResponse. Uses opaque tokens with LastID validation to ensure cursor integrity. Returns the paginated response with properly set NextPageToken.

type BifrostLogProbs

type BifrostLogProbs struct {
	Content []ContentLogProb `json:"content,omitempty"`
	Refusal []LogProb        `json:"refusal,omitempty"`

	*TextCompletionLogProb
}

BifrostLogProbs represents the log probabilities for different aspects of a response.

type BifrostMCPRequest

type BifrostMCPRequest struct {
	RequestType MCPRequestType

	*ChatAssistantMessageToolCall
	*ResponsesToolMessage
}

BifrostMCPRequest is the request struct for all MCP requests. only ONE of the following fields should be set: - ChatAssistantMessageToolCall - ResponsesToolMessage

func (*BifrostMCPRequest) GetToolArguments

func (r *BifrostMCPRequest) GetToolArguments() interface{}

func (*BifrostMCPRequest) GetToolName

func (r *BifrostMCPRequest) GetToolName() string

type BifrostMCPResponse

type BifrostMCPResponse struct {
	ChatMessage      *ChatMessage
	ResponsesMessage *ResponsesMessage
	ExtraFields      BifrostMCPResponseExtraFields
}

BifrostMCPResponse is the response struct for all MCP responses. only ONE of the following fields should be set: - ChatMessage - ResponsesMessage

type BifrostMCPResponseExtraFields

type BifrostMCPResponseExtraFields struct {
	ClientName string `json:"client_name"`
	ToolName   string `json:"tool_name"`
	Latency    int64  `json:"latency"` // in milliseconds
}

type BifrostReasoningDetailsType

type BifrostReasoningDetailsType string
const (
	BifrostReasoningDetailsTypeSummary   BifrostReasoningDetailsType = "reasoning.summary"
	BifrostReasoningDetailsTypeEncrypted BifrostReasoningDetailsType = "reasoning.encrypted"
	BifrostReasoningDetailsTypeText      BifrostReasoningDetailsType = "reasoning.text"
)

type BifrostRequest

type BifrostRequest struct {
	RequestType RequestType

	ListModelsRequest            *BifrostListModelsRequest
	TextCompletionRequest        *BifrostTextCompletionRequest
	ChatRequest                  *BifrostChatRequest
	ResponsesRequest             *BifrostResponsesRequest
	CountTokensRequest           *BifrostResponsesRequest
	EmbeddingRequest             *BifrostEmbeddingRequest
	RerankRequest                *BifrostRerankRequest
	SpeechRequest                *BifrostSpeechRequest
	TranscriptionRequest         *BifrostTranscriptionRequest
	ImageGenerationRequest       *BifrostImageGenerationRequest
	ImageEditRequest             *BifrostImageEditRequest
	ImageVariationRequest        *BifrostImageVariationRequest
	VideoGenerationRequest       *BifrostVideoGenerationRequest
	VideoRetrieveRequest         *BifrostVideoRetrieveRequest
	VideoDownloadRequest         *BifrostVideoDownloadRequest
	VideoListRequest             *BifrostVideoListRequest
	VideoRemixRequest            *BifrostVideoRemixRequest
	VideoDeleteRequest           *BifrostVideoDeleteRequest
	FileUploadRequest            *BifrostFileUploadRequest
	FileListRequest              *BifrostFileListRequest
	FileRetrieveRequest          *BifrostFileRetrieveRequest
	FileDeleteRequest            *BifrostFileDeleteRequest
	FileContentRequest           *BifrostFileContentRequest
	BatchCreateRequest           *BifrostBatchCreateRequest
	BatchListRequest             *BifrostBatchListRequest
	BatchRetrieveRequest         *BifrostBatchRetrieveRequest
	BatchCancelRequest           *BifrostBatchCancelRequest
	BatchResultsRequest          *BifrostBatchResultsRequest
	ContainerCreateRequest       *BifrostContainerCreateRequest
	ContainerListRequest         *BifrostContainerListRequest
	ContainerRetrieveRequest     *BifrostContainerRetrieveRequest
	ContainerDeleteRequest       *BifrostContainerDeleteRequest
	ContainerFileCreateRequest   *BifrostContainerFileCreateRequest
	ContainerFileListRequest     *BifrostContainerFileListRequest
	ContainerFileRetrieveRequest *BifrostContainerFileRetrieveRequest
	ContainerFileContentRequest  *BifrostContainerFileContentRequest
	ContainerFileDeleteRequest   *BifrostContainerFileDeleteRequest
}

BifrostRequest is the request struct for all bifrost requests. only ONE of the following fields should be set: - ListModelsRequest - TextCompletionRequest - ChatRequest - ResponsesRequest - CountTokensRequest - EmbeddingRequest - RerankRequest - SpeechRequest - TranscriptionRequest - ImageGenerationRequest NOTE: Bifrost Request is submitted back to pool after every use so DO NOT keep references to this struct after use, especially in go routines.

func (*BifrostRequest) GetRequestFields

func (br *BifrostRequest) GetRequestFields() (provider ModelProvider, model string, fallbacks []Fallback)

GetRequestFields returns the provider, model, and fallbacks from the request.

func (*BifrostRequest) SetFallbacks

func (br *BifrostRequest) SetFallbacks(fallbacks []Fallback)

func (*BifrostRequest) SetModel

func (br *BifrostRequest) SetModel(model string)

func (*BifrostRequest) SetProvider

func (br *BifrostRequest) SetProvider(provider ModelProvider)

func (*BifrostRequest) SetRawRequestBody

func (br *BifrostRequest) SetRawRequestBody(rawRequestBody []byte)

type BifrostRerankRequest

type BifrostRerankRequest struct {
	Provider       ModelProvider     `json:"provider"`
	Model          string            `json:"model"`
	Query          string            `json:"query"`
	Documents      []RerankDocument  `json:"documents"`
	Params         *RerankParameters `json:"params,omitempty"`
	Fallbacks      []Fallback        `json:"fallbacks,omitempty"`
	RawRequestBody []byte            `json:"-"`
}

BifrostRerankRequest represents a request to rerank documents by relevance to a query.

func (*BifrostRerankRequest) GetRawRequestBody

func (r *BifrostRerankRequest) GetRawRequestBody() []byte

GetRawRequestBody returns the raw request body for the rerank request.

type BifrostRerankResponse

type BifrostRerankResponse struct {
	ID          string                     `json:"id,omitempty"`
	Results     []RerankResult             `json:"results"`
	Model       string                     `json:"model"`
	Usage       *BifrostLLMUsage           `json:"usage,omitempty"`
	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

BifrostRerankResponse represents the response from a rerank request.

type BifrostResponse

type BifrostResponse struct {
	ListModelsResponse            *BifrostListModelsResponse
	TextCompletionResponse        *BifrostTextCompletionResponse
	ChatResponse                  *BifrostChatResponse
	ResponsesResponse             *BifrostResponsesResponse
	ResponsesStreamResponse       *BifrostResponsesStreamResponse
	CountTokensResponse           *BifrostCountTokensResponse
	EmbeddingResponse             *BifrostEmbeddingResponse
	RerankResponse                *BifrostRerankResponse
	SpeechResponse                *BifrostSpeechResponse
	SpeechStreamResponse          *BifrostSpeechStreamResponse
	TranscriptionResponse         *BifrostTranscriptionResponse
	TranscriptionStreamResponse   *BifrostTranscriptionStreamResponse
	ImageGenerationResponse       *BifrostImageGenerationResponse
	ImageGenerationStreamResponse *BifrostImageGenerationStreamResponse
	VideoGenerationResponse       *BifrostVideoGenerationResponse
	VideoDownloadResponse         *BifrostVideoDownloadResponse
	VideoListResponse             *BifrostVideoListResponse
	VideoDeleteResponse           *BifrostVideoDeleteResponse
	FileUploadResponse            *BifrostFileUploadResponse
	FileListResponse              *BifrostFileListResponse
	FileRetrieveResponse          *BifrostFileRetrieveResponse
	FileDeleteResponse            *BifrostFileDeleteResponse
	FileContentResponse           *BifrostFileContentResponse
	BatchCreateResponse           *BifrostBatchCreateResponse
	BatchListResponse             *BifrostBatchListResponse
	BatchRetrieveResponse         *BifrostBatchRetrieveResponse
	BatchCancelResponse           *BifrostBatchCancelResponse
	BatchResultsResponse          *BifrostBatchResultsResponse
	ContainerCreateResponse       *BifrostContainerCreateResponse
	ContainerListResponse         *BifrostContainerListResponse
	ContainerRetrieveResponse     *BifrostContainerRetrieveResponse
	ContainerDeleteResponse       *BifrostContainerDeleteResponse
	ContainerFileCreateResponse   *BifrostContainerFileCreateResponse
	ContainerFileListResponse     *BifrostContainerFileListResponse
	ContainerFileRetrieveResponse *BifrostContainerFileRetrieveResponse
	ContainerFileContentResponse  *BifrostContainerFileContentResponse
	ContainerFileDeleteResponse   *BifrostContainerFileDeleteResponse
}

BifrostResponse represents the complete result from any bifrost request.

func (*BifrostResponse) GetExtraFields

func (r *BifrostResponse) GetExtraFields() *BifrostResponseExtraFields

type BifrostResponseChoice

type BifrostResponseChoice struct {
	Index        int              `json:"index"`
	FinishReason *string          `json:"finish_reason,omitempty"`
	LogProbs     *BifrostLogProbs `json:"log_probs,omitempty"`

	*TextCompletionResponseChoice
	*ChatNonStreamResponseChoice
	*ChatStreamResponseChoice
}

BifrostResponseChoice represents a choice in the completion result. This struct can represent either a streaming or non-streaming response choice. IMPORTANT: Only one of TextCompletionResponseChoice, NonStreamResponseChoice or StreamResponseChoice should be non-nil at a time.

type BifrostResponseExtraFields

type BifrostResponseExtraFields struct {
	RequestType     RequestType        `json:"request_type"`
	Provider        ModelProvider      `json:"provider,omitempty"`
	ModelRequested  string             `json:"model_requested,omitempty"`
	ModelDeployment string             `json:"model_deployment,omitempty"` // only present for providers which use model deployments (e.g. Azure, Bedrock)
	Latency         int64              `json:"latency"`                    // in milliseconds (for streaming responses this will be each chunk latency, and the last chunk latency will be the total latency)
	ChunkIndex      int                `json:"chunk_index"`                // used for streaming responses to identify the chunk index, will be 0 for non-streaming responses
	RawRequest      interface{}        `json:"raw_request,omitempty"`
	RawResponse     interface{}        `json:"raw_response,omitempty"`
	CacheDebug      *BifrostCacheDebug `json:"cache_debug,omitempty"`
	ParseErrors     []BatchError       `json:"parse_errors,omitempty"` // errors encountered while parsing JSONL batch results
	LiteLLMCompat   bool               `json:"litellm_compat,omitempty"`
}

BifrostResponseExtraFields contains additional fields in a response.

type BifrostResponsesRequest

type BifrostResponsesRequest struct {
	Provider       ModelProvider        `json:"provider"`
	Model          string               `json:"model"`
	Input          []ResponsesMessage   `json:"input,omitempty"`
	Params         *ResponsesParameters `json:"params,omitempty"`
	Fallbacks      []Fallback           `json:"fallbacks,omitempty"`
	RawRequestBody []byte               `json:"-"` // set bifrost-use-raw-request-body to true in ctx to use the raw request body. Bifrost will directly send this to the downstream provider.
}

func (*BifrostResponsesRequest) GetRawRequestBody

func (r *BifrostResponsesRequest) GetRawRequestBody() []byte

func (*BifrostResponsesRequest) ToChatRequest

func (brr *BifrostResponsesRequest) ToChatRequest() *BifrostChatRequest

ToChatRequest converts a BifrostResponsesRequest to BifrostChatRequest format

type BifrostResponsesResponse

type BifrostResponsesResponse struct {
	ID     *string `json:"id,omitempty"` // used for internal conversions
	Object string  `json:"object"`       // "response"

	Background         *bool                               `json:"background,omitempty"`
	Conversation       *ResponsesResponseConversation      `json:"conversation,omitempty"`
	CreatedAt          int                                 `json:"created_at"`   // Unix timestamp when Response was created
	CompletedAt        *int                                `json:"completed_at"` // Unix timestamp when Response was completed
	Error              *ResponsesResponseError             `json:"error"`
	Include            []string                            `json:"include,omitempty"`  // Supported values: "web_search_call.action.sources", "code_interpreter_call.outputs", "computer_call_output.output.image_url", "file_search_call.results", "message.input_image.image_url", "message.output_text.logprobs", "reasoning.encrypted_content"
	IncompleteDetails  *ResponsesResponseIncompleteDetails `json:"incomplete_details"` // Details about why the response is incomplete
	Instructions       *ResponsesResponseInstructions      `json:"instructions"`
	MaxOutputTokens    *int                                `json:"max_output_tokens"`
	MaxToolCalls       *int                                `json:"max_tool_calls"`
	Metadata           *map[string]any                     `json:"metadata,omitempty"`
	Model              string                              `json:"model"`
	Output             []ResponsesMessage                  `json:"output"`
	ParallelToolCalls  *bool                               `json:"parallel_tool_calls,omitempty"`
	PreviousResponseID *string                             `json:"previous_response_id"`
	Prompt             *ResponsesPrompt                    `json:"prompt,omitempty"` // Reference to a prompt template and variables
	PromptCacheKey     *string                             `json:"prompt_cache_key"` // Prompt cache key
	PresencePenalty    *float64                            `json:"presence_penalty,omitempty"`
	FrequencyPenalty   *float64                            `json:"frequency_penalty,omitempty"`
	Reasoning          *ResponsesParametersReasoning       `json:"reasoning"`         // Configuration options for reasoning models
	SafetyIdentifier   *string                             `json:"safety_identifier"` // Safety identifier
	ServiceTier        *string                             `json:"service_tier"`
	Status             *string                             `json:"status,omitempty"` // completed, failed, in_progress, cancelled, queued, or incomplete
	StreamOptions      *ResponsesStreamOptions             `json:"stream_options,omitempty"`
	StopReason         *string                             `json:"stop_reason,omitempty"` // Not in OpenAI's spec, but sent by other providers
	Store              *bool                               `json:"store,omitempty"`
	Temperature        *float64                            `json:"temperature,omitempty"`
	Text               *ResponsesTextConfig                `json:"text,omitempty"`
	TopLogProbs        *int                                `json:"top_logprobs,omitempty"`
	TopP               *float64                            `json:"top_p,omitempty"`       // Controls diversity via nucleus sampling
	ToolChoice         *ResponsesToolChoice                `json:"tool_choice,omitempty"` // Whether to call a tool
	Tools              []ResponsesTool                     `json:"tools"`                 // Tools to use
	Truncation         *string                             `json:"truncation,omitempty"`
	Usage              *ResponsesResponseUsage             `json:"usage"`
	ExtraFields        BifrostResponseExtraFields          `json:"extra_fields"`

	// Perplexity-specific fields
	SearchResults []SearchResult `json:"search_results,omitempty"`
	Videos        []VideoResult  `json:"videos,omitempty"`
	Citations     []string       `json:"citations,omitempty"`
}

func (*BifrostResponsesResponse) ToBifrostChatResponse

func (responsesResp *BifrostResponsesResponse) ToBifrostChatResponse() *BifrostChatResponse

ToBifrostChatResponse converts a BifrostResponsesResponse to BifrostChatResponse format This converts Responses API format to Chat-style fields (Choices)

func (*BifrostResponsesResponse) WithDefaults

func (resp *BifrostResponsesResponse) WithDefaults() *BifrostResponsesResponse

type BifrostResponsesStreamResponse

type BifrostResponsesStreamResponse struct {
	Type           ResponsesStreamResponseType `json:"type"`
	SequenceNumber int                         `json:"sequence_number"`

	Response *BifrostResponsesResponse `json:"response,omitempty"`

	OutputIndex *int              `json:"output_index,omitempty"`
	Item        *ResponsesMessage `json:"item"`

	ContentIndex *int                          `json:"content_index,omitempty"`
	ItemID       *string                       `json:"item_id,omitempty"`
	Part         *ResponsesMessageContentBlock `json:"part,omitempty"`

	Delta     *string                                    `json:"delta,omitempty"`
	Signature *string                                    `json:"signature,omitempty"` // Not in OpenAI's spec, but sent by other providers
	LogProbs  []ResponsesOutputMessageContentTextLogProb `json:"logprobs"`

	Text *string `json:"text,omitempty"` // Full text of the output item, comes with event "response.output_text.done"

	Refusal *string `json:"refusal,omitempty"`

	Arguments *string `json:"arguments,omitempty"`

	PartialImageB64   *string `json:"partial_image_b64,omitempty"`
	PartialImageIndex *int    `json:"partial_image_index,omitempty"`

	Annotation      *ResponsesOutputMessageContentTextAnnotation `json:"annotation,omitempty"`
	AnnotationIndex *int                                         `json:"annotation_index,omitempty"`

	Code    *string `json:"code,omitempty"`
	Message *string `json:"message,omitempty"`
	Param   *string `json:"param,omitempty"`

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`

	// Perplexity-specific fields
	SearchResults []SearchResult `json:"search_results,omitempty"`
	Videos        []VideoResult  `json:"videos,omitempty"`
	Citations     []string       `json:"citations,omitempty"`
}

func (*BifrostResponsesStreamResponse) WithDefaults

type BifrostSpeechRequest

type BifrostSpeechRequest struct {
	Provider       ModelProvider     `json:"provider"`
	Model          string            `json:"model"`
	Input          *SpeechInput      `json:"input,omitempty"`
	Params         *SpeechParameters `json:"params,omitempty"`
	Fallbacks      []Fallback        `json:"fallbacks,omitempty"`
	RawRequestBody []byte            `json:"-"` // set bifrost-use-raw-request-body to true in ctx to use the raw request body. Bifrost will directly send this to the downstream provider.
}

func (*BifrostSpeechRequest) GetRawRequestBody

func (r *BifrostSpeechRequest) GetRawRequestBody() []byte

type BifrostSpeechResponse

type BifrostSpeechResponse struct {
	Audio               []byte                     `json:"audio"`
	Usage               *SpeechUsage               `json:"usage"`
	Alignment           *SpeechAlignment           `json:"alignment,omitempty"`            // Character-level timing information
	NormalizedAlignment *SpeechAlignment           `json:"normalized_alignment,omitempty"` // Character-level timing information for normalized text
	AudioBase64         *string                    `json:"audio_base64,omitempty"`         // Base64-encoded audio (when timestamps are requested)
	ExtraFields         BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostSpeechStreamResponse

type BifrostSpeechStreamResponse struct {
	Type        SpeechStreamResponseType   `json:"type"`
	Audio       []byte                     `json:"audio"`
	Usage       *SpeechUsage               `json:"usage"`
	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostStreamChunk

BifrostStreamChunk represents a stream of responses from the Bifrost system. Either BifrostResponse or BifrostError will be non-nil.

func (BifrostStreamChunk) MarshalJSON

func (bs BifrostStreamChunk) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for BifrostStreamChunk. This ensures that only the non-nil embedded struct is marshaled,

type BifrostTextCompletionRequest

type BifrostTextCompletionRequest struct {
	Provider       ModelProvider             `json:"provider"`
	Model          string                    `json:"model"`
	Input          *TextCompletionInput      `json:"input,omitempty"`
	Params         *TextCompletionParameters `json:"params,omitempty"`
	Fallbacks      []Fallback                `json:"fallbacks,omitempty"`
	RawRequestBody []byte                    `json:"-"` // set bifrost-use-raw-request-body to true in ctx to use the raw request body. Bifrost will directly send this to the downstream provider.
}

BifrostTextCompletionRequest is the request struct for text completion requests

func (*BifrostTextCompletionRequest) GetRawRequestBody

func (r *BifrostTextCompletionRequest) GetRawRequestBody() []byte

func (*BifrostTextCompletionRequest) ToBifrostChatRequest

func (r *BifrostTextCompletionRequest) ToBifrostChatRequest() *BifrostChatRequest

ToBifrostChatRequest converts a Bifrost text completion request to a Bifrost chat completion request This method is discouraged to use, but is useful for litellm fallback flows

type BifrostTextCompletionResponse

type BifrostTextCompletionResponse struct {
	ID                string                     `json:"id"`
	Choices           []BifrostResponseChoice    `json:"choices"`
	Model             string                     `json:"model"`
	Object            string                     `json:"object"` // "text_completion" (same for text completion stream)
	SystemFingerprint string                     `json:"system_fingerprint"`
	Usage             *BifrostLLMUsage           `json:"usage"`
	ExtraFields       BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostTranscriptionRequest

type BifrostTranscriptionRequest struct {
	Provider       ModelProvider            `json:"provider"`
	Model          string                   `json:"model"`
	Input          *TranscriptionInput      `json:"input,omitempty"`
	Params         *TranscriptionParameters `json:"params,omitempty"`
	Fallbacks      []Fallback               `json:"fallbacks,omitempty"`
	RawRequestBody []byte                   `json:"-"` // set bifrost-use-raw-request-body to true in ctx to use the raw request body. Bifrost will directly send this to the downstream provider.
}

func (*BifrostTranscriptionRequest) GetRawRequestBody

func (r *BifrostTranscriptionRequest) GetRawRequestBody() []byte

type BifrostTranscriptionResponse

type BifrostTranscriptionResponse struct {
	Duration    *float64                   `json:"duration,omitempty"` // Duration in seconds
	Language    *string                    `json:"language,omitempty"` // e.g., "english"
	LogProbs    []TranscriptionLogProb     `json:"logprobs,omitempty"`
	Segments    []TranscriptionSegment     `json:"segments,omitempty"`
	Task        *string                    `json:"task,omitempty"` // e.g., "transcribe"
	Text        string                     `json:"text"`
	Usage       *TranscriptionUsage        `json:"usage,omitempty"`
	Words       []TranscriptionWord        `json:"words,omitempty"`
	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostTranscriptionStreamResponse

type BifrostTranscriptionStreamResponse struct {
	Delta       *string                         `json:"delta,omitempty"` // For delta events
	LogProbs    []TranscriptionLogProb          `json:"logprobs,omitempty"`
	Text        string                          `json:"text"`
	Type        TranscriptionStreamResponseType `json:"type"`
	Usage       *TranscriptionUsage             `json:"usage,omitempty"`
	ExtraFields BifrostResponseExtraFields      `json:"extra_fields"`
}

BifrostTranscriptionStreamResponse represents streaming specific fields only

type BifrostVideoDeleteRequest

type BifrostVideoDeleteRequest = BifrostVideoReferenceRequest

type BifrostVideoDeleteResponse

type BifrostVideoDeleteResponse struct {
	ID          string                     `json:"id"`
	Deleted     bool                       `json:"deleted"`
	Object      string                     `json:"object,omitempty"` // "video.deleted"
	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostVideoDownloadRequest

type BifrostVideoDownloadRequest struct {
	Provider    ModelProvider         `json:"provider"`
	ID          string                `json:"id"`
	Variant     *VideoDownloadVariant `json:"variant,omitempty"`
	ExtraParams map[string]any        `json:"-"`
}

type BifrostVideoDownloadResponse

type BifrostVideoDownloadResponse struct {
	VideoID     string `json:"video_id"`
	Content     []byte `json:"-"`                      // Raw video content (not serialized)
	ContentType string `json:"content_type,omitempty"` // MIME type (e.g., "video/mp4", "image/png" for thumbnails)

	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostVideoGenerationRequest

type BifrostVideoGenerationRequest struct {
	Provider       ModelProvider              `json:"provider"`
	Model          string                     `json:"model"`
	Input          *VideoGenerationInput      `json:"input"`
	Params         *VideoGenerationParameters `json:"params,omitempty"`
	Fallbacks      []Fallback                 `json:"fallbacks,omitempty"`
	RawRequestBody []byte                     `json:"-"`
}

func (*BifrostVideoGenerationRequest) GetExtraParams

func (b *BifrostVideoGenerationRequest) GetExtraParams() map[string]interface{}

func (*BifrostVideoGenerationRequest) GetRawRequestBody

func (b *BifrostVideoGenerationRequest) GetRawRequestBody() []byte

type BifrostVideoGenerationResponse

type BifrostVideoGenerationResponse struct {
	ID                 string             `json:"id,omitempty"`
	CompletedAt        *int64             `json:"completed_at,omitempty"`          // Unix timestamp (seconds) when the job completed
	CreatedAt          int64              `json:"created_at,omitempty"`            // Unix timestamp (seconds) when the job was created
	Error              *VideoCreateError  `json:"error,omitempty"`                 // Error payload if generation failed
	ExpiresAt          *int64             `json:"expires_at,omitempty"`            // Unix timestamp (seconds) when downloadable assets expire
	Model              string             `json:"model,omitempty"`                 // Video generation model that produced the job
	Object             string             `json:"object,omitempty"`                // Object type, always "video"
	Progress           *float64           `json:"progress,omitempty"`              // Approximate completion percentage (0-100)
	Prompt             string             `json:"prompt,omitempty"`                // Prompt used to generate the video
	RemixedFromVideoID *string            `json:"remixed_from_video_id,omitempty"` // Source video ID if this is a remix
	Seconds            *string            `json:"seconds,omitempty"`               // Duration of the generated clip in seconds
	Size               string             `json:"size,omitempty"`                  // Resolution of the generated video
	Status             VideoStatus        `json:"status,omitempty"`                // Current lifecycle status of the video job
	Videos             []VideoOutput      `json:"videos,omitempty"`                // Generated videos (supports multiple videos)
	ContentFilter      *ContentFilterInfo `json:"content_filter,omitempty"`        // Information about content filtering (if applicable)

	ExtraFields BifrostResponseExtraFields `json:"extra_fields,omitempty"`
}

BifrostVideoGenerationResponse represents the video generation job response in bifrost format.

type BifrostVideoListRequest

type BifrostVideoListRequest struct {
	Provider ModelProvider `json:"provider"`
	After    *string       `json:"after,omitempty"`
	Limit    *int          `json:"limit,omitempty"`
	Order    *string       `json:"order,omitempty"`
}

type BifrostVideoListResponse

type BifrostVideoListResponse struct {
	Object      string                     `json:"object"` // "list"
	Data        []VideoObject              `json:"data"`
	FirstID     *string                    `json:"first_id,omitempty"`
	HasMore     *bool                      `json:"has_more,omitempty"`
	LastID      *string                    `json:"last_id,omitempty"`
	ExtraFields BifrostResponseExtraFields `json:"extra_fields"`
}

type BifrostVideoReferenceRequest

type BifrostVideoReferenceRequest struct {
	Provider ModelProvider `json:"provider"`
	ID       string        `json:"id"`
}

type BifrostVideoRemixRequest

type BifrostVideoRemixRequest struct {
	ID             string                `json:"id"`
	Provider       ModelProvider         `json:"provider"`
	Input          *VideoGenerationInput `json:"input"`
	ExtraParams    map[string]any        `json:"-"`
	RawRequestBody []byte                `json:"-"`
}

func (*BifrostVideoRemixRequest) GetExtraParams

func (b *BifrostVideoRemixRequest) GetExtraParams() map[string]interface{}

func (*BifrostVideoRemixRequest) GetRawRequestBody

func (b *BifrostVideoRemixRequest) GetRawRequestBody() []byte

type BifrostVideoRetrieveRequest

type BifrostVideoRetrieveRequest = BifrostVideoReferenceRequest

type CacheControl

type CacheControl struct {
	Type  CacheControlType `json:"type"`
	TTL   *string          `json:"ttl,omitempty"`   // "1m" | "1h"
	Scope *string          `json:"scope,omitempty"` // "user" | "global"
}

type CacheControlType

type CacheControlType string
const (
	CacheControlTypeEphemeral CacheControlType = "ephemeral"
)

type CachePoint

type CachePoint struct {
	Type string `json:"type"` // "default"
}

CachePoint represents a cache point marker (Bedrock-specific)

type ChatAssistantMessage

type ChatAssistantMessage struct {
	Refusal          *string                          `json:"refusal,omitempty"`
	Audio            *ChatAudioMessageAudio           `json:"audio,omitempty"`
	Reasoning        *string                          `json:"reasoning,omitempty"`
	ReasoningDetails []ChatReasoningDetails           `json:"reasoning_details,omitempty"`
	Annotations      []ChatAssistantMessageAnnotation `json:"annotations,omitempty"`
	ToolCalls        []ChatAssistantMessageToolCall   `json:"tool_calls,omitempty"`
}

ChatAssistantMessage represents a message in a chat conversation.

func (*ChatAssistantMessage) UnmarshalJSON

func (cm *ChatAssistantMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshalling for ChatAssistantMessage. If Reasoning is non-nil and ReasoningDetails is nil/empty, it adds a single ChatReasoningDetails entry of type "reasoning.text" with the text set to Reasoning.

type ChatAssistantMessageAnnotation

type ChatAssistantMessageAnnotation struct {
	Type        string                                 `json:"type"`
	URLCitation ChatAssistantMessageAnnotationCitation `json:"url_citation"`
}

ChatAssistantMessageAnnotation represents an annotation in a response.

type ChatAssistantMessageAnnotationCitation

type ChatAssistantMessageAnnotationCitation struct {
	StartIndex int          `json:"start_index"`
	EndIndex   int          `json:"end_index"`
	Title      string       `json:"title"`
	URL        *string      `json:"url,omitempty"`
	Sources    *interface{} `json:"sources,omitempty"`
	Type       *string      `json:"type,omitempty"`
}

ChatAssistantMessageAnnotationCitation represents a citation in a response.

type ChatAssistantMessageToolCall

type ChatAssistantMessageToolCall struct {
	Index    uint16                               `json:"index"`
	Type     *string                              `json:"type,omitempty"`
	ID       *string                              `json:"id,omitempty"`
	Function ChatAssistantMessageToolCallFunction `json:"function"`
}

ChatAssistantMessageToolCall represents a tool call in a message

type ChatAssistantMessageToolCallFunction

type ChatAssistantMessageToolCallFunction struct {
	Name      *string `json:"name"`
	Arguments string  `json:"arguments"` // stringified json as retured by OpenAI, might not be a valid JSON always
}

ChatAssistantMessageToolCallFunction represents a call to a function.

type ChatAudioMessageAudio

type ChatAudioMessageAudio struct {
	ID         string `json:"id"`
	Data       string `json:"data"`
	ExpiresAt  int    `json:"expires_at"`
	Transcript string `json:"transcript"`
}

ChatAudioMessageAudio represents audio data in a message.

type ChatAudioParameters

type ChatAudioParameters struct {
	Format string `json:"format,omitempty"` // Format for the audio completion
	Voice  string `json:"voice,omitempty"`  // Voice to use for the audio completion
}

ChatAudioParameters represents the parameters for a chat audio completion. (Only supported by OpenAI Models that support audio input)

type ChatCompletionTokensDetails

type ChatCompletionTokensDetails struct {
	TextTokens               int  `json:"text_tokens,omitempty"`
	AcceptedPredictionTokens int  `json:"accepted_prediction_tokens,omitempty"`
	AudioTokens              int  `json:"audio_tokens,omitempty"`
	CitationTokens           *int `json:"citation_tokens,omitempty"`
	NumSearchQueries         *int `json:"num_search_queries,omitempty"`
	ReasoningTokens          int  `json:"reasoning_tokens,omitempty"`
	ImageTokens              *int `json:"image_tokens,omitempty"`
	RejectedPredictionTokens int  `json:"rejected_prediction_tokens,omitempty"`

	// This means the number of input tokens used to create the cache entry. (cache creation tokens)
	CachedTokens int `json:"cached_tokens,omitempty"` // Not in OpenAI's schemas, but sent by a few providers (Anthropic, Bedrock are some of them)
}

type ChatContentBlock

type ChatContentBlock struct {
	Type           ChatContentBlockType `json:"type"`
	Text           *string              `json:"text,omitempty"`
	Refusal        *string              `json:"refusal,omitempty"`
	ImageURLStruct *ChatInputImage      `json:"image_url,omitempty"`
	InputAudio     *ChatInputAudio      `json:"input_audio,omitempty"`
	File           *ChatInputFile       `json:"file,omitempty"`

	// Not in OpenAI's schemas, but sent by a few providers (Anthropic, Bedrock are some of them)
	CacheControl *CacheControl `json:"cache_control,omitempty"`
	Citations    *Citations    `json:"citations,omitempty"`

	// CachePoint is a Bedrock-specific field for standalone cache point blocks
	// When present without other content, this indicates a cache point marker
	CachePoint *CachePoint `json:"cachePoint,omitempty"`
}

ChatContentBlock represents a content block in a message.

type ChatContentBlockType

type ChatContentBlockType string

ChatContentBlockType represents the type of content block in a message.

const (
	ChatContentBlockTypeText       ChatContentBlockType = "text"
	ChatContentBlockTypeImage      ChatContentBlockType = "image_url"
	ChatContentBlockTypeInputAudio ChatContentBlockType = "input_audio"
	ChatContentBlockTypeFile       ChatContentBlockType = "file"
	ChatContentBlockTypeRefusal    ChatContentBlockType = "refusal"
)

ChatContentBlockType values

type ChatInputAudio

type ChatInputAudio struct {
	Data   string  `json:"data"`
	Format *string `json:"format,omitempty"`
}

ChatInputAudio represents audio data in a message. Data carries the audio payload as a string (e.g., data URL or provider-accepted encoded content). Format is optional (e.g., "wav", "mp3"); when nil, providers may attempt auto-detection.

type ChatInputFile

type ChatInputFile struct {
	FileData *string `json:"file_data,omitempty"` // Base64 encoded file data
	FileURL  *string `json:"file_url,omitempty"`  // Direct URL to file
	FileID   *string `json:"file_id,omitempty"`   // Reference to uploaded file
	Filename *string `json:"filename,omitempty"`  // Name of the file
	FileType *string `json:"file_type,omitempty"` // Type of the file
}

ChatInputFile represents a file in a message.

type ChatInputImage

type ChatInputImage struct {
	URL    string  `json:"url"`
	Detail *string `json:"detail,omitempty"`
}

ChatInputImage represents image data in a message.

type ChatMessage

type ChatMessage struct {
	Name    *string             `json:"name,omitempty"` // for chat completions
	Role    ChatMessageRole     `json:"role,omitempty"`
	Content *ChatMessageContent `json:"content,omitempty"`

	// Embedded pointer structs - when non-nil, their exported fields are flattened into the top-level JSON object
	// IMPORTANT: Only one of the following can be non-nil at a time, otherwise the JSON marshalling will override the common fields
	*ChatToolMessage
	*ChatAssistantMessage
}

ChatMessage represents a message in a chat conversation.

func DeepCopyChatMessage

func DeepCopyChatMessage(original ChatMessage) ChatMessage

DeepCopyChatMessage creates a deep copy of a ChatMessage to prevent shared data mutation between different plugin accumulators

func ToChatMessages

func ToChatMessages(rms []ResponsesMessage) []ChatMessage

ToChatMessages converts a slice of ResponsesMessages back to ChatMessages This handles the aggregation of function_call messages back into assistant messages with tool calls

func (*ChatMessage) ToResponsesMessages

func (cm *ChatMessage) ToResponsesMessages() []ResponsesMessage

ToResponsesMessages converts a ChatMessage to one or more ResponsesMessages This handles the expansion of assistant messages with tool calls into separate function_call messages

func (*ChatMessage) ToResponsesToolMessage

func (cm *ChatMessage) ToResponsesToolMessage() *ResponsesMessage

ToResponsesToolMessage converts a ChatToolMessage (tool execution result) to ResponsesToolMessage format. This creates a function_call_output message suitable for the Responses API.

Returns:

  • *ResponsesMessage: A ResponsesMessage with type=function_call_output containing the tool result

Example:

chatToolMsg := &ChatMessage{
    Role: ChatMessageRoleTool,
    ChatToolMessage: &ChatToolMessage{
        ToolCallID: Ptr("call-123"),
    },
    Content: &ChatMessageContent{
        ContentStr: Ptr("Result: 30"),
    },
}
responsesMsg := chatToolMsg.ToResponsesToolMessage()

func (*ChatMessage) UnmarshalJSON

func (cm *ChatMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ChatMessage. This is needed because ChatAssistantMessage has a custom UnmarshalJSON method, which interferes with the JSON library's handling of other fields in ChatMessage.

type ChatMessageContent

type ChatMessageContent struct {
	ContentStr    *string
	ContentBlocks []ChatContentBlock
}

ChatMessageContent represents a content in a message.

func (ChatMessageContent) MarshalJSON

func (mc ChatMessageContent) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ChatMessageContent. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ChatMessageContent) UnmarshalJSON

func (mc *ChatMessageContent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ChatMessageContent. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ChatMessageRole

type ChatMessageRole string

ChatMessageRole represents the role of a chat message

const (
	ChatMessageRoleAssistant ChatMessageRole = "assistant"
	ChatMessageRoleUser      ChatMessageRole = "user"
	ChatMessageRoleSystem    ChatMessageRole = "system"
	ChatMessageRoleTool      ChatMessageRole = "tool"
	ChatMessageRoleDeveloper ChatMessageRole = "developer"
)

ChatMessageRole values

type ChatNonStreamResponseChoice

type ChatNonStreamResponseChoice struct {
	Message    *ChatMessage `json:"message"`
	StopString *string      `json:"stop,omitempty"`
}

ChatNonStreamResponseChoice represents a choice in the non-stream response

type ChatParameters

type ChatParameters struct {
	Audio                *ChatAudioParameters  `json:"audio,omitempty"`                 // Audio parameters
	FrequencyPenalty     *float64              `json:"frequency_penalty,omitempty"`     // Penalizes frequent tokens
	LogitBias            *map[string]float64   `json:"logit_bias,omitempty"`            // Bias for logit values
	LogProbs             *bool                 `json:"logprobs,omitempty"`              // Number of logprobs to return
	MaxCompletionTokens  *int                  `json:"max_completion_tokens,omitempty"` // Maximum number of tokens to generate
	Metadata             *map[string]any       `json:"metadata,omitempty"`              // Metadata to be returned with the response
	Modalities           []string              `json:"modalities,omitempty"`            // Modalities to be returned with the response
	ParallelToolCalls    *bool                 `json:"parallel_tool_calls,omitempty"`
	Prediction           *ChatPrediction       `json:"prediction,omitempty"`             // Predicted output content (OpenAI only)
	PresencePenalty      *float64              `json:"presence_penalty,omitempty"`       // Penalizes repeated tokens
	PromptCacheKey       *string               `json:"prompt_cache_key,omitempty"`       // Prompt cache key
	PromptCacheRetention *string               `json:"prompt_cache_retention,omitempty"` // Prompt cache retention ("in-memory" or "24h")
	Reasoning            *ChatReasoning        `json:"reasoning,omitempty"`              // Reasoning parameters
	ResponseFormat       *interface{}          `json:"response_format,omitempty"`        // Format for the response
	SafetyIdentifier     *string               `json:"safety_identifier,omitempty"`      // Safety identifier
	Seed                 *int                  `json:"seed,omitempty"`
	ServiceTier          *string               `json:"service_tier,omitempty"`
	StreamOptions        *ChatStreamOptions    `json:"stream_options,omitempty"`
	Stop                 []string              `json:"stop,omitempty"`
	Store                *bool                 `json:"store,omitempty"`
	Temperature          *float64              `json:"temperature,omitempty"`
	TopLogProbs          *int                  `json:"top_logprobs,omitempty"`
	TopP                 *float64              `json:"top_p,omitempty"`              // Controls diversity via nucleus sampling
	ToolChoice           *ChatToolChoice       `json:"tool_choice,omitempty"`        // Whether to call a tool
	Tools                []ChatTool            `json:"tools,omitempty"`              // Tools to use
	User                 *string               `json:"user,omitempty"`               // User identifier for tracking
	Verbosity            *string               `json:"verbosity,omitempty"`          // "low" | "medium" | "high"
	WebSearchOptions     *ChatWebSearchOptions `json:"web_search_options,omitempty"` // Web search options (OpenAI only)

	// Dynamic parameters that can be provider-specific, they are directly
	// added to the request as is.
	ExtraParams map[string]interface{} `json:"-"`
}

ChatParameters represents the parameters for a chat completion.

func (*ChatParameters) UnmarshalJSON

func (cp *ChatParameters) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ChatParameters.

type ChatPrediction

type ChatPrediction struct {
	Type    string      `json:"type"`    // Always "content"
	Content interface{} `json:"content"` // String or array of content parts
}

ChatPrediction represents predicted output content for the model to reference (OpenAI only). Providing prediction content can significantly reduce latency for certain models.

type ChatPromptTokensDetails

type ChatPromptTokensDetails struct {
	TextTokens  int `json:"text_tokens,omitempty"`
	AudioTokens int `json:"audio_tokens,omitempty"`
	ImageTokens int `json:"image_tokens,omitempty"`

	// For Providers which follow OpenAI's spec, CachedTokens means the number of input tokens read from the cache+input tokens used to create the cache entry. (because they do not differentiate between cache creation and cache read tokens)
	// For Providers which do not follow OpenAI's spec, CachedTokens means only the number of input tokens read from the cache.
	CachedTokens int `json:"cached_tokens,omitempty"`
}

type ChatReasoning

type ChatReasoning struct {
	Effort    *string `json:"effort,omitempty"`     // "none" |  "minimal" | "low" | "medium" | "high" (any value other than "none" will enable reasoning)
	MaxTokens *int    `json:"max_tokens,omitempty"` // Maximum number of tokens to generate for the reasoning output (required for anthropic)
}

Not in OpenAI's spec, but needed to support extra parameters for reasoning.

type ChatReasoningDetails

type ChatReasoningDetails struct {
	ID        *string                     `json:"id,omitempty"`
	Index     int                         `json:"index"`
	Type      BifrostReasoningDetailsType `json:"type"`
	Summary   *string                     `json:"summary,omitempty"`
	Text      *string                     `json:"text,omitempty"`
	Signature *string                     `json:"signature,omitempty"`
	Data      *string                     `json:"data,omitempty"` // for encrypted data
}

Not in OpenAI's spec, but needed to support inter provider reasoning capabilities.

type ChatStreamOptions

type ChatStreamOptions struct {
	IncludeObfuscation *bool `json:"include_obfuscation,omitempty"`
	IncludeUsage       *bool `json:"include_usage,omitempty"` // Bifrost marks this as true by default
}

ChatStreamOptions represents the stream options for a chat completion.

type ChatStreamResponseChoice

type ChatStreamResponseChoice struct {
	Delta *ChatStreamResponseChoiceDelta `json:"delta,omitempty"` // Partial message info
}

ChatStreamResponseChoice represents a choice in the stream response

type ChatStreamResponseChoiceDelta

type ChatStreamResponseChoiceDelta struct {
	Role             *string                        `json:"role,omitempty"`      // Only in the first chunk
	Content          *string                        `json:"content,omitempty"`   // May be empty string or null
	Refusal          *string                        `json:"refusal,omitempty"`   // Refusal content if any
	Audio            *ChatAudioMessageAudio         `json:"audio,omitempty"`     // Audio data if any
	Reasoning        *string                        `json:"reasoning,omitempty"` // May be empty string or null
	ReasoningDetails []ChatReasoningDetails         `json:"reasoning_details,omitempty"`
	ToolCalls        []ChatAssistantMessageToolCall `json:"tool_calls,omitempty"` // If tool calls used (supports incremental updates)
}

ChatStreamResponseChoiceDelta represents a delta in the stream response

func (*ChatStreamResponseChoiceDelta) UnmarshalJSON

func (d *ChatStreamResponseChoiceDelta) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshalling for ChatStreamResponseChoiceDelta. If Reasoning is non-nil and ReasoningDetails is nil/empty, it adds a single ChatReasoningDetails entry of type "reasoning.text" with the text set to Reasoning.

type ChatToResponsesStreamState

type ChatToResponsesStreamState struct {
	ToolArgumentBuffers   map[string]string // Maps tool call ID to accumulated argument JSON
	ItemIDs               map[string]string // Maps tool call ID to item ID
	ToolCallNames         map[string]string // Maps tool call ID to tool name
	ToolCallIndexToID     map[uint16]string // Maps tool call index to tool call ID (for lookups when ID is missing)
	MessageID             *string           // Message ID from first chunk
	Model                 *string           // Model name
	CreatedAt             int               // Timestamp for created_at consistency
	HasEmittedCreated     bool              // Whether we've emitted response.created
	HasEmittedInProgress  bool              // Whether we've emitted response.in_progress
	TextItemAdded         bool              // Whether text item has been added
	TextItemClosed        bool              // Whether text item has been closed
	TextItemHasContent    bool              // Whether text item has received any content deltas
	CurrentOutputIndex    int               // Current output index counter
	ToolCallOutputIndices map[string]int    // Maps tool call ID to output index
	SequenceNumber        int               // Monotonic sequence number across all chunks
}

ChatToResponsesStreamState tracks state during Chat-to-Responses streaming conversion

func AcquireChatToResponsesStreamState

func AcquireChatToResponsesStreamState() *ChatToResponsesStreamState

AcquireChatToResponsesStreamState gets a ChatToResponsesStreamState from the pool.

type ChatTool

type ChatTool struct {
	Type         ChatToolType      `json:"type"`
	Function     *ChatToolFunction `json:"function,omitempty"`      // Function definition
	Custom       *ChatToolCustom   `json:"custom,omitempty"`        // Custom tool definition
	CacheControl *CacheControl     `json:"cache_control,omitempty"` // Cache control for the tool
}

ChatTool represents a tool definition.

func DeepCopyChatTool

func DeepCopyChatTool(original ChatTool) ChatTool

DeepCopyChatTool creates a deep copy of a ChatTool to prevent shared data mutation between different plugin accumulators

func (*ChatTool) ToResponsesTool

func (ct *ChatTool) ToResponsesTool() *ResponsesTool

ToResponsesTool converts a ChatTool to ResponsesTool format

type ChatToolChoice

type ChatToolChoice struct {
	ChatToolChoiceStr    *string
	ChatToolChoiceStruct *ChatToolChoiceStruct
}

func (ChatToolChoice) MarshalJSON

func (ctc ChatToolChoice) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ChatMessageContent. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ChatToolChoice) ToResponsesToolChoice

func (ctc *ChatToolChoice) ToResponsesToolChoice() *ResponsesToolChoice

ToResponsesToolChoice converts a ChatToolChoice to ResponsesToolChoice format

func (*ChatToolChoice) UnmarshalJSON

func (ctc *ChatToolChoice) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ChatMessageContent. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ChatToolChoiceAllowedTools

type ChatToolChoiceAllowedTools struct {
	Mode  string                           `json:"mode"` // "auto" | "required"
	Tools []ChatToolChoiceAllowedToolsTool `json:"tools"`
}

ChatToolChoiceAllowedTools represents a allowed tools choice.

type ChatToolChoiceAllowedToolsTool

type ChatToolChoiceAllowedToolsTool struct {
	Type     string                 `json:"type"` // "function"
	Function ChatToolChoiceFunction `json:"function,omitempty"`
}

ChatToolChoiceAllowedToolsTool represents a allowed tools tool.

type ChatToolChoiceCustom

type ChatToolChoiceCustom struct {
	Name string `json:"name"`
}

ChatToolChoiceCustom represents a custom choice.

type ChatToolChoiceFunction

type ChatToolChoiceFunction struct {
	Name string `json:"name"`
}

ChatToolChoiceFunction represents a function choice.

type ChatToolChoiceStruct

type ChatToolChoiceStruct struct {
	Type         ChatToolChoiceType          `json:"type"`                    // Type of tool choice
	Function     *ChatToolChoiceFunction     `json:"function,omitempty"`      // Function to call if type is ToolChoiceTypeFunction
	Custom       *ChatToolChoiceCustom       `json:"custom,omitempty"`        // Custom tool to call if type is ToolChoiceTypeCustom
	AllowedTools *ChatToolChoiceAllowedTools `json:"allowed_tools,omitempty"` // Allowed tools to call if type is ToolChoiceTypeAllowedTools
}

ChatToolChoiceStruct represents a tool choice.

type ChatToolChoiceType

type ChatToolChoiceType string

ChatToolChoiceType for all providers, make sure to check the provider's documentation to see which tool choices are supported.

const (
	ChatToolChoiceTypeNone     ChatToolChoiceType = "none"
	ChatToolChoiceTypeAuto     ChatToolChoiceType = "auto"
	ChatToolChoiceTypeAny      ChatToolChoiceType = "any"
	ChatToolChoiceTypeRequired ChatToolChoiceType = "required"
	// ChatToolChoiceTypeFunction means a specific tool must be called
	ChatToolChoiceTypeFunction ChatToolChoiceType = "function"
	// ChatToolChoiceTypeAllowedTools means a specific tool must be called
	ChatToolChoiceTypeAllowedTools ChatToolChoiceType = "allowed_tools"
	// ChatToolChoiceTypeCustom means a custom tool must be called
	ChatToolChoiceTypeCustom ChatToolChoiceType = "custom"
)

ChatToolChoiceType values

type ChatToolCustom

type ChatToolCustom struct {
	Format *ChatToolCustomFormat `json:"format,omitempty"` // The input format
}

type ChatToolCustomFormat

type ChatToolCustomFormat struct {
	Type    string                       `json:"type"` // always "text"
	Grammar *ChatToolCustomGrammarFormat `json:"grammar,omitempty"`
}

type ChatToolCustomGrammarFormat

type ChatToolCustomGrammarFormat struct {
	Definition string `json:"definition"` // The grammar definition
	Syntax     string `json:"syntax"`     // "lark" | "regex"
}

ChatToolCustomGrammarFormat - A grammar defined by the user

type ChatToolFunction

type ChatToolFunction struct {
	Name        string                  `json:"name"`                  // Name of the function
	Description *string                 `json:"description,omitempty"` // Description of the parameters
	Parameters  *ToolFunctionParameters `json:"parameters,omitempty"`  // A JSON schema object describing the parameters
	Strict      *bool                   `json:"strict,omitempty"`      // Whether to enforce strict parameter validation
}

ChatToolFunction represents a function definition.

type ChatToolMessage

type ChatToolMessage struct {
	ToolCallID *string `json:"tool_call_id,omitempty"`
}

ChatToolMessage represents a tool message in a chat conversation.

type ChatToolType

type ChatToolType string

ChatToolType represents the type of tool.

const (
	ChatToolTypeFunction ChatToolType = "function"
	ChatToolTypeCustom   ChatToolType = "custom"
)

ChatToolType values

type ChatWebSearchOptions

type ChatWebSearchOptions struct {
	SearchContextSize *string                           `json:"search_context_size,omitempty"` // "low" | "medium" | "high"
	UserLocation      *ChatWebSearchOptionsUserLocation `json:"user_location,omitempty"`
}

ChatWebSearchOptions represents web search options for chat completions (OpenAI only).

type ChatWebSearchOptionsUserLocation

type ChatWebSearchOptionsUserLocation struct {
	Type        string                                       `json:"type"` // "approximate"
	Approximate *ChatWebSearchOptionsUserLocationApproximate `json:"approximate,omitempty"`
}

ChatWebSearchOptionsUserLocation represents user location for web search.

type ChatWebSearchOptionsUserLocationApproximate

type ChatWebSearchOptionsUserLocationApproximate struct {
	City     *string `json:"city,omitempty"`
	Country  *string `json:"country,omitempty"`  // Two-letter ISO country code (e.g., "US")
	Region   *string `json:"region,omitempty"`   // e.g., "California"
	Timezone *string `json:"timezone,omitempty"` // IANA timezone (e.g., "America/Los_Angeles")
}

ChatWebSearchOptionsUserLocationApproximate represents approximate user location details.

type Citations

type Citations struct {
	Enabled *bool `json:"enabled,omitempty"`
}

type CodeModeBindingLevel

type CodeModeBindingLevel string

CodeModeBindingLevel defines how tools are exposed in the VFS for code execution

const (
	CodeModeBindingLevelServer CodeModeBindingLevel = "server"
	CodeModeBindingLevelTool   CodeModeBindingLevel = "tool"
)

type ConcurrencyAndBufferSize

type ConcurrencyAndBufferSize struct {
	Concurrency int `json:"concurrency"` // Number of concurrent operations. Also used as the initial pool size for the provider reponses.
	BufferSize  int `json:"buffer_size"` // Size of the buffer
}

ConcurrencyAndBufferSize represents configuration for concurrent operations and buffer sizes.

type ContainerExpiresAfter

type ContainerExpiresAfter struct {
	Anchor  string `json:"anchor"`  // The anchor point for expiration (e.g., "last_active_at")
	Minutes int    `json:"minutes"` // Number of minutes after anchor point
}

ContainerExpiresAfter represents the expiration configuration for a container.

type ContainerFileObject

type ContainerFileObject struct {
	ID          string `json:"id"`
	Object      string `json:"object,omitempty"` // "container.file"
	Bytes       int64  `json:"bytes"`
	CreatedAt   int64  `json:"created_at"`
	ContainerID string `json:"container_id"`
	Path        string `json:"path"`
	Source      string `json:"source"` // "user" typically
}

ContainerFileObject represents a file within a container.

type ContainerObject

type ContainerObject struct {
	ID           string                 `json:"id"`
	Object       string                 `json:"object,omitempty"` // "container"
	Name         string                 `json:"name"`
	CreatedAt    int64                  `json:"created_at"`
	Status       ContainerStatus        `json:"status,omitempty"`
	ExpiresAfter *ContainerExpiresAfter `json:"expires_after,omitempty"`
	LastActiveAt *int64                 `json:"last_active_at,omitempty"`
	MemoryLimit  string                 `json:"memory_limit,omitempty"` // e.g., "1g", "4g"
	Metadata     map[string]string      `json:"metadata,omitempty"`
}

ContainerObject represents a container object returned by the API.

type ContainerStatus

type ContainerStatus string

ContainerStatus represents the status of a container.

const (
	ContainerStatusRunning ContainerStatus = "running"
)

type ContentFilterInfo

type ContentFilterInfo struct {
	FilteredCount int      `json:"filtered_count,omitempty"` // Number of items filtered
	Reasons       []string `json:"reasons,omitempty"`        // Human-readable reasons for filtering
}

ContentFilterInfo contains information about content that was filtered due to safety policies. This is a provider-agnostic structure for representing content filtering results.

type ContentLogProb

type ContentLogProb struct {
	Bytes       []int     `json:"bytes"`
	LogProb     float64   `json:"logprob"`
	Token       string    `json:"token"`
	TopLogProbs []LogProb `json:"top_logprobs"`
}

ContentLogProb represents log probability information for content.

type CustomProviderConfig

type CustomProviderConfig struct {
	CustomProviderKey    string                 `json:"-"`                                // Custom provider key, internally set by Bifrost
	IsKeyLess            bool                   `json:"is_key_less"`                      // Whether the custom provider requires a key (not allowed for Bedrock)
	BaseProviderType     ModelProvider          `json:"base_provider_type"`               // Base provider type
	AllowedRequests      *AllowedRequests       `json:"allowed_requests,omitempty"`       // Allowed requests for the custom provider
	RequestPathOverrides map[RequestType]string `json:"request_path_overrides,omitempty"` // Mapping of request type to its custom path which will override the default path of the provider (not allowed for Bedrock)
}

func (*CustomProviderConfig) IsOperationAllowed

func (cpc *CustomProviderConfig) IsOperationAllowed(operation RequestType) bool

IsOperationAllowed checks if a specific operation is allowed for this custom provider

type DefaultParameters

type DefaultParameters struct {
	Temperature      *float64 `json:"temperature,omitempty"`
	TopP             *float64 `json:"top_p,omitempty"`
	FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
}

type EmbeddingData

type EmbeddingData struct {
	Index     int             `json:"index"`
	Object    string          `json:"object"`    // "embedding"
	Embedding EmbeddingStruct `json:"embedding"` // can be string, []float32 or [][]float32
}

type EmbeddingInput

type EmbeddingInput struct {
	Text       *string
	Texts      []string
	Embedding  []int
	Embeddings [][]int
}

EmbeddingInput represents the input for an embedding request.

func (*EmbeddingInput) MarshalJSON

func (e *EmbeddingInput) MarshalJSON() ([]byte, error)

func (*EmbeddingInput) UnmarshalJSON

func (e *EmbeddingInput) UnmarshalJSON(data []byte) error

type EmbeddingParameters

type EmbeddingParameters struct {
	EncodingFormat *string `json:"encoding_format,omitempty"` // Format for embedding output (e.g., "float", "base64")
	Dimensions     *int    `json:"dimensions,omitempty"`      // Number of dimensions for embedding output

	// Dynamic parameters that can be provider-specific, they are directly
	// added to the request as is.
	ExtraParams map[string]interface{} `json:"-"`
}

type EmbeddingStruct

type EmbeddingStruct struct {
	EmbeddingStr     *string
	EmbeddingArray   []float32
	Embedding2DArray [][]float32
}

func (EmbeddingStruct) MarshalJSON

func (be EmbeddingStruct) MarshalJSON() ([]byte, error)

func (*EmbeddingStruct) UnmarshalJSON

func (be *EmbeddingStruct) UnmarshalJSON(data []byte) error

type EnvVar

type EnvVar struct {
	Val     string `json:"value"`
	EnvVar  string `json:"env_var"`
	FromEnv bool   `json:"from_env"`
}

EnvVar is a wrapper around a value that can be sourced from an environment variable.

func NewEnvVar

func NewEnvVar(value string) *EnvVar

NewEnvVar creates a new EnvValue from a string.

func (*EnvVar) CoerceBool

func (e *EnvVar) CoerceBool(defaultValue bool) bool

CoerceBool coerces value to bool

func (*EnvVar) CoerceInt

func (e *EnvVar) CoerceInt(defaultValue int) int

CoerceInt coerces value to int

func (*EnvVar) Equals

func (e *EnvVar) Equals(other *EnvVar) bool

Equals checks if two SecretKeys are equal.

func (*EnvVar) GetValue

func (e *EnvVar) GetValue() string

GetValue returns the value.

func (*EnvVar) GetValuePtr

func (e *EnvVar) GetValuePtr() *string

GetValuePtr returns a pointer to the value.

func (*EnvVar) IsFromEnv

func (e *EnvVar) IsFromEnv() bool

IsFromEnv returns true if the value is sourced from an environment variable.

func (*EnvVar) IsRedacted

func (e *EnvVar) IsRedacted() bool

IsRedacted returns true if the value is redacted.

func (*EnvVar) Redacted

func (e *EnvVar) Redacted() *EnvVar

Redacted returns a new SecretKey with the value redacted.

func (*EnvVar) Scan

func (e *EnvVar) Scan(value any) error

Scan scans the value from the database.

func (*EnvVar) String

func (e *EnvVar) String() string

String returns the value as a string.

func (*EnvVar) UnmarshalJSON

func (e *EnvVar) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the value from JSON.

func (EnvVar) Value

func (e EnvVar) Value() (driver.Value, error)

Value implements driver.Valuer for database storage. It stores the original env reference (e.g., "env.API_KEY") if FromEnv is true, otherwise stores the raw value.

type ErrorField

type ErrorField struct {
	Type    *string     `json:"type,omitempty"`
	Code    *string     `json:"code,omitempty"`
	Message string      `json:"message"`
	Error   error       `json:"-"`
	Param   interface{} `json:"param,omitempty"`
	EventID *string     `json:"event_id,omitempty"`
}

ErrorField represents detailed error information.

func (*ErrorField) MarshalJSON

func (e *ErrorField) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ErrorField. It converts the Error field (error interface) to a string.

func (*ErrorField) UnmarshalJSON

func (e *ErrorField) UnmarshalJSON(data []byte) error

type EventBroadcaster

type EventBroadcaster func(eventType string, data interface{})

EventBroadcaster is a generic callback for broadcasting typed events to connected clients (e.g., via WebSocket). Any plugin or subsystem can use this to push real-time updates to the frontend. eventType identifies the message (e.g., "governance_update"), data is the JSON-serializable payload.

type Fallback

type Fallback struct {
	Provider ModelProvider `json:"provider"`
	Model    string        `json:"model"`
}

Fallback represents a fallback model to be used if the primary model is not available.

func ParseFallbacks

func ParseFallbacks(fallbacks []string) []Fallback

ParseFallbacks parses a slice of strings into a slice of Fallback structs

type FileExpiresAfter

type FileExpiresAfter struct {
	Anchor  string `json:"anchor"`  // e.g., "created_at"
	Seconds int    `json:"seconds"` // 3600-2592000 (1 hour to 30 days)
}

FileExpiresAfter represents an expiration configuration for uploaded files.

type FileObject

type FileObject struct {
	ID            string      `json:"id"`
	Object        string      `json:"object,omitempty"` // "file"
	Bytes         int64       `json:"bytes"`
	CreatedAt     int64       `json:"created_at"`
	Filename      string      `json:"filename"`
	Purpose       FilePurpose `json:"purpose"`
	Status        FileStatus  `json:"status,omitempty"`
	StatusDetails *string     `json:"status_details,omitempty"`
	ExpiresAt     *int64      `json:"expires_at,omitempty"`
}

FileObject represents a file object returned by the API.

type FilePurpose

type FilePurpose string

FilePurpose represents the purpose of an uploaded file.

const (
	FilePurposeBatch       FilePurpose = "batch"
	FilePurposeAssistants  FilePurpose = "assistants"
	FilePurposeFineTune    FilePurpose = "fine-tune"
	FilePurposeVision      FilePurpose = "vision"
	FilePurposeBatchOutput FilePurpose = "batch_output"
	FilePurposeUserData    FilePurpose = "user_data"
	FilePurposeResponses   FilePurpose = "responses"
	FilePurposeEvals       FilePurpose = "evals"
)

type FileStatus

type FileStatus string

FileStatus represents the status of a file.

const (
	FileStatusUploaded   FileStatus = "uploaded"
	FileStatusProcessed  FileStatus = "processed"
	FileStatusProcessing FileStatus = "processing"
	FileStatusError      FileStatus = "error"
	FileStatusDeleted    FileStatus = "deleted"
)

type FileStorageBackend

type FileStorageBackend string

FileStorageBackend represents the storage backend type.

const (
	FileStorageAPI    FileStorageBackend = "api"    // OpenAI/Azure REST API
	FileStorageS3     FileStorageBackend = "s3"     // AWS S3
	FileStorageGCS    FileStorageBackend = "gcs"    // Google Cloud Storage
	FileStorageMemory FileStorageBackend = "memory" // In-memory (for Anthropic virtual files)
)

type FileStorageConfig

type FileStorageConfig struct {
	S3  *S3StorageConfig  `json:"s3,omitempty"`
	GCS *GCSStorageConfig `json:"gcs,omitempty"`
}

FileStorageConfig represents storage configuration for cloud storage backends.

type GCSStorageConfig

type GCSStorageConfig struct {
	Bucket  string `json:"bucket,omitempty"`
	Project string `json:"project,omitempty"`
	Prefix  string `json:"prefix,omitempty"`
}

GCSStorageConfig represents Google Cloud Storage configuration.

type HTTPRequest

type HTTPRequest struct {
	Method     string            `json:"method"`
	Path       string            `json:"path"`
	Headers    map[string]string `json:"headers"`
	Query      map[string]string `json:"query"`
	Body       []byte            `json:"body"`
	PathParams map[string]string `json:"path_params"` // Path variables extracted from the URL pattern (e.g., {model})
}

HTTPRequest is a serializable representation of an HTTP request. Used for plugin HTTP transport interception (supports both native .so and WASM plugins). This type is pooled for allocation control - use AcquireHTTPRequest and ReleaseHTTPRequest.

func AcquireHTTPRequest

func AcquireHTTPRequest() *HTTPRequest

AcquireHTTPRequest gets an HTTPRequest from the pool. The returned HTTPRequest is ready to use with pre-allocated maps. Call ReleaseHTTPRequest when done to return it to the pool.

func (*HTTPRequest) CaseInsensitiveHeaderLookup

func (req *HTTPRequest) CaseInsensitiveHeaderLookup(key string) string

CaseInsensitiveHeaderLookup looks up a header key in a case-insensitive manner

func (*HTTPRequest) CaseInsensitivePathParamLookup

func (req *HTTPRequest) CaseInsensitivePathParamLookup(key string) string

CaseInsensitivePathParamLookup looks up a path parameter key in a case-insensitive manner

func (*HTTPRequest) CaseInsensitiveQueryLookup

func (req *HTTPRequest) CaseInsensitiveQueryLookup(key string) string

CaseInsensitiveQueryLookup looks up a query key in a case-insensitive manner

type HTTPResponse

type HTTPResponse struct {
	StatusCode int               `json:"status_code"`
	Headers    map[string]string `json:"headers"`
	Body       []byte            `json:"body"`
}

HTTPResponse is a serializable representation of an HTTP response. Used for short-circuit responses in plugin HTTP transport interception. This type is pooled for allocation control - use AcquireHTTPResponse and ReleaseHTTPResponse.

func AcquireHTTPResponse

func AcquireHTTPResponse() *HTTPResponse

AcquireHTTPResponse gets an HTTPResponse from the pool. The returned HTTPResponse is ready to use with a pre-allocated Headers map. Call ReleaseHTTPResponse when done to return it to the pool.

type HTTPTransportPlugin

type HTTPTransportPlugin interface {
	BasePlugin

	// HTTPTransportPreHook is called at the HTTP transport layer before requests enter Bifrost core.
	// It receives a serializable HTTPRequest and allows plugins to modify it in-place.
	// Only invoked when using HTTP transport (bifrost-http), not when using Bifrost as a Go SDK directly.
	// Works with both native .so plugins and WASM plugins due to serializable types.
	//
	// Return values:
	// - (nil, nil): Continue to next plugin/handler, request modifications are applied
	// - (*HTTPResponse, nil): Short-circuit with this response, skip remaining plugins and provider call
	// - (nil, error): Short-circuit with error response
	//
	// Return nil for both values if the plugin doesn't need HTTP transport interception.
	HTTPTransportPreHook(ctx *BifrostContext, req *HTTPRequest) (*HTTPResponse, error)

	// HTTPTransportPostHook is called at the HTTP transport layer after requests exit Bifrost core.
	// It receives a serializable HTTPRequest and HTTPResponse and allows plugins to modify it in-place.
	// Only invoked when using HTTP transport (bifrost-http), not when using Bifrost as a Go SDK directly.
	// Works with both native .so plugins and WASM plugins due to serializable types.
	// NOTE: This hook is NOT called for streaming responses. Use HTTPTransportStreamChunkHook instead.
	//
	// Return values:
	// - nil: Continue to next plugin/handler, response modifications are applied
	// - error: Short-circuit with error response and skip remaining plugins
	//
	// Return nil if the plugin doesn't need HTTP transport interception.
	HTTPTransportPostHook(ctx *BifrostContext, req *HTTPRequest, resp *HTTPResponse) error

	// HTTPTransportStreamChunkHook is called for each chunk during streaming responses.
	// It receives the BifrostStreamChunk BEFORE they are written to the client.
	// Only invoked for streaming responses when using HTTP transport (bifrost-http).
	// Works with both native .so plugins and WASM plugins due to serializable types.
	//
	// Plugins can modify the chunk by returning a different BifrostStreamChunk.
	// Return the original chunk unchanged if no modification is needed.
	//
	// Return values:
	// - (*BifrostStreamChunk, nil): Continue with the (potentially modified) BifrostStreamChunk
	// - (nil, nil): Skip this BifrostStreamChunk entirely (don't send to client)
	// - (*BifrostStreamChunk, error): Log warning and continue with the BifrostStreamChunk
	// - (nil, error): Send back error to the client and stop the streaming
	//
	// Return (*BifrostStreamChunk, nil) unchanged if the plugin doesn't need streaming chunk interception.
	HTTPTransportStreamChunkHook(ctx *BifrostContext, req *HTTPRequest, chunk *BifrostStreamChunk) (*BifrostStreamChunk, error)
}

type HuggingFaceKeyConfig

type HuggingFaceKeyConfig struct {
	Deployments map[string]string `json:"deployments,omitempty"` // Mapping of model identifiers to deployment names
}

type ImageContentType

type ImageContentType string

ImageContentType represents the type of image content

const (
	ImageContentTypeBase64 ImageContentType = "base64"
	ImageContentTypeURL    ImageContentType = "url"
)

type ImageData

type ImageData struct {
	URL           string `json:"url,omitempty"`
	B64JSON       string `json:"b64_json,omitempty"`
	RevisedPrompt string `json:"revised_prompt,omitempty"`
	Index         int    `json:"index"`
}

type ImageEditInput

type ImageEditInput struct {
	Images []ImageInput `json:"images"`
	Prompt string       `json:"prompt"`
}

type ImageEditParameters

type ImageEditParameters struct {
	Type              *string                `json:"type,omitempty"`           // "inpainting", "outpainting", "background_removal",
	Background        *string                `json:"background,omitempty"`     // "transparent", "opaque", "auto"
	InputFidelity     *string                `json:"input_fidelity,omitempty"` // "low", "high"
	Mask              []byte                 `json:"mask,omitempty"`
	N                 *int                   `json:"n,omitempty"`                  // number of images to generate (1-10)
	OutputCompression *int                   `json:"output_compression,omitempty"` // compression level (0-100%)
	OutputFormat      *string                `json:"output_format,omitempty"`      // "png", "webp", "jpeg"
	PartialImages     *int                   `json:"partial_images,omitempty"`     // 0-3
	Quality           *string                `json:"quality,omitempty"`            // "auto", "high", "medium", "low", "standard"
	ResponseFormat    *string                `json:"response_format,omitempty"`    // "url", "b64_json"
	Size              *string                `json:"size,omitempty"`               // "256x256", "512x512", "1024x1024", "1536x1024", "1024x1536", "auto"
	User              *string                `json:"user,omitempty"`
	NegativePrompt    *string                `json:"negative_prompt,omitempty"`     // negative prompt for image editing
	Seed              *int                   `json:"seed,omitempty"`                // seed for image editing
	NumInferenceSteps *int                   `json:"num_inference_steps,omitempty"` // number of inference steps
	ExtraParams       map[string]interface{} `json:"-"`
}

type ImageEventType

type ImageEventType string
const (
	ImageGenerationEventTypePartial   ImageEventType = "image_generation.partial_image"
	ImageGenerationEventTypeCompleted ImageEventType = "image_generation.completed"
	ImageGenerationEventTypeError     ImageEventType = "error"
	ImageEditEventTypePartial         ImageEventType = "image_edit.partial_image"
	ImageEditEventTypeCompleted       ImageEventType = "image_edit.completed"
	ImageEditEventTypeError           ImageEventType = "error"
)

type ImageGenerationInput

type ImageGenerationInput struct {
	Prompt string `json:"prompt"`
}

type ImageGenerationParameters

type ImageGenerationParameters struct {
	N                 *int                   `json:"n,omitempty"`                   // Number of images (1-10)
	Background        *string                `json:"background,omitempty"`          // "transparent", "opaque", "auto"
	Moderation        *string                `json:"moderation,omitempty"`          // "low", "auto"
	PartialImages     *int                   `json:"partial_images,omitempty"`      // 0-3
	Size              *string                `json:"size,omitempty"`                // "256x256", "512x512", "1024x1024", "1792x1024", "1024x1792", "1536x1024", "1024x1536", "auto"
	Quality           *string                `json:"quality,omitempty"`             // "auto", "high", "medium", "low", "hd", "standard"
	OutputCompression *int                   `json:"output_compression,omitempty"`  // compression level (0-100%)
	OutputFormat      *string                `json:"output_format,omitempty"`       // "png", "webp", "jpeg"
	Style             *string                `json:"style,omitempty"`               // "natural", "vivid"
	ResponseFormat    *string                `json:"response_format,omitempty"`     // "url", "b64_json"
	Seed              *int                   `json:"seed,omitempty"`                // seed for image generation
	NegativePrompt    *string                `json:"negative_prompt,omitempty"`     // negative prompt for image generation
	NumInferenceSteps *int                   `json:"num_inference_steps,omitempty"` // number of inference steps
	User              *string                `json:"user,omitempty"`
	InputImages       []string               `json:"input_images,omitempty"` // input images for image generation, base64 encoded or URL
	AspectRatio       *string                `json:"aspect_ratio,omitempty"` // aspect ratio of the image
	Resolution        *string                `json:"resolution,omitempty"`   // resolution of the image
	ExtraParams       map[string]interface{} `json:"-"`
}

type ImageGenerationResponseParameters

type ImageGenerationResponseParameters struct {
	Background   string `json:"background,omitempty"`
	OutputFormat string `json:"output_format,omitempty"`
	Quality      string `json:"quality,omitempty"`
	Size         string `json:"size,omitempty"`
}

type ImageInput

type ImageInput struct {
	Image []byte `json:"image"`
}

type ImageTokenDetails

type ImageTokenDetails struct {
	NImages     int `json:"-"` // Number of images generated (used internally for bifrost)
	ImageTokens int `json:"image_tokens,omitempty"`
	TextTokens  int `json:"text_tokens,omitempty"`
}

type ImageUsage

type ImageUsage struct {
	InputTokens         int                `json:"input_tokens,omitempty"` // Always text tokens unless InputTokensDetails is not nil
	InputTokensDetails  *ImageTokenDetails `json:"input_tokens_details,omitempty"`
	TotalTokens         int                `json:"total_tokens,omitempty"`
	OutputTokens        int                `json:"output_tokens,omitempty"` // Always image tokens unless OutputTokensDetails is not nil
	OutputTokensDetails *ImageTokenDetails `json:"output_tokens_details,omitempty"`
}

type ImageVariationInput

type ImageVariationInput struct {
	Image ImageInput `json:"image"`
}

type ImageVariationParameters

type ImageVariationParameters struct {
	N              *int                   `json:"n,omitempty"`               // Number of images (1-10)
	ResponseFormat *string                `json:"response_format,omitempty"` // "url", "b64_json"
	Size           *string                `json:"size,omitempty"`            // "256x256", "512x512", "1024x1024", "1792x1024", "1024x1792", "1536x1024", "1024x1536", "auto"
	User           *string                `json:"user,omitempty"`
	ExtraParams    map[string]interface{} `json:"-"`
}

type Interval

type Interval struct {
	// Optional. The start time of the interval.
	StartTime time.Time `json:"start_time,omitempty"`
	// Optional. The end time of the interval.
	EndTime time.Time `json:"end_time,omitempty"`
}

Interval represents a time interval, encoded as a start time (inclusive) and an end time (exclusive). The start time must be less than or equal to the end time. When the start equals the end time, the interval is an empty interval. (matches no time) When both start and end are unspecified, the interval matches any time.

func (*Interval) MarshalJSON

func (i *Interval) MarshalJSON() ([]byte, error)

func (*Interval) UnmarshalJSON

func (i *Interval) UnmarshalJSON(data []byte) error

type JSONKeyOrder

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

JSONKeyOrder is a lightweight helper that preserves JSON key ordering through struct serialization round-trips. Embed it in any struct with `json:"-"` tag.

LLMs are autoregressive sequence models that are sensitive to JSON key ordering in tool schemas. This helper ensures that when Bifrost deserializes and re-serializes JSON, the original key order from the client is preserved.

Usage:

type MyStruct struct {
    keyOrder JSONKeyOrder `json:"-"`
    Field1   string      `json:"field1"`
    Field2   string      `json:"field2"`
}

func (s *MyStruct) UnmarshalJSON(data []byte) error {
    type Alias MyStruct
    if err := Unmarshal(data, (*Alias)(s)); err != nil { return err }
    s.keyOrder.Capture(data)
    return nil
}

func (s MyStruct) MarshalJSON() ([]byte, error) {
    type Alias MyStruct
    data, err := Marshal(Alias(s))
    if err != nil { return nil, err }
    return s.keyOrder.Apply(data)
}

func (*JSONKeyOrder) Apply

func (o *JSONKeyOrder) Apply(data []byte) ([]byte, error)

Apply reorders the keys in serialized JSON to match the captured order. If no order was captured (programmatic construction), returns data unchanged. Call this at the end of MarshalJSON.

func (*JSONKeyOrder) Capture

func (o *JSONKeyOrder) Capture(data []byte)

Capture extracts and stores the top-level key order from raw JSON data. Call this at the end of UnmarshalJSON.

type Key

type Key struct {
	ID                   string                `json:"id"`                               // The unique identifier for the key (used by bifrost to identify the key)
	Name                 string                `json:"name"`                             // The name of the key (used by users to identify the key, not used by bifrost)
	Value                EnvVar                `json:"value"`                            // The actual API key value
	Models               []string              `json:"models"`                           // List of models this key can access
	Weight               float64               `json:"weight"`                           // Weight for load balancing between multiple keys
	AzureKeyConfig       *AzureKeyConfig       `json:"azure_key_config,omitempty"`       // Azure-specific key configuration
	VertexKeyConfig      *VertexKeyConfig      `json:"vertex_key_config,omitempty"`      // Vertex-specific key configuration
	BedrockKeyConfig     *BedrockKeyConfig     `json:"bedrock_key_config,omitempty"`     // AWS Bedrock-specific key configuration
	HuggingFaceKeyConfig *HuggingFaceKeyConfig `json:"huggingface_key_config,omitempty"` // Hugging Face-specific key configuration
	ReplicateKeyConfig   *ReplicateKeyConfig   `json:"replicate_key_config,omitempty"`   // Replicate-specific key configuration
	VLLMKeyConfig        *VLLMKeyConfig        `json:"vllm_key_config,omitempty"`        // vLLM-specific key configuration
	Enabled              *bool                 `json:"enabled,omitempty"`                // Whether the key is active (default:true)
	UseForBatchAPI       *bool                 `json:"use_for_batch_api,omitempty"`      // Whether this key can be used for batch API operations (default:false for new keys, migrated keys default to true)
	ConfigHash           string                `json:"config_hash,omitempty"`            // Hash of config.json version, used for change detection
	Status               KeyStatusType         `json:"status,omitempty"`                 // Status of key
	Description          string                `json:"description,omitempty"`            // Description of key
}

Key represents an API key and its associated configuration for a provider. It contains the key value, supported models, and a weight for load balancing.

type KeySelector

type KeySelector func(ctx *BifrostContext, keys []Key, providerKey ModelProvider, model string) (Key, error)

type KeyStatus

type KeyStatus struct {
	KeyID    string        `json:"key_id"`   // Empty for keyless providers
	Status   KeyStatusType `json:"status"`   // "success", "failed"
	Provider ModelProvider `json:"provider"` // Always populated
	Error    *BifrostError `json:"error,omitempty"`
}

KeyStatus represents the status of model listing for a specific key

type KeyStatusType

type KeyStatusType string
const (
	KeyStatusSuccess          KeyStatusType = "success"
	KeyStatusListModelsFailed KeyStatusType = "list_models_failed"
)

type LLMPlugin

type LLMPlugin interface {
	BasePlugin

	PreLLMHook(ctx *BifrostContext, req *BifrostRequest) (*BifrostRequest, *LLMPluginShortCircuit, error)
	PostLLMHook(ctx *BifrostContext, resp *BifrostResponse, bifrostErr *BifrostError) (*BifrostResponse, *BifrostError, error)
}

type LLMPluginShortCircuit

type LLMPluginShortCircuit struct {
	Response *BifrostResponse         // If set, short-circuit with this response (skips provider call)
	Stream   chan *BifrostStreamChunk // If set, short-circuit with this stream (skips provider call)
	Error    *BifrostError            // If set, short-circuit with this error (can set AllowFallbacks field)
}

LLMPluginShortCircuit represents a plugin's decision to short-circuit the normal flow. It can contain either a response (success short-circuit), a stream (streaming short-circuit), or an error (error short-circuit).

type ListModelsByKeyResult

type ListModelsByKeyResult struct {
	Response *BifrostListModelsResponse
	Err      *BifrostError
	KeyID    string
}

Structure to collect results from goroutines

type LogEventBuilder

type LogEventBuilder interface {
	Str(key, val string) LogEventBuilder
	Int(key string, val int) LogEventBuilder
	Int64(key string, val int64) LogEventBuilder
	Send()
}

LogEventBuilder provides a fluent interface for building structured log entries.

var NoopLogEvent LogEventBuilder = noopLogEventBuilder{}

NoopLogEvent is a shared singleton no-op LogEventBuilder.

type LogLevel

type LogLevel string

LogLevel represents the severity level of a log message. Internally it maps to zerolog.Level for interoperability.

const (
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
)

LogLevel constants for different severity levels.

type LogProb

type LogProb struct {
	Bytes   []int   `json:"bytes,omitempty"`
	LogProb float64 `json:"logprob"`
	Token   string  `json:"token"`
}

LogProb represents the log probability of a token.

type Logger

type Logger interface {
	// Debug logs a debug-level message.
	// This is used for detailed debugging information that is typically only needed
	// during development or troubleshooting.
	Debug(msg string, args ...any)

	// Info logs an info-level message.
	// This is used for general informational messages about normal operation.
	Info(msg string, args ...any)

	// Warn logs a warning-level message.
	// This is used for potentially harmful situations that don't prevent normal operation.
	Warn(msg string, args ...any)

	// Error logs an error-level message.
	// This is used for serious problems that need attention and may prevent normal operation.
	Error(msg string, args ...any)

	// Fatal logs a fatal-level message.
	// This is used for critical situations that require immediate attention and will terminate the program.
	Fatal(msg string, args ...any)

	// SetLevel sets the log level for the logger.
	SetLevel(level LogLevel)

	// SetOutputType sets the output type for the logger.
	SetOutputType(outputType LoggerOutputType)

	// LogHTTPRequest returns a LogEventBuilder for structured HTTP access logging.
	// The level parameter controls the log severity, msg is sent when Send() is called.
	// Use the fluent builder to attach typed fields before calling Send().
	LogHTTPRequest(level LogLevel, msg string) LogEventBuilder
}

Logger defines the interface for logging operations in the Bifrost system. Implementations of this interface should provide methods for logging messages at different severity levels.

type LoggerOutputType

type LoggerOutputType string

LoggerOutputType represents the output type of a logger.

const (
	LoggerOutputTypeJSON   LoggerOutputType = "json"
	LoggerOutputTypePretty LoggerOutputType = "pretty"
)

LoggerOutputType constants for different output types.

type MCPAuthType

type MCPAuthType string

MCPAuthType defines the authentication type for MCP connections

const (
	MCPAuthTypeNone    MCPAuthType = "none"    // No authentication
	MCPAuthTypeHeaders MCPAuthType = "headers" // Header-based authentication (API keys, etc.)
	MCPAuthTypeOauth   MCPAuthType = "oauth"   // OAuth 2.0 authentication
)

type MCPClient

type MCPClient struct {
	Config *MCPClientConfig   `json:"config"` // Tool filtering settings
	Tools  []ChatToolFunction `json:"tools"`  // Available tools
	State  MCPConnectionState `json:"state"`  // Connection state
}

MCPClient represents a connected MCP client with its configuration and tools, and connection information, after it has been initialized. It is returned by GetMCPClients() method in bifrost.

type MCPClientConfig

type MCPClientConfig struct {
	ID               string            `json:"client_id"`                   // Client ID
	Name             string            `json:"name"`                        // Client name
	IsCodeModeClient bool              `json:"is_code_mode_client"`         // Whether the client is a code mode client
	ConnectionType   MCPConnectionType `json:"connection_type"`             // How to connect (HTTP, STDIO, SSE, or InProcess)
	ConnectionString *EnvVar           `json:"connection_string,omitempty"` // HTTP or SSE URL (required for HTTP or SSE connections)
	StdioConfig      *MCPStdioConfig   `json:"stdio_config,omitempty"`      // STDIO configuration (required for STDIO connections)
	AuthType         MCPAuthType       `json:"auth_type"`                   // Authentication type (none, headers, or oauth)
	OauthConfigID    *string           `json:"oauth_config_id,omitempty"`   // OAuth config ID (references oauth_configs table)
	State            string            `json:"state,omitempty"`             // Connection state (connected, disconnected, error)
	Headers          map[string]EnvVar `json:"headers,omitempty"`           // Headers to send with the request (for headers auth type)
	InProcessServer  *server.MCPServer `json:"-"`                           // MCP server instance for in-process connections (Go package only)
	ToolsToExecute   []string          `json:"tools_to_execute,omitempty"`  // Include-only list.
	// ToolsToExecute semantics:
	// - ["*"] => all tools are included
	// - []    => no tools are included (deny-by-default)
	// - nil/omitted => treated as [] (no tools)
	// - ["tool1", "tool2"] => include only the specified tools
	ToolsToAutoExecute []string `json:"tools_to_auto_execute,omitempty"` // Auto-execute list.
	// ToolsToAutoExecute semantics:
	// - ["*"] => all tools are auto-executed
	// - []    => no tools are auto-executed (deny-by-default)
	// - nil/omitted => treated as [] (no tools)
	// - ["tool1", "tool2"] => auto-execute only the specified tools
	// Note: If a tool is in ToolsToAutoExecute but not in ToolsToExecute, it will be skipped.
	IsPingAvailable  bool               `json:"is_ping_available"`            // Whether the MCP server supports ping for health checks (default: true). If false, uses listTools for health checks.
	ToolSyncInterval time.Duration      `json:"tool_sync_interval,omitempty"` // Per-client override for tool sync interval (0 = use global, negative = disabled)
	ToolPricing      map[string]float64 `json:"tool_pricing,omitempty"`       // Tool pricing for each tool (cost per execution)
	ConfigHash       string             `json:"-"`                            // Config hash for reconciliation (not serialized)
}

MCPClientConfig defines tool filtering for an MCP client.

func NewMCPClientConfigFromMap

func NewMCPClientConfigFromMap(configMap map[string]any) *MCPClientConfig

NewMCPClientConfigFromMap creates a new MCP client config from a map[string]any.

func (*MCPClientConfig) HttpHeaders

func (c *MCPClientConfig) HttpHeaders(ctx context.Context, oauth2Provider OAuth2Provider) (map[string]string, error)

HttpHeaders returns the HTTP headers for the MCP client config.

type MCPClientConnectionInfo

type MCPClientConnectionInfo struct {
	Type               MCPConnectionType `json:"type"`                           // Connection type (HTTP, STDIO, SSE, or InProcess)
	ConnectionURL      *string           `json:"connection_url,omitempty"`       // HTTP/SSE endpoint URL (for HTTP/SSE connections)
	StdioCommandString *string           `json:"stdio_command_string,omitempty"` // Command string for display (for STDIO connections)
}

MCPClientConnectionInfo stores metadata about how a client is connected.

type MCPClientState

type MCPClientState struct {
	Name            string                   // Unique name for this client
	Conn            *client.Client           // Active MCP client connection
	ExecutionConfig *MCPClientConfig         // Tool filtering settings
	ToolMap         map[string]ChatTool      // Available tools mapped by name
	ToolNameMapping map[string]string        // Maps sanitized_name -> original_mcp_name (e.g., "notion_search" -> "notion-search")
	ConnectionInfo  *MCPClientConnectionInfo `json:"connection_info"` // Connection metadata for management
	CancelFunc      context.CancelFunc       `json:"-"`               // Cancel function for SSE connections (not serialized)
	State           MCPConnectionState       // Connection state (connected, disconnected, error)
}

MCPClientState represents a connected MCP client with its configuration and tools. It is used internally by the MCP manager to track the state of a connected MCP client.

type MCPConfig

type MCPConfig struct {
	ClientConfigs     []*MCPClientConfig    `json:"client_configs,omitempty"`      // Per-client execution configurations
	ToolManagerConfig *MCPToolManagerConfig `json:"tool_manager_config,omitempty"` // MCP tool manager configuration
	ToolSyncInterval  time.Duration         `json:"tool_sync_interval,omitempty"`  // Global default interval for syncing tools from MCP servers (0 = use default 10 min)

	// Function to fetch a new request ID for each tool call result message in agent mode,
	// this is used to ensure that the tool call result messages are unique and can be tracked in plugins or by the user.
	// This id is attached to ctx.Value(schemas.BifrostContextKeyRequestID) in the agent mode.
	// If not provider, same request ID is used for all tool call result messages without any overrides.
	FetchNewRequestIDFunc func(ctx *BifrostContext) string `json:"-"`

	// PluginPipelineProvider returns a plugin pipeline for running MCP plugin hooks.
	// Used when executeCode tool calls nested MCP tools to ensure plugins run for them.
	// The plugin pipeline should be released back to the pool using ReleasePluginPipeline.
	PluginPipelineProvider func() interface{} `json:"-"`

	// ReleasePluginPipeline releases a plugin pipeline back to the pool.
	// This should be called after the plugin pipeline is no longer needed.
	ReleasePluginPipeline func(pipeline interface{}) `json:"-"`
}

MCPConfig represents the configuration for MCP integration in Bifrost. It enables tool auto-discovery and execution from local and external MCP servers.

type MCPConnectionState

type MCPConnectionState string
const (
	MCPConnectionStateConnected    MCPConnectionState = "connected"    // Client is connected and ready to use
	MCPConnectionStateDisconnected MCPConnectionState = "disconnected" // Client is not connected
	MCPConnectionStateError        MCPConnectionState = "error"        // Client is in an error state, and cannot be used
)

type MCPConnectionType

type MCPConnectionType string

MCPConnectionType defines the communication protocol for MCP connections

const (
	MCPConnectionTypeHTTP      MCPConnectionType = "http"      // HTTP-based connection
	MCPConnectionTypeSTDIO     MCPConnectionType = "stdio"     // STDIO-based connection
	MCPConnectionTypeSSE       MCPConnectionType = "sse"       // Server-Sent Events connection
	MCPConnectionTypeInProcess MCPConnectionType = "inprocess" // In-process (in-memory) connection
)

type MCPPlugin

type MCPPlugin interface {
	BasePlugin

	PreMCPHook(ctx *BifrostContext, req *BifrostMCPRequest) (*BifrostMCPRequest, *MCPPluginShortCircuit, error)
	PostMCPHook(ctx *BifrostContext, resp *BifrostMCPResponse, bifrostErr *BifrostError) (*BifrostMCPResponse, *BifrostError, error)
}

type MCPPluginShortCircuit

type MCPPluginShortCircuit struct {
	Response *BifrostMCPResponse // If set, short-circuit with this response (skips MCP call)
	Error    *BifrostError       // If set, short-circuit with this error (can set AllowFallbacks field)
}

MCPPluginShortCircuit represents a plugin's decision to short-circuit the normal flow. It can contain either a response (success short-circuit), or an error (error short-circuit).

type MCPRequestType

type MCPRequestType string
const (
	MCPRequestTypeChatToolCall      MCPRequestType = "chat_tool_call"      // Chat API format
	MCPRequestTypeResponsesToolCall MCPRequestType = "responses_tool_call" // Responses API format
)

type MCPStdioConfig

type MCPStdioConfig struct {
	Command string   `json:"command"` // Executable command to run
	Args    []string `json:"args"`    // Command line arguments
	Envs    []string `json:"envs"`    // Environment variables required
}

MCPStdioConfig defines how to launch a STDIO-based MCP server.

type MCPToolManagerConfig

type MCPToolManagerConfig struct {
	ToolExecutionTimeout time.Duration        `json:"tool_execution_timeout"`
	MaxAgentDepth        int                  `json:"max_agent_depth"`
	CodeModeBindingLevel CodeModeBindingLevel `json:"code_mode_binding_level,omitempty"` // How tools are exposed in VFS: "server" or "tool"
}

type Model

type Model struct {
	ID                  string             `json:"id"`
	CanonicalSlug       *string            `json:"canonical_slug,omitempty"`
	Name                *string            `json:"name,omitempty"`
	Deployment          *string            `json:"deployment,omitempty"` // Name of the actual deployment
	Created             *int64             `json:"created,omitempty"`
	ContextLength       *int               `json:"context_length,omitempty"`
	MaxInputTokens      *int               `json:"max_input_tokens,omitempty"`
	MaxOutputTokens     *int               `json:"max_output_tokens,omitempty"`
	Architecture        *Architecture      `json:"architecture,omitempty"`
	Pricing             *Pricing           `json:"pricing,omitempty"`
	TopProvider         *TopProvider       `json:"top_provider,omitempty"`
	PerRequestLimits    *PerRequestLimits  `json:"per_request_limits,omitempty"`
	SupportedParameters []string           `json:"supported_parameters,omitempty"`
	DefaultParameters   *DefaultParameters `json:"default_parameters,omitempty"`
	HuggingFaceID       *string            `json:"hugging_face_id,omitempty"`
	Description         *string            `json:"description,omitempty"`

	OwnedBy          *string  `json:"owned_by,omitempty"`
	SupportedMethods []string `json:"supported_methods,omitempty"`
}

type ModelProvider

type ModelProvider string

ModelProvider represents the different AI model providers supported by Bifrost.

const (
	OpenAI      ModelProvider = "openai"
	Azure       ModelProvider = "azure"
	Anthropic   ModelProvider = "anthropic"
	Bedrock     ModelProvider = "bedrock"
	Cohere      ModelProvider = "cohere"
	Vertex      ModelProvider = "vertex"
	Mistral     ModelProvider = "mistral"
	Ollama      ModelProvider = "ollama"
	Groq        ModelProvider = "groq"
	SGL         ModelProvider = "sgl"
	Parasail    ModelProvider = "parasail"
	Perplexity  ModelProvider = "perplexity"
	Cerebras    ModelProvider = "cerebras"
	Gemini      ModelProvider = "gemini"
	Deepseek    ModelProvider = "deepseek"
	GLM         ModelProvider = "glm"
	OpenRouter  ModelProvider = "openrouter"
	Elevenlabs  ModelProvider = "elevenlabs"
	HuggingFace ModelProvider = "huggingface"
	Nebius      ModelProvider = "nebius"
	Qwen        ModelProvider = "qwen"
	XAI         ModelProvider = "xai"
	Replicate   ModelProvider = "replicate"
	VLLM        ModelProvider = "vllm"
	Runway      ModelProvider = "runway"
	Minimax     ModelProvider = "minimax"
	Moonshot    ModelProvider = "moonshot"
	Volcengine  ModelProvider = "volcengine"
)

func ParseModelString

func ParseModelString(model string, defaultProvider ModelProvider) (ModelProvider, string)

ParseModelString extracts provider and model from a model string. For model strings like "anthropic/claude", it returns ("anthropic", "claude"). For model strings like "claude", it returns ("", "claude"). Only splits on "/" when the prefix is a known Bifrost provider, so model namespaces like "meta-llama/Llama-3.1-8B" are preserved as-is.

type NetworkConfig

type NetworkConfig struct {
	// BaseURL is supported for OpenAI, Anthropic, Cohere, Mistral, and Ollama providers (required for Ollama)
	BaseURL                        string            `json:"base_url,omitempty"`                 // Base URL for the provider (optional)
	ExtraHeaders                   map[string]string `json:"extra_headers,omitempty"`            // Additional headers to include in requests (optional)
	DefaultRequestTimeoutInSeconds int               `json:"default_request_timeout_in_seconds"` // Default timeout for requests
	MaxRetries                     int               `json:"max_retries"`                        // Maximum number of retries
	RetryBackoffInitial            time.Duration     `json:"retry_backoff_initial"`              // Initial backoff duration (stored as nanoseconds, JSON as milliseconds)
	RetryBackoffMax                time.Duration     `json:"retry_backoff_max"`                  // Maximum backoff duration (stored as nanoseconds, JSON as milliseconds)
}

NetworkConfig represents the network configuration for provider connections. ExtraHeaders is automatically copied during provider initialization to prevent data races.

RetryBackoffInitial and RetryBackoffMax are stored internally as time.Duration (nanoseconds), but are serialized/deserialized to/from JSON as milliseconds (integers). This means:

  • In JSON: values are represented as milliseconds (e.g., 1000 means 1000ms)
  • In Go: values are time.Duration (e.g., 1000ms = 1000000000 nanoseconds)
  • When unmarshaling from JSON: a value of 1000 is interpreted as 1000ms, not 1000ns
  • When marshaling to JSON: a time.Duration is converted to milliseconds

func (NetworkConfig) MarshalJSON

func (nc NetworkConfig) MarshalJSON() ([]byte, error)

MarshalJSON customizes JSON marshaling for NetworkConfig. RetryBackoffInitial and RetryBackoffMax are converted from time.Duration (nanoseconds) to milliseconds (integers) in JSON.

func (*NetworkConfig) UnmarshalJSON

func (nc *NetworkConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes JSON unmarshaling for NetworkConfig. RetryBackoffInitial and RetryBackoffMax are interpreted as milliseconds in JSON, but stored as time.Duration (nanoseconds) internally.

type NoOpTracer

type NoOpTracer struct{}

NoOpTracer is a tracer that does nothing (default when tracing disabled). It satisfies the Tracer interface but performs no actual tracing operations.

func (*NoOpTracer) AddEvent

func (n *NoOpTracer) AddEvent(_ SpanHandle, _ string, _ map[string]any)

AddEvent does nothing.

func (*NoOpTracer) AddStreamingChunk

func (n *NoOpTracer) AddStreamingChunk(_ string, _ *BifrostResponse)

AddStreamingChunk does nothing.

func (*NoOpTracer) CleanupStreamAccumulator

func (n *NoOpTracer) CleanupStreamAccumulator(_ string)

CleanupStreamAccumulator does nothing.

func (*NoOpTracer) ClearDeferredSpan

func (n *NoOpTracer) ClearDeferredSpan(_ string)

ClearDeferredSpan does nothing.

func (*NoOpTracer) CreateStreamAccumulator

func (n *NoOpTracer) CreateStreamAccumulator(_ string, _ time.Time)

CreateStreamAccumulator does nothing.

func (*NoOpTracer) CreateTrace

func (n *NoOpTracer) CreateTrace(_ string) string

CreateTrace returns an empty string (no trace created).

func (*NoOpTracer) EndSpan

func (n *NoOpTracer) EndSpan(_ SpanHandle, _ SpanStatus, _ string)

EndSpan does nothing.

func (*NoOpTracer) EndTrace

func (n *NoOpTracer) EndTrace(_ string) *Trace

EndTrace returns nil (no trace to end).

func (*NoOpTracer) GetAccumulatedChunks

func (n *NoOpTracer) GetAccumulatedChunks(_ string) (*BifrostResponse, int64, int)

GetAccumulatedChunks returns nil, 0, 0.

func (*NoOpTracer) GetDeferredSpanHandle

func (n *NoOpTracer) GetDeferredSpanHandle(_ string) SpanHandle

GetDeferredSpanHandle returns nil.

func (*NoOpTracer) GetDeferredSpanID

func (n *NoOpTracer) GetDeferredSpanID(_ string) string

GetDeferredSpanID returns empty string.

func (*NoOpTracer) PopulateLLMRequestAttributes

func (n *NoOpTracer) PopulateLLMRequestAttributes(_ SpanHandle, _ *BifrostRequest)

PopulateLLMRequestAttributes does nothing.

func (*NoOpTracer) PopulateLLMResponseAttributes

func (n *NoOpTracer) PopulateLLMResponseAttributes(_ SpanHandle, _ *BifrostResponse, _ *BifrostError)

PopulateLLMResponseAttributes does nothing.

func (*NoOpTracer) ProcessStreamingChunk

func (n *NoOpTracer) ProcessStreamingChunk(_ string, _ bool, _ *BifrostResponse, _ *BifrostError) *StreamAccumulatorResult

ProcessStreamingChunk returns nil.

func (*NoOpTracer) SetAttribute

func (n *NoOpTracer) SetAttribute(_ SpanHandle, _ string, _ any)

SetAttribute does nothing.

func (*NoOpTracer) StartSpan

func (n *NoOpTracer) StartSpan(ctx context.Context, _ string, _ SpanKind) (context.Context, SpanHandle)

StartSpan returns the context unchanged and a nil handle.

func (*NoOpTracer) Stop

func (n *NoOpTracer) Stop()

Stop does nothing.

func (*NoOpTracer) StoreDeferredSpan

func (n *NoOpTracer) StoreDeferredSpan(_ string, _ SpanHandle)

StoreDeferredSpan does nothing.

type OAuth2Config

type OAuth2Config struct {
	ID              string   `json:"id"`
	ClientID        string   `json:"client_id,omitempty"`        // Optional: Will be obtained via dynamic registration (RFC 7591) if not provided
	ClientSecret    string   `json:"client_secret,omitempty"`    // Optional: For public clients using PKCE, or obtained via dynamic registration
	AuthorizeURL    string   `json:"authorize_url,omitempty"`    // Optional: Will be discovered from ServerURL if not provided
	TokenURL        string   `json:"token_url,omitempty"`        // Optional: Will be discovered from ServerURL if not provided
	RegistrationURL *string  `json:"registration_url,omitempty"` // Optional: For dynamic client registration (RFC 7591), can be discovered
	RedirectURI     string   `json:"redirect_uri"`               // Required
	Scopes          []string `json:"scopes,omitempty"`           // Optional: Can be discovered
	ServerURL       string   `json:"server_url"`                 // MCP server URL for OAuth discovery (required if URLs not provided)
	UseDiscovery    bool     `json:"use_discovery,omitempty"`    // Deprecated: Discovery now happens automatically when URLs are missing
}

OauthConfig represents OAuth client configuration

type OAuth2FlowInitiation

type OAuth2FlowInitiation struct {
	OauthConfigID string    `json:"oauth_config_id"`
	AuthorizeURL  string    `json:"authorize_url"`
	State         string    `json:"state"`
	ExpiresAt     time.Time `json:"expires_at"`
}

OauthFlowInitiation represents the response when initiating an OAuth flow

type OAuth2Provider

type OAuth2Provider interface {
	// GetAccessToken retrieves the access token for a given oauth_config_id
	GetAccessToken(ctx context.Context, oauthConfigID string) (string, error)

	// RefreshAccessToken refreshes the access token for a given oauth_config_id
	RefreshAccessToken(ctx context.Context, oauthConfigID string) error

	// ValidateToken checks if the token is still valid
	ValidateToken(ctx context.Context, oauthConfigID string) (bool, error)

	// RevokeToken revokes the OAuth token
	RevokeToken(ctx context.Context, oauthConfigID string) error
}

OauthProvider interface defines OAuth operations

type OAuth2Token

type OAuth2Token struct {
	ID              string     `json:"id"`
	AccessToken     string     `json:"access_token"`
	RefreshToken    string     `json:"refresh_token"`
	TokenType       string     `json:"token_type"`
	ExpiresAt       time.Time  `json:"expires_at"`
	Scopes          []string   `json:"scopes"`
	LastRefreshedAt *time.Time `json:"last_refreshed_at,omitempty"`
}

OauthToken represents OAuth access and refresh tokens

type OAuth2TokenExchangeRequest

type OAuth2TokenExchangeRequest struct {
	GrantType    string `json:"grant_type"`
	Code         string `json:"code,omitempty"`
	RedirectURI  string `json:"redirect_uri,omitempty"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	CodeVerifier string `json:"code_verifier,omitempty"` // PKCE verifier for authorization_code grant
}

OAuth2TokenExchangeRequest represents the OAuth token exchange request

type OAuth2TokenExchangeResponse

type OAuth2TokenExchangeResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token,omitempty"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope,omitempty"`
}

OAuth2TokenExchangeResponse represents the OAuth token exchange response

type ObservabilityPlugin

type ObservabilityPlugin interface {
	BasePlugin

	// Inject receives a completed trace for forwarding to observability backends.
	// This method is called asynchronously after the response has been written to the client.
	// The trace contains all spans that were added during request processing.
	//
	// Implementations should:
	// - Convert the trace to their backend's format
	// - Send the trace to the backend (can be async)
	// - Handle errors gracefully (log and continue)
	//
	// The context passed is a fresh background context, not the request context.
	Inject(ctx context.Context, trace *Trace) error
}

ObservabilityPlugin is an interface for plugins that receive completed traces for forwarding to observability backends (e.g., OTEL collectors, Datadog, etc.)

ObservabilityPlugins are called asynchronously after the HTTP response has been written to the wire, ensuring they don't add latency to the client response.

Plugins implementing this interface will: 1. Continue to work as regular plugins via PreLLMHook/PostLLMHook 2. Additionally receive completed traces via the Inject method

Example backends: OpenTelemetry collectors, Datadog, Jaeger, Maxim, etc.

Note: Go type assertion (plugin.(ObservabilityPlugin)) is used to identify plugins implementing this interface - no marker method is needed.

type OrderedMap

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

OrderedMap is a map that preserves insertion order of keys. It stores key-value pairs and maintains the order in which keys were first inserted. It is NOT safe for concurrent use.

func NewOrderedMap

func NewOrderedMap() *OrderedMap

NewOrderedMap creates a new empty OrderedMap.

func NewOrderedMapFromPairs

func NewOrderedMapFromPairs(pairs ...Pair) *OrderedMap

NewOrderedMapFromPairs creates an OrderedMap from key-value pairs, preserving the given order.

func NewOrderedMapWithCapacity

func NewOrderedMapWithCapacity(cap int) *OrderedMap

NewOrderedMapWithCapacity creates a new empty OrderedMap with preallocated capacity.

func OrderedMapFromMap

func OrderedMapFromMap(m map[string]interface{}) *OrderedMap

OrderedMapFromMap creates an OrderedMap from a plain map. Key order is NOT guaranteed since Go maps have undefined iteration order. Use this only when insertion order doesn't matter (e.g., for hashing).

func SafeExtractOrderedMap

func SafeExtractOrderedMap(value interface{}) (*OrderedMap, bool)

func (*OrderedMap) Clone

func (om *OrderedMap) Clone() *OrderedMap

Clone creates a shallow copy of the OrderedMap (keys and top-level values are copied, but nested values share references).

func (*OrderedMap) Delete

func (om *OrderedMap) Delete(key string)

Delete removes a key and its value. The key is also removed from the ordered keys list.

func (*OrderedMap) Get

func (om *OrderedMap) Get(key string) (interface{}, bool)

Get returns the value associated with the key and whether the key exists.

func (*OrderedMap) Keys

func (om *OrderedMap) Keys() []string

Keys returns the keys in insertion order. The returned slice is a copy.

func (*OrderedMap) Len

func (om *OrderedMap) Len() int

Len returns the number of key-value pairs.

func (OrderedMap) MarshalJSON

func (om OrderedMap) MarshalJSON() ([]byte, error)

MarshalJSON serializes the OrderedMap to JSON, preserving insertion order of keys. Uses a value receiver so that both OrderedMap and *OrderedMap invoke this method (critical for []OrderedMap slices like AnyOf/OneOf/AllOf in ToolFunctionParameters).

func (*OrderedMap) MarshalSorted

func (om *OrderedMap) MarshalSorted() ([]byte, error)

MarshalSorted serializes the OrderedMap to JSON with keys sorted alphabetically. Use this when deterministic output is needed regardless of insertion order (e.g., hashing).

func (*OrderedMap) Range

func (om *OrderedMap) Range(fn func(key string, value interface{}) bool)

Range iterates over key-value pairs in insertion order. If fn returns false, iteration stops.

func (*OrderedMap) Set

func (om *OrderedMap) Set(key string, value interface{})

Set sets the value for a key. If the key is new, it is appended to the end. If the key already exists, its value is updated in place without changing order.

func (*OrderedMap) ToMap

func (om *OrderedMap) ToMap() map[string]interface{}

ToMap returns a plain map[string]interface{} with the same key-value pairs. The returned map does not preserve insertion order.

func (*OrderedMap) UnmarshalJSON

func (om *OrderedMap) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes JSON into the OrderedMap, preserving the key order from the JSON document. Nested objects are also deserialized as *OrderedMap. Note: uses encoding/json.Decoder (not sonic) because token-by-token decoding is required to preserve key order from the JSON document.

type Pair

type Pair struct {
	Key   string
	Value interface{}
}

Pair is a key-value pair for constructing OrderedMaps with order preserved.

func KV

func KV(key string, value interface{}) Pair

KV is a shorthand constructor for Pair.

type PerRequestLimits

type PerRequestLimits struct {
	PromptTokens     *int `json:"prompt_tokens,omitempty"`
	CompletionTokens *int `json:"completion_tokens,omitempty"`
}

type PluginConfig

type PluginConfig struct {
	Enabled bool    `json:"enabled"`
	Name    string  `json:"name"`
	Path    *string `json:"path,omitempty"`
	Version *int16  `json:"version,omitempty"`
	Config  any     `json:"config,omitempty"`
}

PluginConfig is the configuration for a plugin. It contains the name of the plugin, whether it is enabled, and the configuration for the plugin.

type PluginShortCircuit

type PluginShortCircuit = LLMPluginShortCircuit

PluginShortCircuit is the legacy name for LLMPluginShortCircuit (v1.3.x compatibility). Deprecated: Use LLMPluginShortCircuit instead.

type PluginStatus

type PluginStatus struct {
	Name   string       `json:"name"` // Display name of the plugin
	Status string       `json:"status"`
	Logs   []string     `json:"logs"`
	Types  []PluginType `json:"types"` // Plugin types (LLM, MCP, HTTP)
}

PluginStatus represents the status of a plugin.

type PluginType

type PluginType string

PluginType represents the type of plugin.

const (
	PluginTypeLLM  PluginType = "llm"
	PluginTypeMCP  PluginType = "mcp"
	PluginTypeHTTP PluginType = "http"
)

type PostHookRunner

type PostHookRunner func(ctx *BifrostContext, result *BifrostResponse, err *BifrostError) (*BifrostResponse, *BifrostError)

type Pricing

type Pricing struct {
	Prompt            *string `json:"prompt,omitempty"`
	Completion        *string `json:"completion,omitempty"`
	Request           *string `json:"request,omitempty"`
	Image             *string `json:"image,omitempty"`
	WebSearch         *string `json:"web_search,omitempty"`
	InternalReasoning *string `json:"internal_reasoning,omitempty"`
	InputCacheRead    *string `json:"input_cache_read,omitempty"`
	InputCacheWrite   *string `json:"input_cache_write,omitempty"`
}

type PricingOverrideMatchType

type PricingOverrideMatchType string
const (
	PricingOverrideMatchExact    PricingOverrideMatchType = "exact"
	PricingOverrideMatchWildcard PricingOverrideMatchType = "wildcard"
	PricingOverrideMatchRegex    PricingOverrideMatchType = "regex"
)

type Provider

type Provider interface {
	// GetProviderKey returns the provider's identifier
	GetProviderKey() ModelProvider
	// ListModels performs a list models request
	ListModels(ctx *BifrostContext, keys []Key, request *BifrostListModelsRequest) (*BifrostListModelsResponse, *BifrostError)
	// TextCompletion performs a text completion request
	TextCompletion(ctx *BifrostContext, key Key, request *BifrostTextCompletionRequest) (*BifrostTextCompletionResponse, *BifrostError)
	// TextCompletionStream performs a text completion stream request
	TextCompletionStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key, request *BifrostTextCompletionRequest) (chan *BifrostStreamChunk, *BifrostError)
	// ChatCompletion performs a chat completion request
	ChatCompletion(ctx *BifrostContext, key Key, request *BifrostChatRequest) (*BifrostChatResponse, *BifrostError)
	// ChatCompletionStream performs a chat completion stream request
	ChatCompletionStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key, request *BifrostChatRequest) (chan *BifrostStreamChunk, *BifrostError)
	// Responses performs a completion request using the Responses API (uses chat completion request internally for non-openai providers)
	Responses(ctx *BifrostContext, key Key, request *BifrostResponsesRequest) (*BifrostResponsesResponse, *BifrostError)
	// ResponsesStream performs a completion request using the Responses API stream (uses chat completion stream request internally for non-openai providers)
	ResponsesStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key, request *BifrostResponsesRequest) (chan *BifrostStreamChunk, *BifrostError)
	// CountTokens performs a count tokens request
	CountTokens(ctx *BifrostContext, key Key, request *BifrostResponsesRequest) (*BifrostCountTokensResponse, *BifrostError)
	// Embedding performs an embedding request
	Embedding(ctx *BifrostContext, key Key, request *BifrostEmbeddingRequest) (*BifrostEmbeddingResponse, *BifrostError)
	// Rerank performs a rerank request to reorder documents by relevance to a query
	Rerank(ctx *BifrostContext, key Key, request *BifrostRerankRequest) (*BifrostRerankResponse, *BifrostError)
	// Speech performs a text to speech request
	Speech(ctx *BifrostContext, key Key, request *BifrostSpeechRequest) (*BifrostSpeechResponse, *BifrostError)
	// SpeechStream performs a text to speech stream request
	SpeechStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key, request *BifrostSpeechRequest) (chan *BifrostStreamChunk, *BifrostError)
	// Transcription performs a transcription request
	Transcription(ctx *BifrostContext, key Key, request *BifrostTranscriptionRequest) (*BifrostTranscriptionResponse, *BifrostError)
	// TranscriptionStream performs a transcription stream request
	TranscriptionStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key, request *BifrostTranscriptionRequest) (chan *BifrostStreamChunk, *BifrostError)
	// ImageGeneration performs an image generation request
	ImageGeneration(ctx *BifrostContext, key Key, request *BifrostImageGenerationRequest) (
		*BifrostImageGenerationResponse, *BifrostError)
	// ImageGenerationStream performs an image generation stream request
	ImageGenerationStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key,
		request *BifrostImageGenerationRequest) (chan *BifrostStreamChunk, *BifrostError)
	// ImageEdit performs an image edit request
	ImageEdit(ctx *BifrostContext, key Key, request *BifrostImageEditRequest) (*BifrostImageGenerationResponse, *BifrostError)
	// ImageEditStream performs an image edit stream request
	ImageEditStream(ctx *BifrostContext, postHookRunner PostHookRunner, key Key,
		request *BifrostImageEditRequest) (chan *BifrostStreamChunk, *BifrostError)
	// ImageVariation performs an image variation request
	ImageVariation(ctx *BifrostContext, key Key, request *BifrostImageVariationRequest) (*BifrostImageGenerationResponse, *BifrostError)
	// VideoGeneration performs a video generation request
	VideoGeneration(ctx *BifrostContext, key Key, request *BifrostVideoGenerationRequest) (*BifrostVideoGenerationResponse, *BifrostError)
	// VideoRetrieve retrieves a video from the provider
	VideoRetrieve(ctx *BifrostContext, key Key, request *BifrostVideoRetrieveRequest) (*BifrostVideoGenerationResponse, *BifrostError)
	// VideoDownload downloads a video from the provider
	VideoDownload(ctx *BifrostContext, key Key, request *BifrostVideoDownloadRequest) (*BifrostVideoDownloadResponse, *BifrostError)
	// VideoDelete deletes a video from the provider
	VideoDelete(ctx *BifrostContext, key Key, request *BifrostVideoDeleteRequest) (*BifrostVideoDeleteResponse, *BifrostError)
	// VideoList lists videos from the provider
	VideoList(ctx *BifrostContext, key Key, request *BifrostVideoListRequest) (*BifrostVideoListResponse, *BifrostError)
	// VideoRemix remixes a video from the provider
	VideoRemix(ctx *BifrostContext, key Key, request *BifrostVideoRemixRequest) (*BifrostVideoGenerationResponse, *BifrostError)
	// BatchCreate creates a new batch job for asynchronous processing
	BatchCreate(ctx *BifrostContext, key Key, request *BifrostBatchCreateRequest) (*BifrostBatchCreateResponse, *BifrostError)
	// BatchList lists batch jobs
	BatchList(ctx *BifrostContext, keys []Key, request *BifrostBatchListRequest) (*BifrostBatchListResponse, *BifrostError)
	// BatchRetrieve retrieves a specific batch job
	BatchRetrieve(ctx *BifrostContext, keys []Key, request *BifrostBatchRetrieveRequest) (*BifrostBatchRetrieveResponse, *BifrostError)
	// BatchCancel cancels a batch job
	BatchCancel(ctx *BifrostContext, keys []Key, request *BifrostBatchCancelRequest) (*BifrostBatchCancelResponse, *BifrostError)
	// BatchResults retrieves results from a completed batch job
	BatchResults(ctx *BifrostContext, keys []Key, request *BifrostBatchResultsRequest) (*BifrostBatchResultsResponse, *BifrostError)
	// FileUpload uploads a file to the provider
	FileUpload(ctx *BifrostContext, key Key, request *BifrostFileUploadRequest) (*BifrostFileUploadResponse, *BifrostError)
	// FileList lists files from the provider
	FileList(ctx *BifrostContext, keys []Key, request *BifrostFileListRequest) (*BifrostFileListResponse, *BifrostError)
	// FileRetrieve retrieves file metadata from the provider
	FileRetrieve(ctx *BifrostContext, keys []Key, request *BifrostFileRetrieveRequest) (*BifrostFileRetrieveResponse, *BifrostError)
	// FileDelete deletes a file from the provider
	FileDelete(ctx *BifrostContext, keys []Key, request *BifrostFileDeleteRequest) (*BifrostFileDeleteResponse, *BifrostError)
	// FileContent downloads file content from the provider
	FileContent(ctx *BifrostContext, keys []Key, request *BifrostFileContentRequest) (*BifrostFileContentResponse, *BifrostError)
	// ContainerCreate creates a new container
	ContainerCreate(ctx *BifrostContext, key Key, request *BifrostContainerCreateRequest) (*BifrostContainerCreateResponse, *BifrostError)
	// ContainerList lists containers
	ContainerList(ctx *BifrostContext, keys []Key, request *BifrostContainerListRequest) (*BifrostContainerListResponse, *BifrostError)
	// ContainerRetrieve retrieves a specific container
	ContainerRetrieve(ctx *BifrostContext, keys []Key, request *BifrostContainerRetrieveRequest) (*BifrostContainerRetrieveResponse, *BifrostError)
	// ContainerDelete deletes a container
	ContainerDelete(ctx *BifrostContext, keys []Key, request *BifrostContainerDeleteRequest) (*BifrostContainerDeleteResponse, *BifrostError)
	// ContainerFileCreate creates a file in a container
	ContainerFileCreate(ctx *BifrostContext, key Key, request *BifrostContainerFileCreateRequest) (*BifrostContainerFileCreateResponse, *BifrostError)
	// ContainerFileList lists files in a container
	ContainerFileList(ctx *BifrostContext, keys []Key, request *BifrostContainerFileListRequest) (*BifrostContainerFileListResponse, *BifrostError)
	// ContainerFileRetrieve retrieves a file from a container
	ContainerFileRetrieve(ctx *BifrostContext, keys []Key, request *BifrostContainerFileRetrieveRequest) (*BifrostContainerFileRetrieveResponse, *BifrostError)
	// ContainerFileContent retrieves the content of a file from a container
	ContainerFileContent(ctx *BifrostContext, keys []Key, request *BifrostContainerFileContentRequest) (*BifrostContainerFileContentResponse, *BifrostError)
	// ContainerFileDelete deletes a file from a container
	ContainerFileDelete(ctx *BifrostContext, keys []Key, request *BifrostContainerFileDeleteRequest) (*BifrostContainerFileDeleteResponse, *BifrostError)
}

Provider defines the interface for AI model providers.

type ProviderConfig

type ProviderConfig struct {
	NetworkConfig            NetworkConfig            `json:"network_config"`              // Network configuration
	ConcurrencyAndBufferSize ConcurrencyAndBufferSize `json:"concurrency_and_buffer_size"` // Concurrency settings
	// Logger instance, can be provided by the user or bifrost default logger is used if not provided
	Logger               Logger                    `json:"-"`
	ProxyConfig          *ProxyConfig              `json:"proxy_config,omitempty"` // Proxy configuration
	SendBackRawRequest   bool                      `json:"send_back_raw_request"`  // Send raw request back in the bifrost response (default: false)
	SendBackRawResponse  bool                      `json:"send_back_raw_response"` // Send raw response back in the bifrost response (default: false)
	CustomProviderConfig *CustomProviderConfig     `json:"custom_provider_config,omitempty"`
	PricingOverrides     []ProviderPricingOverride `json:"pricing_overrides,omitempty"`
}

ProviderConfig represents the complete configuration for a provider. An array of ProviderConfig needs to be provided in GetConfigForProvider in your account interface implementation.

func (*ProviderConfig) CheckAndSetDefaults

func (config *ProviderConfig) CheckAndSetDefaults()

type ProviderPricingOverride

type ProviderPricingOverride struct {
	ModelPattern string                   `json:"model_pattern"`
	MatchType    PricingOverrideMatchType `json:"match_type"`
	RequestTypes []RequestType            `json:"request_types,omitempty"`

	// Basic token pricing
	InputCostPerToken  *float64 `json:"input_cost_per_token,omitempty"`
	OutputCostPerToken *float64 `json:"output_cost_per_token,omitempty"`

	// Additional pricing for media
	InputCostPerVideoPerSecond *float64 `json:"input_cost_per_video_per_second,omitempty"`
	InputCostPerAudioPerSecond *float64 `json:"input_cost_per_audio_per_second,omitempty"`

	// Character-based pricing
	InputCostPerCharacter  *float64 `json:"input_cost_per_character,omitempty"`
	OutputCostPerCharacter *float64 `json:"output_cost_per_character,omitempty"`

	// Pricing above 128k tokens
	InputCostPerTokenAbove128kTokens          *float64 `json:"input_cost_per_token_above_128k_tokens,omitempty"`
	InputCostPerCharacterAbove128kTokens      *float64 `json:"input_cost_per_character_above_128k_tokens,omitempty"`
	InputCostPerImageAbove128kTokens          *float64 `json:"input_cost_per_image_above_128k_tokens,omitempty"`
	InputCostPerVideoPerSecondAbove128kTokens *float64 `json:"input_cost_per_video_per_second_above_128k_tokens,omitempty"`
	InputCostPerAudioPerSecondAbove128kTokens *float64 `json:"input_cost_per_audio_per_second_above_128k_tokens,omitempty"`
	OutputCostPerTokenAbove128kTokens         *float64 `json:"output_cost_per_token_above_128k_tokens,omitempty"`
	OutputCostPerCharacterAbove128kTokens     *float64 `json:"output_cost_per_character_above_128k_tokens,omitempty"`

	// Pricing above 200k tokens
	InputCostPerTokenAbove200kTokens           *float64 `json:"input_cost_per_token_above_200k_tokens,omitempty"`
	OutputCostPerTokenAbove200kTokens          *float64 `json:"output_cost_per_token_above_200k_tokens,omitempty"`
	CacheCreationInputTokenCostAbove200kTokens *float64 `json:"cache_creation_input_token_cost_above_200k_tokens,omitempty"`
	CacheReadInputTokenCostAbove200kTokens     *float64 `json:"cache_read_input_token_cost_above_200k_tokens,omitempty"`

	// Cache and batch pricing
	CacheReadInputTokenCost     *float64 `json:"cache_read_input_token_cost,omitempty"`
	CacheCreationInputTokenCost *float64 `json:"cache_creation_input_token_cost,omitempty"`
	InputCostPerTokenBatches    *float64 `json:"input_cost_per_token_batches,omitempty"`
	OutputCostPerTokenBatches   *float64 `json:"output_cost_per_token_batches,omitempty"`

	// Image generation pricing
	InputCostPerImageToken       *float64 `json:"input_cost_per_image_token,omitempty"`
	OutputCostPerImageToken      *float64 `json:"output_cost_per_image_token,omitempty"`
	InputCostPerImage            *float64 `json:"input_cost_per_image,omitempty"`
	OutputCostPerImage           *float64 `json:"output_cost_per_image,omitempty"`
	CacheReadInputImageTokenCost *float64 `json:"cache_read_input_image_token_cost,omitempty"`
}

ProviderPricingOverride contains a partial pricing patch applied at lookup time. Any nil field falls back to the base pricing data.

type ProxyConfig

type ProxyConfig struct {
	Type      ProxyType `json:"type"`        // Type of proxy to use
	URL       string    `json:"url"`         // URL of the proxy server
	Username  string    `json:"username"`    // Username for proxy authentication
	Password  string    `json:"password"`    // Password for proxy authentication
	CACertPEM string    `json:"ca_cert_pem"` // PEM-encoded CA certificate to trust for TLS connections through the proxy
}

ProxyConfig holds the configuration for proxy settings.

func (*ProxyConfig) Redacted

func (pc *ProxyConfig) Redacted() *ProxyConfig

Redacted returns a redacted copy of the proxy configuration.

type ProxyType

type ProxyType string

ProxyType defines the type of proxy to use for connections.

const (
	// NoProxy indicates no proxy should be used
	NoProxy ProxyType = "none"
	// HTTPProxy indicates an HTTP proxy should be used
	HTTPProxy ProxyType = "http"
	// Socks5Proxy indicates a SOCKS5 proxy should be used
	Socks5Proxy ProxyType = "socks5"
	// EnvProxy indicates the proxy should be read from environment variables
	EnvProxy ProxyType = "environment"
)

type ReplicateKeyConfig

type ReplicateKeyConfig struct {
	Deployments map[string]string `json:"deployments,omitempty"` // Mapping of model identifiers to deployment names
}

type RequestType

type RequestType string

RequestType represents the type of request being made to a provider.

const (
	ListModelsRequest            RequestType = "list_models"
	TextCompletionRequest        RequestType = "text_completion"
	TextCompletionStreamRequest  RequestType = "text_completion_stream"
	ChatCompletionRequest        RequestType = "chat_completion"
	ChatCompletionStreamRequest  RequestType = "chat_completion_stream"
	ResponsesRequest             RequestType = "responses"
	ResponsesStreamRequest       RequestType = "responses_stream"
	EmbeddingRequest             RequestType = "embedding"
	SpeechRequest                RequestType = "speech"
	SpeechStreamRequest          RequestType = "speech_stream"
	TranscriptionRequest         RequestType = "transcription"
	TranscriptionStreamRequest   RequestType = "transcription_stream"
	ImageGenerationRequest       RequestType = "image_generation"
	ImageGenerationStreamRequest RequestType = "image_generation_stream"
	ImageEditRequest             RequestType = "image_edit"
	ImageEditStreamRequest       RequestType = "image_edit_stream"
	ImageVariationRequest        RequestType = "image_variation"
	VideoGenerationRequest       RequestType = "video_generation"
	VideoRetrieveRequest         RequestType = "video_retrieve"
	VideoDownloadRequest         RequestType = "video_download"
	VideoDeleteRequest           RequestType = "video_delete"
	VideoListRequest             RequestType = "video_list"
	VideoRemixRequest            RequestType = "video_remix"
	BatchCreateRequest           RequestType = "batch_create"
	BatchListRequest             RequestType = "batch_list"
	BatchRetrieveRequest         RequestType = "batch_retrieve"
	BatchCancelRequest           RequestType = "batch_cancel"
	BatchResultsRequest          RequestType = "batch_results"
	FileUploadRequest            RequestType = "file_upload"
	FileListRequest              RequestType = "file_list"
	FileRetrieveRequest          RequestType = "file_retrieve"
	FileDeleteRequest            RequestType = "file_delete"
	FileContentRequest           RequestType = "file_content"
	ContainerCreateRequest       RequestType = "container_create"
	ContainerListRequest         RequestType = "container_list"
	ContainerRetrieveRequest     RequestType = "container_retrieve"
	ContainerDeleteRequest       RequestType = "container_delete"
	ContainerFileCreateRequest   RequestType = "container_file_create"
	ContainerFileListRequest     RequestType = "container_file_list"
	ContainerFileRetrieveRequest RequestType = "container_file_retrieve"
	ContainerFileContentRequest  RequestType = "container_file_content"
	ContainerFileDeleteRequest   RequestType = "container_file_delete"
	RerankRequest                RequestType = "rerank"
	CountTokensRequest           RequestType = "count_tokens"
	MCPToolExecutionRequest      RequestType = "mcp_tool_execution"
	UnknownRequest               RequestType = "unknown"
)

type RerankDocument

type RerankDocument struct {
	Text string                 `json:"text"`
	ID   *string                `json:"id,omitempty"`
	Meta map[string]interface{} `json:"meta,omitempty"`
}

RerankDocument represents a document to be reranked.

type RerankParameters

type RerankParameters struct {
	TopN            *int                   `json:"top_n,omitempty"`
	MaxTokensPerDoc *int                   `json:"max_tokens_per_doc,omitempty"`
	Priority        *int                   `json:"priority,omitempty"`
	ReturnDocuments *bool                  `json:"return_documents,omitempty"`
	ExtraParams     map[string]interface{} `json:"-"`
}

RerankParameters contains optional parameters for a rerank request.

type RerankResult

type RerankResult struct {
	Index          int             `json:"index"`
	RelevanceScore float64         `json:"relevance_score"`
	Document       *RerankDocument `json:"document,omitempty"`
}

RerankResult represents a single reranked document with its relevance score.

type ResponsesCodeInterpreterOutput

type ResponsesCodeInterpreterOutput struct {
	*ResponsesCodeInterpreterOutputLogs
	*ResponsesCodeInterpreterOutputImage
}

ResponsesCodeInterpreterOutput represents a code interpreter output

func (ResponsesCodeInterpreterOutput) MarshalJSON

func (o ResponsesCodeInterpreterOutput) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ResponsesCodeInterpreterOutput

func (*ResponsesCodeInterpreterOutput) UnmarshalJSON

func (o *ResponsesCodeInterpreterOutput) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ResponsesCodeInterpreterOutput

type ResponsesCodeInterpreterOutputImage

type ResponsesCodeInterpreterOutputImage struct {
	Type string `json:"type"` // always "image"
	URL  string `json:"url"`
}

ResponsesCodeInterpreterOutputImage represents the image output from the code interpreter

type ResponsesCodeInterpreterOutputLogs

type ResponsesCodeInterpreterOutputLogs struct {
	Logs string `json:"logs"`
	Type string `json:"type"` // always "logs"
}

ResponsesCodeInterpreterOutputLogs represents the logs output from the code interpreter

type ResponsesCodeInterpreterToolCall

type ResponsesCodeInterpreterToolCall struct {
	Code        *string                          `json:"code"`         // The code to run, or null if not available
	ContainerID string                           `json:"container_id"` // The ID of the container used to run the code
	Outputs     []ResponsesCodeInterpreterOutput `json:"outputs"`      // The outputs generated by the code interpreter, can be null
}

ResponsesCodeInterpreterToolCall represents a code interpreter tool call

type ResponsesComputerToolCall

type ResponsesComputerToolCall struct {
	PendingSafetyChecks []ResponsesComputerToolCallPendingSafetyCheck `json:"pending_safety_checks,omitempty"`
}

ResponsesComputerToolCall represents a computer tool call

type ResponsesComputerToolCallAcknowledgedSafetyCheck

type ResponsesComputerToolCallAcknowledgedSafetyCheck struct {
	ID      string  `json:"id"`
	Code    *string `json:"code,omitempty"`
	Message *string `json:"message,omitempty"`
}

ResponsesComputerToolCallAcknowledgedSafetyCheck represents a safety check that has been acknowledged by the developer

type ResponsesComputerToolCallAction

type ResponsesComputerToolCallAction struct {
	Type    string                                `json:"type"`             // "click" | "double_click" | "drag" | "keypress" | "move" | "screenshot" | "scroll" | "type" | "wait" | "zoom"
	X       *int                                  `json:"x,omitempty"`      // Common X coordinate field (Click, DoubleClick, Move, Scroll)
	Y       *int                                  `json:"y,omitempty"`      // Common Y coordinate field (Click, DoubleClick, Move, Scroll)
	Button  *string                               `json:"button,omitempty"` // "left" | "right" | "wheel" | "back" | "forward"
	Path    []ResponsesComputerToolCallActionPath `json:"path,omitempty"`
	Keys    []string                              `json:"keys,omitempty"`
	ScrollX *int                                  `json:"scroll_x,omitempty"`
	ScrollY *int                                  `json:"scroll_y,omitempty"`
	Text    *string                               `json:"text,omitempty"`
	Region  []int                                 `json:"region,omitempty"` // [x1, y1, x2, y2] for zoom action (Anthropic Opus 4.5)
}

ResponsesComputerToolCallAction represents the different types of computer actions

type ResponsesComputerToolCallActionPath

type ResponsesComputerToolCallActionPath struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type ResponsesComputerToolCallOutput

type ResponsesComputerToolCallOutput struct {
	AcknowledgedSafetyChecks []ResponsesComputerToolCallAcknowledgedSafetyCheck `json:"acknowledged_safety_checks,omitempty"`
}

ResponsesComputerToolCallOutput represents a computer tool call output

type ResponsesComputerToolCallOutputData

type ResponsesComputerToolCallOutputData struct {
	Type     string  `json:"type"` // always "computer_screenshot"
	FileID   *string `json:"file_id,omitempty"`
	ImageURL *string `json:"image_url,omitempty"`
}

ResponsesComputerToolCallOutputData represents a computer screenshot image used with the computer use tool

type ResponsesComputerToolCallPendingSafetyCheck

type ResponsesComputerToolCallPendingSafetyCheck struct {
	ID      string `json:"id"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

ResponsesComputerToolCallPendingSafetyCheck represents a pending safety check

type ResponsesCustomToolCall

type ResponsesCustomToolCall struct {
	Input string `json:"input"` // The input for the custom tool call generated by the model
}

ResponsesCustomToolCall represents a custom tool call

type ResponsesFileSearchToolCall

type ResponsesFileSearchToolCall struct {
	Queries []string                            `json:"queries"`
	Results []ResponsesFileSearchToolCallResult `json:"results,omitempty"`
}

type ResponsesFileSearchToolCallResult

type ResponsesFileSearchToolCallResult struct {
	Attributes *map[string]any `json:"attributes,omitempty"`
	FileID     *string         `json:"file_id,omitempty"`
	Filename   *string         `json:"filename,omitempty"`
	Score      *float64        `json:"score,omitempty"`
	Text       *string         `json:"text,omitempty"`
}

type ResponsesFunctionToolCallOutput

type ResponsesFunctionToolCallOutput struct {
	ResponsesFunctionToolCallOutputStr    *string //A JSON string of the output of the function tool call.
	ResponsesFunctionToolCallOutputBlocks []ResponsesMessageContentBlock
}

ResponsesFunctionToolCallOutput represents a function tool call output

func (ResponsesFunctionToolCallOutput) MarshalJSON

func (rf ResponsesFunctionToolCallOutput) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ResponsesFunctionToolCallOutput. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ResponsesFunctionToolCallOutput) UnmarshalJSON

func (rf *ResponsesFunctionToolCallOutput) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ResponsesFunctionToolCallOutput. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ResponsesImageGenerationCall

type ResponsesImageGenerationCall struct {
	Result string `json:"result"`
}

ResponsesImageGenerationCall represents an image generation tool call

type ResponsesInputMessageContentBlockAudio

type ResponsesInputMessageContentBlockAudio struct {
	Format string `json:"format"` // "mp3" or "wav"
	Data   string `json:"data"`   // base64 encoded audio data
}

type ResponsesInputMessageContentBlockFile

type ResponsesInputMessageContentBlockFile struct {
	FileData *string `json:"file_data,omitempty"` // Base64 encoded file data or plain text
	FileURL  *string `json:"file_url,omitempty"`  // Direct URL to file
	Filename *string `json:"filename,omitempty"`  // Name of the file
	FileType *string `json:"file_type,omitempty"` // MIME type (e.g., "application/pdf", "text/plain")
}

type ResponsesInputMessageContentBlockImage

type ResponsesInputMessageContentBlockImage struct {
	ImageURL *string `json:"image_url,omitempty"`
	Detail   *string `json:"detail,omitempty"` // "low" | "high" | "auto"
}

type ResponsesLocalShellToolCallAction

type ResponsesLocalShellToolCallAction struct {
	Command          []string `json:"command"`
	Env              []string `json:"env"`
	Type             string   `json:"type"` // always "exec"
	TimeoutMS        *int     `json:"timeout_ms,omitempty"`
	User             *string  `json:"user,omitempty"`
	WorkingDirectory *string  `json:"working_directory,omitempty"`
}

ResponsesLocalShellCallAction represents the different types of local shell actions

type ResponsesMCPApprovalRequestAction

type ResponsesMCPApprovalRequestAction struct {
	ID          string `json:"id"`
	Type        string `json:"type"` // always "mcp_approval_request"
	Name        string `json:"name"`
	ServerLabel string `json:"server_label"`
	Arguments   string `json:"arguments"`
}

ResponsesMCPApprovalRequestAction represents the different types of MCP approval request actions

type ResponsesMCPApprovalResponse

type ResponsesMCPApprovalResponse struct {
	ApprovalResponseID string  `json:"approval_response_id"`
	Approve            bool    `json:"approve"`
	Reason             *string `json:"reason,omitempty"`
}

ResponsesMCPApprovalResponse represents a MCP approval response

type ResponsesMCPListTools

type ResponsesMCPListTools struct {
	ServerLabel string             `json:"server_label"`
	Tools       []ResponsesMCPTool `json:"tools"`
}

ResponsesMCPListTools represents a list of MCP tools

type ResponsesMCPTool

type ResponsesMCPTool struct {
	Name        string          `json:"name"`
	InputSchema map[string]any  `json:"input_schema"`
	Description *string         `json:"description,omitempty"`
	Annotations *map[string]any `json:"annotations,omitempty"`
}

ResponsesMCPTool represents an MCP tool

type ResponsesMCPToolCall

type ResponsesMCPToolCall struct {
	ServerLabel string `json:"server_label"` // The label of the MCP server running the tool
}

ResponsesMCPToolCall represents a MCP tool call

type ResponsesMessage

type ResponsesMessage struct {
	ID     *string               `json:"id,omitempty"` // Common ID field for most item types
	Type   *ResponsesMessageType `json:"type,omitempty"`
	Status *string               `json:"status,omitempty"` // "in_progress" | "completed" | "incomplete" | "interpreting" | "failed"

	Role    *ResponsesMessageRoleType `json:"role,omitempty"`
	Content *ResponsesMessageContent  `json:"content,omitempty"`

	*ResponsesToolMessage // For Tool calls and outputs

	// Reasoning
	// gpt-oss models include only reasoning_text content blocks in a message, while other openai models include summaries+encrypted_content
	*ResponsesReasoning
}

ResponsesMessage is a union type that can contain different types of input items Only one of the fields should be set at a time

func DeepCopyResponsesMessage

func DeepCopyResponsesMessage(original ResponsesMessage) ResponsesMessage

DeepCopyResponsesMessage creates a deep copy of a ResponsesMessage to prevent shared data mutation between different plugin accumulators

type ResponsesMessageContent

type ResponsesMessageContent struct {
	ContentStr *string // Simple text content

	// Output will ALWAYS be an array of content blocks
	ContentBlocks []ResponsesMessageContentBlock // Rich content with multiple media types
}

ResponsesMessageContent is a union type that can be either a string or array of content blocks

func (ResponsesMessageContent) MarshalJSON

func (rc ResponsesMessageContent) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ResponsesMessageContent. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ResponsesMessageContent) UnmarshalJSON

func (rc *ResponsesMessageContent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ResponsesMessageContent. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ResponsesMessageContentBlock

type ResponsesMessageContentBlock struct {
	Type      ResponsesMessageContentBlockType `json:"type"`
	FileID    *string                          `json:"file_id,omitempty"` // Reference to uploaded file
	Text      *string                          `json:"text,omitempty"`
	Signature *string                          `json:"signature,omitempty"` // Signature of the content (for reasoning)

	*ResponsesInputMessageContentBlockImage
	*ResponsesInputMessageContentBlockFile
	Audio *ResponsesInputMessageContentBlockAudio `json:"input_audio,omitempty"`

	*ResponsesOutputMessageContentText            // Normal text output from the model
	*ResponsesOutputMessageContentRefusal         // Model refusal to answer
	*ResponsesOutputMessageContentRenderedContent // Rendered content from search entry point
	*ResponsesOutputMessageContentCompaction      // Compaction content from the model

	// Not in OpenAI's schemas, but sent by a few providers (Anthropic, Bedrock are some of them)
	CacheControl *CacheControl `json:"cache_control,omitempty"`
	Citations    *Citations    `json:"citations,omitempty"`
}

ResponsesMessageContentBlock represents different types of content (text, image, file, audio) Only one of the content type fields should be set

type ResponsesMessageContentBlockType

type ResponsesMessageContentBlockType string
const (
	ResponsesInputMessageContentBlockTypeText  ResponsesMessageContentBlockType = "input_text"
	ResponsesInputMessageContentBlockTypeImage ResponsesMessageContentBlockType = "input_image"
	ResponsesInputMessageContentBlockTypeFile  ResponsesMessageContentBlockType = "input_file"
	ResponsesInputMessageContentBlockTypeAudio ResponsesMessageContentBlockType = "input_audio"
	ResponsesOutputMessageContentTypeText      ResponsesMessageContentBlockType = "output_text"
	ResponsesOutputMessageContentTypeRefusal   ResponsesMessageContentBlockType = "refusal"
	ResponsesOutputMessageContentTypeReasoning ResponsesMessageContentBlockType = "reasoning_text"

	// gemini sends rendered content in google search results
	ResponsesOutputMessageContentTypeRenderedContent ResponsesMessageContentBlockType = "rendered_content"

	ResponsesOutputMessageContentTypeCompaction ResponsesMessageContentBlockType = "compaction"
)

type ResponsesMessageRoleType

type ResponsesMessageRoleType string
const (
	ResponsesInputMessageRoleAssistant ResponsesMessageRoleType = "assistant"
	ResponsesInputMessageRoleUser      ResponsesMessageRoleType = "user"
	ResponsesInputMessageRoleSystem    ResponsesMessageRoleType = "system"
	ResponsesInputMessageRoleDeveloper ResponsesMessageRoleType = "developer"
)

type ResponsesMessageType

type ResponsesMessageType string
const (
	ResponsesMessageTypeMessage              ResponsesMessageType = "message"
	ResponsesMessageTypeFileSearchCall       ResponsesMessageType = "file_search_call"
	ResponsesMessageTypeComputerCall         ResponsesMessageType = "computer_call"
	ResponsesMessageTypeComputerCallOutput   ResponsesMessageType = "computer_call_output"
	ResponsesMessageTypeWebSearchCall        ResponsesMessageType = "web_search_call"
	ResponsesMessageTypeFunctionCall         ResponsesMessageType = "function_call"
	ResponsesMessageTypeFunctionCallOutput   ResponsesMessageType = "function_call_output"
	ResponsesMessageTypeCodeInterpreterCall  ResponsesMessageType = "code_interpreter_call"
	ResponsesMessageTypeLocalShellCall       ResponsesMessageType = "local_shell_call"
	ResponsesMessageTypeLocalShellCallOutput ResponsesMessageType = "local_shell_call_output"
	ResponsesMessageTypeMCPCall              ResponsesMessageType = "mcp_call"
	ResponsesMessageTypeCustomToolCall       ResponsesMessageType = "custom_tool_call"
	ResponsesMessageTypeCustomToolCallOutput ResponsesMessageType = "custom_tool_call_output"
	ResponsesMessageTypeImageGenerationCall  ResponsesMessageType = "image_generation_call"
	ResponsesMessageTypeMCPListTools         ResponsesMessageType = "mcp_list_tools"
	ResponsesMessageTypeMCPApprovalRequest   ResponsesMessageType = "mcp_approval_request"
	ResponsesMessageTypeMCPApprovalResponses ResponsesMessageType = "mcp_approval_responses"
	ResponsesMessageTypeReasoning            ResponsesMessageType = "reasoning"
	ResponsesMessageTypeItemReference        ResponsesMessageType = "item_reference"
	ResponsesMessageTypeRefusal              ResponsesMessageType = "refusal"
)

type ResponsesOutputMessageContentCompaction

type ResponsesOutputMessageContentCompaction struct {
	Summary string `json:"summary,omitempty"` // The compaction summary text
}

type ResponsesOutputMessageContentRefusal

type ResponsesOutputMessageContentRefusal struct {
	Refusal string `json:"refusal"`
}

type ResponsesOutputMessageContentRenderedContent

type ResponsesOutputMessageContentRenderedContent struct {
	RenderedContent string `json:"rendered_content"` // HTML/styled content from search entry point
}

type ResponsesOutputMessageContentText

type ResponsesOutputMessageContentText struct {
	Annotations []ResponsesOutputMessageContentTextAnnotation `json:"annotations"` // Citations and references
	LogProbs    []ResponsesOutputMessageContentTextLogProb    `json:"logprobs"`    // Token log probabilities
}

type ResponsesOutputMessageContentTextAnnotation

type ResponsesOutputMessageContentTextAnnotation struct {
	Type        string  `json:"type"`                  // "file_citation" | "url_citation" | "container_file_citation" | "file_path"
	Index       *int    `json:"index,omitempty"`       // Common index field (FileCitation, FilePath)
	FileID      *string `json:"file_id,omitempty"`     // Common file ID field (FileCitation, ContainerFileCitation, FilePath)
	Text        *string `json:"text,omitempty"`        // Text of the citation
	StartIndex  *int    `json:"start_index,omitempty"` // Common start index field (URLCitation, ContainerFileCitation)
	EndIndex    *int    `json:"end_index,omitempty"`   // Common end index field (URLCitation, ContainerFileCitation)
	Filename    *string `json:"filename,omitempty"`
	Title       *string `json:"title,omitempty"`
	URL         *string `json:"url,omitempty"`
	ContainerID *string `json:"container_id,omitempty"`

	// Anthropic specific fields
	StartCharIndex  *int    `json:"start_char_index,omitempty"`
	EndCharIndex    *int    `json:"end_char_index,omitempty"`
	StartPageNumber *int    `json:"start_page_number,omitempty"`
	EndPageNumber   *int    `json:"end_page_number,omitempty"`
	StartBlockIndex *int    `json:"start_block_index,omitempty"`
	EndBlockIndex   *int    `json:"end_block_index,omitempty"`
	Source          *string `json:"source,omitempty"`
	EncryptedIndex  *string `json:"encrypted_index,omitempty"`
}

type ResponsesOutputMessageContentTextLogProb

type ResponsesOutputMessageContentTextLogProb struct {
	Bytes       []int     `json:"bytes"`
	LogProb     float64   `json:"logprob"`
	Token       string    `json:"token"`
	TopLogProbs []LogProb `json:"top_logprobs"`
}

ResponsesOutputMessageContentTextLogProb represents log probability information for content.

type ResponsesParameters

type ResponsesParameters struct {
	Background         *bool                         `json:"background,omitempty"`
	Conversation       *string                       `json:"conversation,omitempty"`
	Include            []string                      `json:"include,omitempty"` // Supported values: "web_search_call.action.sources", "code_interpreter_call.outputs", "computer_call_output.output.image_url", "file_search_call.results", "message.input_image.image_url", "message.output_text.logprobs", "reasoning.encrypted_content"
	Instructions       *string                       `json:"instructions,omitempty"`
	MaxOutputTokens    *int                          `json:"max_output_tokens,omitempty"`
	MaxToolCalls       *int                          `json:"max_tool_calls,omitempty"`
	Metadata           *map[string]any               `json:"metadata,omitempty"`
	ParallelToolCalls  *bool                         `json:"parallel_tool_calls,omitempty"`
	PreviousResponseID *string                       `json:"previous_response_id,omitempty"`
	PromptCacheKey     *string                       `json:"prompt_cache_key,omitempty"`  // Prompt cache key
	Reasoning          *ResponsesParametersReasoning `json:"reasoning,omitempty"`         // Configuration options for reasoning models
	SafetyIdentifier   *string                       `json:"safety_identifier,omitempty"` // Safety identifier
	ServiceTier        *string                       `json:"service_tier,omitempty"`
	StreamOptions      *ResponsesStreamOptions       `json:"stream_options,omitempty"`
	Store              *bool                         `json:"store,omitempty"`
	Temperature        *float64                      `json:"temperature,omitempty"`
	Text               *ResponsesTextConfig          `json:"text,omitempty"`
	TopLogProbs        *int                          `json:"top_logprobs,omitempty"`
	TopP               *float64                      `json:"top_p,omitempty"`       // Controls diversity via nucleus sampling
	ToolChoice         *ResponsesToolChoice          `json:"tool_choice,omitempty"` // Whether to call a tool
	Tools              []ResponsesTool               `json:"tools,omitempty"`       // Tools to use
	Truncation         *string                       `json:"truncation,omitempty"`
	User               *string                       `json:"user,omitempty"`
	// Dynamic parameters that can be provider-specific, they are directly
	// added to the request as is.
	ExtraParams map[string]interface{} `json:"-"`
}

type ResponsesParametersReasoning

type ResponsesParametersReasoning struct {
	Effort          *string `json:"effort"`                     // "none" | "minimal" | "low" | "medium" | "high" (any value other than "none" will enable reasoning)
	GenerateSummary *string `json:"generate_summary,omitempty"` // Deprecated: use summary instead
	Summary         *string `json:"summary"`                    // "auto" | "concise" | "detailed"
	MaxTokens       *int    `json:"max_tokens,omitempty"`       // Maximum number of tokens to generate for the reasoning output (required for anthropic)
}

type ResponsesPrompt

type ResponsesPrompt struct {
	ID        string         `json:"id"`
	Variables map[string]any `json:"variables"`
	Version   *string        `json:"version,omitempty"`
}

type ResponsesReasoning

type ResponsesReasoning struct {
	Summary          []ResponsesReasoningSummary `json:"summary"`
	EncryptedContent *string                     `json:"encrypted_content,omitempty"`
}

ResponsesReasoning represents a reasoning output

type ResponsesReasoningContentBlockType

type ResponsesReasoningContentBlockType string

ResponsesReasoningContentBlockType represents the type of reasoning content

const (
	ResponsesReasoningContentBlockTypeSummaryText ResponsesReasoningContentBlockType = "summary_text"
)

ResponsesReasoningContentBlockType values

type ResponsesReasoningSummary

type ResponsesReasoningSummary struct {
	Type ResponsesReasoningContentBlockType `json:"type"`
	Text string                             `json:"text"`
}

ResponsesReasoningSummary represents a reasoning content block

type ResponsesResponseConversation

type ResponsesResponseConversation struct {
	ResponsesResponseConversationStr    *string
	ResponsesResponseConversationStruct *ResponsesResponseConversationStruct
}

func (ResponsesResponseConversation) MarshalJSON

func (rc ResponsesResponseConversation) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ResponsesMessageContent. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ResponsesResponseConversation) UnmarshalJSON

func (rc *ResponsesResponseConversation) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ResponsesMessageContent. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ResponsesResponseConversationStruct

type ResponsesResponseConversationStruct struct {
	ID string `json:"id"` // The unique ID of the conversation
}

type ResponsesResponseError

type ResponsesResponseError struct {
	Code    string `json:"code"`    // The error code for the response
	Message string `json:"message"` // A human-readable description of the error
}

type ResponsesResponseIncompleteDetails

type ResponsesResponseIncompleteDetails struct {
	Reason string `json:"reason"` // The reason why the response is incomplete
}

type ResponsesResponseInputTokens

type ResponsesResponseInputTokens struct {
	TextTokens  int `json:"text_tokens,omitempty"`  // Tokens for text input
	AudioTokens int `json:"audio_tokens,omitempty"` // Tokens for audio input
	ImageTokens int `json:"image_tokens,omitempty"` // Tokens for image input

	// For Providers which follow OpenAI's spec, CachedTokens means the number of input tokens read from the cache+input tokens used to create the cache entry. (because they do not differentiate between cache creation and cache read tokens)
	// For Providers which do not follow OpenAI's spec, CachedTokens means only the number of input tokens read from the cache.
	CachedTokens int `json:"cached_tokens"`
}

type ResponsesResponseInstructions

type ResponsesResponseInstructions struct {
	ResponsesResponseInstructionsStr   *string
	ResponsesResponseInstructionsArray []ResponsesMessage
}

func (ResponsesResponseInstructions) MarshalJSON

func (rc ResponsesResponseInstructions) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ResponsesMessageContent. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ResponsesResponseInstructions) UnmarshalJSON

func (rc *ResponsesResponseInstructions) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ResponsesMessageContent. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ResponsesResponseOutputTokens

type ResponsesResponseOutputTokens struct {
	TextTokens               int  `json:"text_tokens,omitempty"`
	AcceptedPredictionTokens int  `json:"accepted_prediction_tokens,omitempty"`
	AudioTokens              int  `json:"audio_tokens,omitempty"`
	ImageTokens              *int `json:"image_tokens,omitempty"`
	ReasoningTokens          int  `json:"reasoning_tokens"` // Required for few OpenAI models
	RejectedPredictionTokens int  `json:"rejected_prediction_tokens,omitempty"`
	CitationTokens           *int `json:"citation_tokens,omitempty"`
	NumSearchQueries         *int `json:"num_search_queries,omitempty"`

	// This means the number of input tokens used to create the cache entry. (cache creation tokens)
	CachedTokens int `json:"cached_tokens,omitempty"` // Not in OpenAI's schemas, but sent by a few providers (Anthropic, Bedrock are some of them)
}

type ResponsesResponseUsage

type ResponsesResponseUsage struct {
	Type                *string                        `json:"type,omitempty"`        // type field is sent by anthropic
	InputTokens         int                            `json:"input_tokens"`          // Number of input tokens
	InputTokensDetails  *ResponsesResponseInputTokens  `json:"input_tokens_details"`  // Detailed breakdown of input tokens
	OutputTokens        int                            `json:"output_tokens"`         // Number of output tokens
	OutputTokensDetails *ResponsesResponseOutputTokens `json:"output_tokens_details"` // Detailed breakdown of output tokens	TotalTokens int `json:"total_tokens"` // Total number of tokens used
	TotalTokens         int                            `json:"total_tokens"`          // Total number of tokens used
	Cost                *BifrostCost                   `json:"cost,omitempty"`        // Only for the providers which support cost calculation
	Iterations          []ResponsesResponseUsage       `json:"iterations,omitempty"`  // iterations field is sent by anthropic
}

func (*ResponsesResponseUsage) ToBifrostLLMUsage

func (ru *ResponsesResponseUsage) ToBifrostLLMUsage() *BifrostLLMUsage

type ResponsesStreamOptions

type ResponsesStreamOptions struct {
	IncludeObfuscation *bool `json:"include_obfuscation,omitempty"`
}

type ResponsesStreamResponseType

type ResponsesStreamResponseType string
const (
	// Ping events are just keepalive (sent by very few providers, Anthropic is one of them)
	ResponsesStreamResponseTypePing ResponsesStreamResponseType = "response.ping"

	ResponsesStreamResponseTypeCreated    ResponsesStreamResponseType = "response.created"
	ResponsesStreamResponseTypeInProgress ResponsesStreamResponseType = "response.in_progress"
	ResponsesStreamResponseTypeCompleted  ResponsesStreamResponseType = "response.completed"
	ResponsesStreamResponseTypeFailed     ResponsesStreamResponseType = "response.failed"
	ResponsesStreamResponseTypeIncomplete ResponsesStreamResponseType = "response.incomplete"

	ResponsesStreamResponseTypeOutputItemAdded ResponsesStreamResponseType = "response.output_item.added"
	ResponsesStreamResponseTypeOutputItemDone  ResponsesStreamResponseType = "response.output_item.done"

	ResponsesStreamResponseTypeContentPartAdded ResponsesStreamResponseType = "response.content_part.added"
	ResponsesStreamResponseTypeContentPartDone  ResponsesStreamResponseType = "response.content_part.done"

	ResponsesStreamResponseTypeOutputTextDelta ResponsesStreamResponseType = "response.output_text.delta"
	ResponsesStreamResponseTypeOutputTextDone  ResponsesStreamResponseType = "response.output_text.done"

	ResponsesStreamResponseTypeRefusalDelta ResponsesStreamResponseType = "response.refusal.delta"
	ResponsesStreamResponseTypeRefusalDone  ResponsesStreamResponseType = "response.refusal.done"

	ResponsesStreamResponseTypeFunctionCallArgumentsDelta     ResponsesStreamResponseType = "response.function_call_arguments.delta"
	ResponsesStreamResponseTypeFunctionCallArgumentsDone      ResponsesStreamResponseType = "response.function_call_arguments.done"
	ResponsesStreamResponseTypeFileSearchCallInProgress       ResponsesStreamResponseType = "response.file_search_call.in_progress"
	ResponsesStreamResponseTypeFileSearchCallSearching        ResponsesStreamResponseType = "response.file_search_call.searching"
	ResponsesStreamResponseTypeFileSearchCallResultsAdded     ResponsesStreamResponseType = "response.file_search_call.results.added"
	ResponsesStreamResponseTypeFileSearchCallResultsCompleted ResponsesStreamResponseType = "response.file_search_call.results.completed"
	ResponsesStreamResponseTypeWebSearchCallInProgress        ResponsesStreamResponseType = "response.web_search_call.in_progress"
	ResponsesStreamResponseTypeWebSearchCallSearching         ResponsesStreamResponseType = "response.web_search_call.searching"
	ResponsesStreamResponseTypeWebSearchCallCompleted         ResponsesStreamResponseType = "response.web_search_call.completed"
	ResponsesStreamResponseTypeWebSearchCallResultsAdded      ResponsesStreamResponseType = "response.web_search_call.results.added"
	ResponsesStreamResponseTypeWebSearchCallResultsCompleted  ResponsesStreamResponseType = "response.web_search_call.results.completed"

	ResponsesStreamResponseTypeReasoningSummaryPartAdded ResponsesStreamResponseType = "response.reasoning_summary_part.added"
	ResponsesStreamResponseTypeReasoningSummaryPartDone  ResponsesStreamResponseType = "response.reasoning_summary_part.done"
	ResponsesStreamResponseTypeReasoningSummaryTextDelta ResponsesStreamResponseType = "response.reasoning_summary_text.delta"
	ResponsesStreamResponseTypeReasoningSummaryTextDone  ResponsesStreamResponseType = "response.reasoning_summary_text.done"

	ResponsesStreamResponseTypeImageGenerationCallCompleted    ResponsesStreamResponseType = "response.image_generation_call.completed"
	ResponsesStreamResponseTypeImageGenerationCallGenerating   ResponsesStreamResponseType = "response.image_generation_call.generating"
	ResponsesStreamResponseTypeImageGenerationCallInProgress   ResponsesStreamResponseType = "response.image_generation_call.in_progress"
	ResponsesStreamResponseTypeImageGenerationCallPartialImage ResponsesStreamResponseType = "response.image_generation_call.partial_image"

	ResponsesStreamResponseTypeMCPCallArgumentsDelta  ResponsesStreamResponseType = "response.mcp_call_arguments.delta"
	ResponsesStreamResponseTypeMCPCallArgumentsDone   ResponsesStreamResponseType = "response.mcp_call_arguments.done"
	ResponsesStreamResponseTypeMCPCallCompleted       ResponsesStreamResponseType = "response.mcp_call.completed"
	ResponsesStreamResponseTypeMCPCallFailed          ResponsesStreamResponseType = "response.mcp_call.failed"
	ResponsesStreamResponseTypeMCPCallInProgress      ResponsesStreamResponseType = "response.mcp_call.in_progress"
	ResponsesStreamResponseTypeMCPListToolsCompleted  ResponsesStreamResponseType = "response.mcp_list_tools.completed"
	ResponsesStreamResponseTypeMCPListToolsFailed     ResponsesStreamResponseType = "response.mcp_list_tools.failed"
	ResponsesStreamResponseTypeMCPListToolsInProgress ResponsesStreamResponseType = "response.mcp_list_tools.in_progress"

	ResponsesStreamResponseTypeCodeInterpreterCallInProgress   ResponsesStreamResponseType = "response.code_interpreter_call.in_progress"
	ResponsesStreamResponseTypeCodeInterpreterCallInterpreting ResponsesStreamResponseType = "response.code_interpreter_call.interpreting"
	ResponsesStreamResponseTypeCodeInterpreterCallCompleted    ResponsesStreamResponseType = "response.code_interpreter_call.completed"
	ResponsesStreamResponseTypeCodeInterpreterCallCodeDelta    ResponsesStreamResponseType = "response.code_interpreter_call_code.delta"
	ResponsesStreamResponseTypeCodeInterpreterCallCodeDone     ResponsesStreamResponseType = "response.code_interpreter_call_code.done"

	ResponsesStreamResponseTypeOutputTextAnnotationAdded ResponsesStreamResponseType = "response.output_text.annotation.added"
	ResponsesStreamResponseTypeOutputTextAnnotationDone  ResponsesStreamResponseType = "response.output_text.annotation.done"

	ResponsesStreamResponseTypeQueued ResponsesStreamResponseType = "response.queued"

	ResponsesStreamResponseTypeCustomToolCallInputDelta ResponsesStreamResponseType = "response.custom_tool_call_input.delta"
	ResponsesStreamResponseTypeCustomToolCallInputDone  ResponsesStreamResponseType = "response.custom_tool_call_input.done"

	ResponsesStreamResponseTypeError ResponsesStreamResponseType = "error"
)

type ResponsesTextConfig

type ResponsesTextConfig struct {
	Format    *ResponsesTextConfigFormat `json:"format,omitempty"`    // An object specifying the format that the model must output
	Verbosity *string                    `json:"verbosity,omitempty"` // "low" | "medium" | "high" or null
}

type ResponsesTextConfigFormat

type ResponsesTextConfigFormat struct {
	Type       string                               `json:"type"`             // "text" | "json_schema" | "json_object"
	Name       *string                              `json:"name,omitempty"`   // Name of the format
	JSONSchema *ResponsesTextConfigFormatJSONSchema `json:"schema,omitempty"` // when type == "json_schema"
	Strict     *bool                                `json:"strict,omitempty"`
}

type ResponsesTextConfigFormatJSONSchema

type ResponsesTextConfigFormatJSONSchema struct {
	Name                 *string                     `json:"name,omitempty"`
	Schema               *any                        `json:"schema,omitempty"`
	Description          *string                     `json:"description,omitempty"`
	Strict               *bool                       `json:"strict,omitempty"`
	AdditionalProperties *AdditionalPropertiesStruct `json:"additionalProperties,omitempty"`
	Properties           *map[string]any             `json:"properties,omitempty"`
	Required             []string                    `json:"required,omitempty"`
	Type                 *string                     `json:"type,omitempty"`

	// JSON Schema definition fields
	Defs        *map[string]any `json:"$defs,omitempty"`       // JSON Schema draft 2019-09+ definitions
	Definitions *map[string]any `json:"definitions,omitempty"` // Legacy JSON Schema draft-07 definitions
	Ref         *string         `json:"$ref,omitempty"`        // Reference to definition

	// Array schema fields
	Items    *map[string]any `json:"items,omitempty"`    // Array element schema
	MinItems *int64          `json:"minItems,omitempty"` // Minimum array length
	MaxItems *int64          `json:"maxItems,omitempty"` // Maximum array length

	// Composition fields (union types)
	AnyOf []map[string]any `json:"anyOf,omitempty"` // Union types (any of these schemas)
	OneOf []map[string]any `json:"oneOf,omitempty"` // Exclusive union types (exactly one of these)
	AllOf []map[string]any `json:"allOf,omitempty"` // Schema intersection (all of these)

	// String validation fields
	Format    *string `json:"format,omitempty"`    // String format (email, date, uri, etc.)
	Pattern   *string `json:"pattern,omitempty"`   // Regex pattern for strings
	MinLength *int64  `json:"minLength,omitempty"` // Minimum string length
	MaxLength *int64  `json:"maxLength,omitempty"` // Maximum string length

	// Number validation fields
	Minimum *float64 `json:"minimum,omitempty"` // Minimum number value
	Maximum *float64 `json:"maximum,omitempty"` // Maximum number value

	// Misc fields
	Title            *string     `json:"title,omitempty"`            // Schema title
	Default          interface{} `json:"default,omitempty"`          // Default value
	Nullable         *bool       `json:"nullable,omitempty"`         // Nullable indicator (OpenAPI 3.0 style)
	Enum             []string    `json:"enum,omitempty"`             // Enum values
	PropertyOrdering []string    `json:"propertyOrdering,omitempty"` // Ordering of properties, specific to Gemini
}

ResponsesTextConfigFormatJSONSchema represents a JSON schema specification It supports JSON Schema fields used by various providers for structured outputs.

type ResponsesTool

type ResponsesTool struct {
	Type        ResponsesToolType `json:"type"`                  // "function" | "file_search" | "computer_use_preview" | "web_search" | "web_search_2025_08_26" | "mcp" | "code_interpreter" | "image_generation" | "local_shell" | "custom" | "web_search_preview" | "web_search_preview_2025_03_11"
	Name        *string           `json:"name,omitempty"`        // Common name field (Function, Custom tools)
	Description *string           `json:"description,omitempty"` // Common description field (Function, Custom tools)

	// Not in OpenAI's schemas, but sent by a few providers (Anthropic, Bedrock are some of them)
	CacheControl *CacheControl `json:"cache_control,omitempty"`

	*ResponsesToolFunction
	*ResponsesToolFileSearch
	*ResponsesToolComputerUsePreview
	*ResponsesToolWebSearch
	*ResponsesToolMCP
	*ResponsesToolCodeInterpreter
	*ResponsesToolImageGeneration
	*ResponsesToolLocalShell
	*ResponsesToolCustom
	*ResponsesToolWebSearchPreview
}

ResponsesTool represents a tool

func (ResponsesTool) MarshalJSON

func (t ResponsesTool) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ResponsesTool It merges common fields with the appropriate embedded struct based on type

func (*ResponsesTool) ToChatTool

func (rt *ResponsesTool) ToChatTool() *ChatTool

ToChatTool converts a ResponsesTool to ChatTool format

func (*ResponsesTool) UnmarshalJSON

func (t *ResponsesTool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ResponsesTool It unmarshals common fields first, then the appropriate embedded struct based on type

type ResponsesToolChoice

type ResponsesToolChoice struct {
	ResponsesToolChoiceStr    *string
	ResponsesToolChoiceStruct *ResponsesToolChoiceStruct
}

ResponsesToolChoice represents a tool choice

func (ResponsesToolChoice) MarshalJSON

func (tc ResponsesToolChoice) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for ChatMessageContent. It marshals either ContentStr or ContentBlocks directly without wrapping.

func (*ResponsesToolChoice) ToChatToolChoice

func (tc *ResponsesToolChoice) ToChatToolChoice() *ChatToolChoice

ToChatToolChoice converts a ResponsesToolChoice to ChatToolChoice format

func (*ResponsesToolChoice) UnmarshalJSON

func (tc *ResponsesToolChoice) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ChatMessageContent. It determines whether "content" is a string or array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type ResponsesToolChoiceAllowedToolDef

type ResponsesToolChoiceAllowedToolDef struct {
	Type        string  `json:"type"`                   // "function" | "mcp" | "image_generation"
	Name        *string `json:"name,omitempty"`         // for function tools
	ServerLabel *string `json:"server_label,omitempty"` // for MCP tools
}

ResponsesToolChoiceAllowedToolDef represents a tool choice allowed tool definition

type ResponsesToolChoiceStruct

type ResponsesToolChoiceStruct struct {
	Type        ResponsesToolChoiceType             `json:"type"`                   // Type of tool choice
	Mode        *string                             `json:"mode,omitempty"`         //"none" | "auto" | "required"
	Name        *string                             `json:"name,omitempty"`         // Common name field for function/MCP/custom tools
	ServerLabel *string                             `json:"server_label,omitempty"` // Common server label field for MCP tools
	Tools       []ResponsesToolChoiceAllowedToolDef `json:"tools,omitempty"`
}

ResponsesToolChoiceStruct represents a tool choice struct

type ResponsesToolChoiceType

type ResponsesToolChoiceType string

ResponsesToolChoiceType represents the type of tool choice

const (
	// ResponsesToolChoiceTypeNone means no tool should be called
	ResponsesToolChoiceTypeNone ResponsesToolChoiceType = "none"
	// ResponsesToolChoiceTypeAuto means an automatic tool should be called
	ResponsesToolChoiceTypeAuto ResponsesToolChoiceType = "auto"
	// ResponsesToolChoiceTypeAny means any tool can be called
	ResponsesToolChoiceTypeAny ResponsesToolChoiceType = "any"
	// ResponsesToolChoiceTypeRequired means a specific tool must be called
	ResponsesToolChoiceTypeRequired ResponsesToolChoiceType = "required"
	// ResponsesToolChoiceTypeFunction means a specific tool must be called
	ResponsesToolChoiceTypeFunction ResponsesToolChoiceType = "function"
	// ResponsesToolChoiceTypeAllowedTools means a specific tool must be called
	ResponsesToolChoiceTypeAllowedTools ResponsesToolChoiceType = "allowed_tools"
	// ResponsesToolChoiceTypeFileSearch means a file search tool must be called
	ResponsesToolChoiceTypeFileSearch ResponsesToolChoiceType = "file_search"
	// ResponsesToolChoiceTypeWebSearchPreview means a web search preview tool must be called
	ResponsesToolChoiceTypeWebSearchPreview ResponsesToolChoiceType = "web_search_preview"
	// ResponsesToolChoiceTypeComputerUsePreview means a computer use preview tool must be called
	ResponsesToolChoiceTypeComputerUsePreview ResponsesToolChoiceType = "computer_use_preview"
	// ResponsesToolChoiceTypeCodeInterpreter means a code interpreter tool must be called
	ResponsesToolChoiceTypeCodeInterpreter ResponsesToolChoiceType = "code_interpreter"
	// ResponsesToolChoiceTypeImageGeneration means an image generation tool must be called
	ResponsesToolChoiceTypeImageGeneration ResponsesToolChoiceType = "image_generation"
	// ResponsesToolChoiceTypeMCP means an MCP tool must be called
	ResponsesToolChoiceTypeMCP ResponsesToolChoiceType = "mcp"
	// ResponsesToolChoiceTypeCustom means a custom tool must be called
	ResponsesToolChoiceTypeCustom ResponsesToolChoiceType = "custom"
)

ResponsesToolChoiceType values

type ResponsesToolCodeInterpreter

type ResponsesToolCodeInterpreter struct {
	Container interface{} `json:"container"` // Container ID or object with file IDs
}

ResponsesToolCodeInterpreter represents a tool code interpreter

type ResponsesToolComputerUsePreview

type ResponsesToolComputerUsePreview struct {
	DisplayHeight int    `json:"display_height"` // The height of the computer display
	DisplayWidth  int    `json:"display_width"`  // The width of the computer display
	Environment   string `json:"environment"`    // The type of computer environment to control

	EnableZoom *bool `json:"enable_zoom,omitempty"` // for computer tool in anthropic only
}

ResponsesToolComputerUsePreview represents a tool computer use preview

type ResponsesToolCustom

type ResponsesToolCustom struct {
	Format *ResponsesToolCustomFormat `json:"format,omitempty"` // The input format
}

ResponsesToolCustom represents a custom tool

type ResponsesToolCustomFormat

type ResponsesToolCustomFormat struct {
	Type string `json:"type"` // always "text"

	// For Grammar
	Definition *string `json:"definition,omitempty"` // The grammar definition
	Syntax     *string `json:"syntax,omitempty"`     // "lark" | "regex"
}

ResponsesToolCustomFormat represents the input format for the custom tool

type ResponsesToolFileSearch

type ResponsesToolFileSearch struct {
	VectorStoreIDs []string                               `json:"vector_store_ids"`          // The IDs of the vector stores to search
	Filters        *ResponsesToolFileSearchFilter         `json:"filters,omitempty"`         // A filter to apply
	MaxNumResults  *int                                   `json:"max_num_results,omitempty"` // Maximum results (1-50)
	RankingOptions *ResponsesToolFileSearchRankingOptions `json:"ranking_options,omitempty"` // Ranking options for search
}

ResponsesToolFileSearch represents a tool file search

type ResponsesToolFileSearchComparisonFilter

type ResponsesToolFileSearchComparisonFilter struct {
	Key   string      `json:"key"`   // The key to compare against the value
	Type  string      `json:"type"`  //
	Value interface{} `json:"value"` // The value to compare (string, number, or boolean)
}

ResponsesToolFileSearchComparisonFilter represents a file search comparison filter

type ResponsesToolFileSearchCompoundFilter

type ResponsesToolFileSearchCompoundFilter struct {
	Filters []ResponsesToolFileSearchFilter `json:"filters"` // Array of filters to combine
}

ResponsesToolFileSearchCompoundFilter represents a file search compound filter

type ResponsesToolFileSearchFilter

type ResponsesToolFileSearchFilter struct {
	Type string `json:"type"` // "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "and" | "or"

	// Filter types - only one should be set
	*ResponsesToolFileSearchComparisonFilter
	*ResponsesToolFileSearchCompoundFilter
}

ResponsesToolFileSearchFilter represents a file search filter

func (*ResponsesToolFileSearchFilter) MarshalJSON

func (f *ResponsesToolFileSearchFilter) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ResponsesToolFileSearchFilter

func (*ResponsesToolFileSearchFilter) UnmarshalJSON

func (f *ResponsesToolFileSearchFilter) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ResponsesToolFileSearchFilter

type ResponsesToolFileSearchRankingOptions

type ResponsesToolFileSearchRankingOptions struct {
	Ranker         *string  `json:"ranker,omitempty"`          // The ranker to use
	ScoreThreshold *float64 `json:"score_threshold,omitempty"` // Score threshold (0-1)
}

ResponsesToolFileSearchRankingOptions represents a file search ranking options

type ResponsesToolFunction

type ResponsesToolFunction struct {
	Parameters *ToolFunctionParameters `json:"parameters,omitempty"` // A JSON schema object describing the parameters
	Strict     *bool                   `json:"strict"`               // Whether to enforce strict parameter validation
}

ResponsesToolFunction represents a tool function

type ResponsesToolImageGeneration

type ResponsesToolImageGeneration struct {
	Background        *string                                     `json:"background,omitempty"`         // "transparent" | "opaque" | "auto"
	InputFidelity     *string                                     `json:"input_fidelity,omitempty"`     // "high" | "low"
	InputImageMask    *ResponsesToolImageGenerationInputImageMask `json:"input_image_mask,omitempty"`   // Optional mask for inpainting
	Model             *string                                     `json:"model,omitempty"`              // Image generation model
	Moderation        *string                                     `json:"moderation,omitempty"`         // Moderation level
	OutputCompression *int                                        `json:"output_compression,omitempty"` // Compression level (0-100)
	OutputFormat      *string                                     `json:"output_format,omitempty"`      // "png" | "webp" | "jpeg"
	PartialImages     *int                                        `json:"partial_images,omitempty"`     // Number of partial images (0-3)
	Quality           *string                                     `json:"quality,omitempty"`            // "low" | "medium" | "high" | "auto"
	Size              *string                                     `json:"size,omitempty"`               // Image size
}

ResponsesToolImageGeneration represents a tool image generation

type ResponsesToolImageGenerationInputImageMask

type ResponsesToolImageGenerationInputImageMask struct {
	FileID   *string `json:"file_id,omitempty"`   // File ID for the mask image
	ImageURL *string `json:"image_url,omitempty"` // Base64-encoded mask image
}

ResponsesToolImageGenerationInputImageMask represents a image generation input image mask

type ResponsesToolLocalShell

type ResponsesToolLocalShell struct {
}

ResponsesToolLocalShell represents a tool local shell

type ResponsesToolMCP

type ResponsesToolMCP struct {
	ServerLabel       string                                       `json:"server_label"`                 // A label for this MCP server
	AllowedTools      *ResponsesToolMCPAllowedTools                `json:"allowed_tools,omitempty"`      // List of allowed tool names or filter
	Authorization     *string                                      `json:"authorization,omitempty"`      // OAuth access token
	ConnectorID       *string                                      `json:"connector_id,omitempty"`       // Service connector ID
	Headers           *map[string]string                           `json:"headers,omitempty"`            // Optional HTTP headers
	RequireApproval   *ResponsesToolMCPAllowedToolsApprovalSetting `json:"require_approval,omitempty"`   // Tool approval settings
	ServerDescription *string                                      `json:"server_description,omitempty"` // Optional server description
	ServerURL         *string                                      `json:"server_url,omitempty"`         // The URL for the MCP server
}

ResponsesToolMCP - Give the model access to additional tools via remote MCP servers

type ResponsesToolMCPAllowedTools

type ResponsesToolMCPAllowedTools struct {
	// Either a simple array of tool names or a filter object
	ToolNames []string                            `json:",omitempty"`
	Filter    *ResponsesToolMCPAllowedToolsFilter `json:",omitempty"`
}

ResponsesToolMCPAllowedTools - List of allowed tool names or a filter object

type ResponsesToolMCPAllowedToolsApprovalFilter

type ResponsesToolMCPAllowedToolsApprovalFilter struct {
	ReadOnly  *bool    `json:"read_only,omitempty"`  // Whether tool is read-only
	ToolNames []string `json:"tool_names,omitempty"` // List of tool names
}

ResponsesToolMCPAllowedToolsApprovalFilter - Filter for approval settings

type ResponsesToolMCPAllowedToolsApprovalSetting

type ResponsesToolMCPAllowedToolsApprovalSetting struct {
	// Either a string setting or filter objects
	Setting *string                                     `json:",omitempty"` // "always" | "never"
	Always  *ResponsesToolMCPAllowedToolsApprovalFilter `json:"always,omitempty"`
	Never   *ResponsesToolMCPAllowedToolsApprovalFilter `json:"never,omitempty"`
}

ResponsesToolMCPAllowedToolsApprovalSetting - Specify which tools require approval

func (ResponsesToolMCPAllowedToolsApprovalSetting) MarshalJSON

MarshalJSON implements custom JSON marshalling for ResponsesToolMCPAllowedToolsApprovalSetting

func (*ResponsesToolMCPAllowedToolsApprovalSetting) UnmarshalJSON

func (as *ResponsesToolMCPAllowedToolsApprovalSetting) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ResponsesToolMCPAllowedToolsApprovalSetting

type ResponsesToolMCPAllowedToolsFilter

type ResponsesToolMCPAllowedToolsFilter struct {
	ReadOnly  *bool    `json:"read_only,omitempty"`  // Whether tool is read-only
	ToolNames []string `json:"tool_names,omitempty"` // List of allowed tool names
}

ResponsesToolMCPAllowedToolsFilter - A filter object to specify which tools are allowed

type ResponsesToolMessage

type ResponsesToolMessage struct {
	CallID    *string                           `json:"call_id,omitempty"` // Common call ID for tool calls and outputs
	Name      *string                           `json:"name,omitempty"`    // Common name field for tool calls
	Arguments *string                           `json:"arguments,omitempty"`
	Output    *ResponsesToolMessageOutputStruct `json:"output,omitempty"`
	Action    *ResponsesToolMessageActionStruct `json:"action,omitempty"`
	Error     *string                           `json:"error,omitempty"`

	// Tool calls and outputs
	*ResponsesFileSearchToolCall
	*ResponsesComputerToolCall
	*ResponsesComputerToolCallOutput
	*ResponsesCodeInterpreterToolCall
	*ResponsesMCPToolCall
	*ResponsesCustomToolCall
	*ResponsesImageGenerationCall

	// MCP-specific
	*ResponsesMCPListTools
	*ResponsesMCPApprovalResponse
}

func (*ResponsesToolMessage) ToChatAssistantMessageToolCall

func (rtm *ResponsesToolMessage) ToChatAssistantMessageToolCall() *ChatAssistantMessageToolCall

ToChatAssistantMessageToolCall converts a ResponsesToolMessage to ChatAssistantMessageToolCall format. This is useful for executing Responses API tool calls using the Chat API tool executor.

Returns:

  • *ChatAssistantMessageToolCall: The converted tool call in Chat API format

Example:

responsesToolMsg := &ResponsesToolMessage{
    CallID:    Ptr("call-123"),
    Name:      Ptr("calculate"),
    Arguments: Ptr("{\"x\": 10, \"y\": 20}"),
}
chatToolCall := responsesToolMsg.ToChatAssistantMessageToolCall()

type ResponsesToolMessageActionStruct

type ResponsesToolMessageActionStruct struct {
	ResponsesComputerToolCallAction   *ResponsesComputerToolCallAction
	ResponsesWebSearchToolCallAction  *ResponsesWebSearchToolCallAction
	ResponsesLocalShellToolCallAction *ResponsesLocalShellToolCallAction
	ResponsesMCPApprovalRequestAction *ResponsesMCPApprovalRequestAction
}

func (ResponsesToolMessageActionStruct) MarshalJSON

func (action ResponsesToolMessageActionStruct) MarshalJSON() ([]byte, error)

func (*ResponsesToolMessageActionStruct) UnmarshalJSON

func (action *ResponsesToolMessageActionStruct) UnmarshalJSON(data []byte) error

type ResponsesToolMessageOutputStruct

type ResponsesToolMessageOutputStruct struct {
	ResponsesToolCallOutputStr            *string // Common output string for tool calls and outputs (used by function, custom and local shell tool calls)
	ResponsesFunctionToolCallOutputBlocks []ResponsesMessageContentBlock
	ResponsesComputerToolCallOutput       *ResponsesComputerToolCallOutputData
}

func (ResponsesToolMessageOutputStruct) MarshalJSON

func (output ResponsesToolMessageOutputStruct) MarshalJSON() ([]byte, error)

func (*ResponsesToolMessageOutputStruct) UnmarshalJSON

func (output *ResponsesToolMessageOutputStruct) UnmarshalJSON(data []byte) error

type ResponsesToolType

type ResponsesToolType string
const (
	ResponsesToolTypeFunction           ResponsesToolType = "function"
	ResponsesToolTypeFileSearch         ResponsesToolType = "file_search"
	ResponsesToolTypeComputerUsePreview ResponsesToolType = "computer_use_preview"
	ResponsesToolTypeWebSearch          ResponsesToolType = "web_search"
	ResponsesToolTypeMCP                ResponsesToolType = "mcp"
	ResponsesToolTypeCodeInterpreter    ResponsesToolType = "code_interpreter"
	ResponsesToolTypeImageGeneration    ResponsesToolType = "image_generation"
	ResponsesToolTypeLocalShell         ResponsesToolType = "local_shell"
	ResponsesToolTypeCustom             ResponsesToolType = "custom"
	ResponsesToolTypeWebSearchPreview   ResponsesToolType = "web_search_preview"
)

type ResponsesToolWebSearch

type ResponsesToolWebSearch struct {
	Filters           *ResponsesToolWebSearchFilters      `json:"filters,omitempty"`             // Filters for the search
	SearchContextSize *string                             `json:"search_context_size,omitempty"` // "low" | "medium" | "high"
	UserLocation      *ResponsesToolWebSearchUserLocation `json:"user_location,omitempty"`       // The approximate location of the user

	// Anthropic only
	MaxUses *int `json:"max_uses,omitempty"` // Maximum number of uses for the search
}

ResponsesToolWebSearch represents a tool web search

type ResponsesToolWebSearchFilters

type ResponsesToolWebSearchFilters struct {
	AllowedDomains []string `json:"allowed_domains,omitempty"` // Allowed domains for the search
	BlockedDomains []string `json:"blocked_domains,omitempty"` // Blocked domains for the search, only used in anthropic

	// Gemini only
	// Filter search results to a specific time range.
	// If users set a start time, they must set an end time (and vice versa).
	TimeRangeFilter *Interval `json:"time_range_filter,omitempty"`
}

ResponsesToolWebSearchFilters represents filters for web search

type ResponsesToolWebSearchPreview

type ResponsesToolWebSearchPreview struct {
	SearchContextSize *string                             `json:"search_context_size,omitempty"` // "low" | "medium" | "high"
	UserLocation      *ResponsesToolWebSearchUserLocation `json:"user_location,omitempty"`       // The user's location
}

ResponsesToolWebSearchPreview represents a web search preview

type ResponsesToolWebSearchUserLocation

type ResponsesToolWebSearchUserLocation struct {
	City     *string `json:"city,omitempty"`     // Free text input for the city
	Country  *string `json:"country,omitempty"`  // Two-letter ISO country code
	Region   *string `json:"region,omitempty"`   // Free text input for the region
	Timezone *string `json:"timezone,omitempty"` // IANA timezone
	Type     *string `json:"type,omitempty"`     // always "approximate"
}

ResponsesToolWebSearchUserLocation - The approximate location of the user

type ResponsesWebSearchToolCallAction

type ResponsesWebSearchToolCallAction struct {
	Type    string                                         `json:"type"`          // "search" | "open_page" | "find"
	URL     *string                                        `json:"url,omitempty"` // Common URL field (OpenPage, Find)
	Query   *string                                        `json:"query,omitempty"`
	Queries []string                                       `json:"queries,omitempty"`
	Sources []ResponsesWebSearchToolCallActionSearchSource `json:"sources,omitempty"`
	Pattern *string                                        `json:"pattern,omitempty"`
}

ResponsesWebSearchToolCallAction represents the different types of web search actions

type ResponsesWebSearchToolCallActionSearchSource

type ResponsesWebSearchToolCallActionSearchSource struct {
	Type string `json:"type"` // always "url"
	URL  string `json:"url"`

	// Anthropic specific fields
	Title            *string `json:"title,omitempty"`
	EncryptedContent *string `json:"encrypted_content,omitempty"`
	PageAge          *string `json:"page_age,omitempty"`
}

ResponsesWebSearchToolCallActionSearchSource represents a web search action search source

type RoutingEngineLogEntry

type RoutingEngineLogEntry struct {
	Engine    string // e.g., "governance", "routing-rule", "openrouter"
	Message   string // Human-readable decision/action message
	Timestamp int64  // Unix milliseconds
}

RoutingEngineLogEntry represents a log entry from a routing engine format: [timestamp] [engine] - message

type S3BucketConfig

type S3BucketConfig struct {
	BucketName string `json:"bucket_name"`          // S3 bucket name
	Prefix     string `json:"prefix,omitempty"`     // S3 key prefix for batch files
	IsDefault  bool   `json:"is_default,omitempty"` // Whether this is the default bucket for batch operations
}

S3BucketConfig represents a single S3 bucket configuration for batch operations.

type S3StorageConfig

type S3StorageConfig struct {
	Bucket string `json:"bucket,omitempty"`
	Region string `json:"region,omitempty"`
	Prefix string `json:"prefix,omitempty"`
}

S3StorageConfig represents AWS S3 storage configuration.

type SearchResult

type SearchResult struct {
	Title       string  `json:"title"`
	URL         string  `json:"url"`
	Date        *string `json:"date,omitempty"`
	LastUpdated *string `json:"last_updated,omitempty"`
	Snippet     *string `json:"snippet,omitempty"`
	Source      *string `json:"source,omitempty"`
}

type SerialCursor

type SerialCursor struct {
	Version  int    `json:"v"` // Version for compatibility
	KeyIndex int    `json:"i"` // Current key index in sorted keys array
	Cursor   string `json:"c"` // Native cursor for current key (empty = start fresh)
}

SerialCursor tracks pagination state for serial key exhaustion. When paginating across multiple keys, we exhaust all pages from one key before moving to the next, ensuring only one API call per pagination request.

func DecodeSerialCursor

func DecodeSerialCursor(encoded string) (*SerialCursor, error)

DecodeSerialCursor decodes a base64 string back to a SerialCursor. Returns (nil, nil) if the encoded string is empty; returns an error for invalid data.

func NewSerialCursor

func NewSerialCursor(keyIndex int, cursor string) *SerialCursor

NewSerialCursor creates a new SerialCursor with version 1.

type Span

type Span struct {
	SpanID     string         // Unique identifier for this span
	ParentID   string         // Parent span ID (empty for root span)
	TraceID    string         // The trace this span belongs to
	Name       string         // Name of the operation
	Kind       SpanKind       // Type of span (LLM call, plugin, etc.)
	StartTime  time.Time      // When the span started
	EndTime    time.Time      // When the span completed
	Status     SpanStatus     // Status of the operation
	StatusMsg  string         // Optional status message (for errors)
	Attributes map[string]any // Additional attributes for the span
	Events     []SpanEvent    // Events that occurred during the span
	// contains filtered or unexported fields
}

Span represents a single operation within a trace

func (*Span) AddEvent

func (s *Span) AddEvent(event SpanEvent)

AddEvent adds an event to the span in a thread-safe manner

func (*Span) End

func (s *Span) End(status SpanStatus, statusMsg string)

End marks the span as complete with the given status

func (*Span) Reset

func (s *Span) Reset()

Reset clears the span for reuse from pool

func (*Span) SetAttribute

func (s *Span) SetAttribute(key string, value any)

SetAttribute sets an attribute on the span in a thread-safe manner

type SpanEvent

type SpanEvent struct {
	Name       string         // Name of the event
	Timestamp  time.Time      // When the event occurred
	Attributes map[string]any // Additional attributes for the event
}

SpanEvent represents a time-stamped event within a span

type SpanHandle

type SpanHandle interface{}

SpanHandle is an opaque handle to a span, implementation-specific. Different Tracer implementations can use their own concrete types.

type SpanKind

type SpanKind string

SpanKind represents the type of operation a span represents These are LLM-specific kinds designed for AI gateway observability

const (
	// SpanKindUnspecified is the default span kind
	SpanKindUnspecified SpanKind = ""
	// SpanKindLLMCall represents a call to an LLM provider
	SpanKindLLMCall SpanKind = "llm.call"
	// SpanKindPlugin represents plugin execution (PreLLMHook/PostLLMHook)
	SpanKindPlugin SpanKind = "plugin"
	// SpanKindMCPTool represents an MCP tool invocation
	SpanKindMCPTool SpanKind = "mcp.tool"
	// SpanKindRetry represents a retry attempt
	SpanKindRetry SpanKind = "retry"
	// SpanKindFallback represents a fallback to another provider
	SpanKindFallback SpanKind = "fallback"
	// SpanKindHTTPRequest represents the root HTTP request span
	SpanKindHTTPRequest SpanKind = "http.request"
	// SpanKindEmbedding represents an embedding request
	SpanKindEmbedding SpanKind = "embedding"
	// SpanKindSpeech represents a text-to-speech request
	SpanKindSpeech SpanKind = "speech"
	// SpanKindTranscription represents a speech-to-text request
	SpanKindTranscription SpanKind = "transcription"
	// SpanKindInternal represents internal operations (key selection, etc.)
	SpanKindInternal SpanKind = "internal"
)

type SpanStatus

type SpanStatus string

SpanStatus represents the status of a span's operation

const (
	// SpanStatusUnset indicates status has not been set
	SpanStatusUnset SpanStatus = "unset"
	// SpanStatusOk indicates the operation completed successfully
	SpanStatusOk SpanStatus = "ok"
	// SpanStatusError indicates the operation failed
	SpanStatusError SpanStatus = "error"
)

type SpeechAlignment

type SpeechAlignment struct {
	CharStartTimesMs []float64 `json:"char_start_times_ms"` // Start time in milliseconds for each character
	CharEndTimesMs   []float64 `json:"char_end_times_ms"`   // End time in milliseconds for each character
	Characters       []string  `json:"characters"`          // Characters corresponding to timing info
}

SpeechAlignment represents character-level timing information for audio-text synchronization

type SpeechInput

type SpeechInput struct {
	Input string `json:"input"`
}

SpeechInput represents the input for a speech request.

type SpeechParameters

type SpeechParameters struct {
	VoiceConfig    *SpeechVoiceInput `json:"voice"`
	Instructions   string            `json:"instructions,omitempty"`
	ResponseFormat string            `json:"response_format,omitempty"` // Default is "mp3"
	Speed          *float64          `json:"speed,omitempty"`

	LanguageCode                    *string                                `json:"language_code,omitempty"`
	PronunciationDictionaryLocators []SpeechPronunciationDictionaryLocator `json:"pronunciation_dictionary_locators"`
	EnableLogging                   *bool                                  `json:"enable_logging,omitempty"`
	OptimizeStreamingLatency        *bool                                  `json:"optimize_streaming_latency,omitempty"`
	WithTimestamps                  *bool                                  `json:"with_timestamps,omitempty"` // Returns character-level timing information

	// Dynamic parameters that can be provider-specific, they are directly
	// added to the request as is.
	ExtraParams map[string]interface{} `json:"-"`
}

type SpeechPronunciationDictionaryLocator

type SpeechPronunciationDictionaryLocator struct {
	PronunciationDictionaryID string  `json:"pronunciation_dictionary_id"`
	VersionID                 *string `json:"version_id,omitempty"`
}

type SpeechStreamResponseType

type SpeechStreamResponseType string
const (
	SpeechStreamResponseTypeDelta SpeechStreamResponseType = "speech.audio.delta"
	SpeechStreamResponseTypeDone  SpeechStreamResponseType = "speech.audio.done"
)

type SpeechUsage

type SpeechUsage struct {
	InputTokens       int                           `json:"input_tokens"`
	InputTokenDetails *SpeechUsageInputTokenDetails `json:"input_token_details,omitempty"`
	OutputTokens      int                           `json:"output_tokens"`
	TotalTokens       int                           `json:"total_tokens"`
}

type SpeechUsageInputTokenDetails

type SpeechUsageInputTokenDetails struct {
	TextTokens  int `json:"text_tokens,omitempty"`
	AudioTokens int `json:"audio_tokens,omitempty"`
}

type SpeechVoiceInput

type SpeechVoiceInput struct {
	Voice            *string
	MultiVoiceConfig []VoiceConfig
}

func (*SpeechVoiceInput) MarshalJSON

func (vi *SpeechVoiceInput) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshalling for SpeechVoiceInput. It marshals either Voice or MultiVoiceConfig directly without wrapping.

func (*SpeechVoiceInput) UnmarshalJSON

func (vi *SpeechVoiceInput) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for SpeechVoiceInput. It determines whether "voice" is a string or a VoiceConfig object/array and assigns to the appropriate field. It also handles direct string/array content without a wrapper object.

type StreamAccumulatorResult

type StreamAccumulatorResult struct {
	RequestID             string                          // Request ID
	Model                 string                          // Model used
	Provider              ModelProvider                   // Provider used
	Status                string                          // Status of the stream
	Latency               int64                           // Latency in milliseconds
	TimeToFirstToken      int64                           // Time to first token in milliseconds
	OutputMessage         *ChatMessage                    // Accumulated output message
	OutputMessages        []ResponsesMessage              // For responses API
	TokenUsage            *BifrostLLMUsage                // Token usage
	Cost                  *float64                        // Cost in dollars
	ErrorDetails          *BifrostError                   // Error details if any
	AudioOutput           *BifrostSpeechResponse          // For speech streaming
	TranscriptionOutput   *BifrostTranscriptionResponse   // For transcription streaming
	ImageGenerationOutput *BifrostImageGenerationResponse // For image generation streaming
	FinishReason          *string                         // Finish reason
	RawResponse           *string                         // Raw response
	RawRequest            interface{}                     // Raw request
}

StreamAccumulatorResult contains the accumulated data from streaming chunks. This is the return type for tracer's streaming accumulation methods.

type StreamControl

type StreamControl struct {
	LogError   *bool `json:"log_error,omitempty"`   // Optional: Controls logging of error
	SkipStream *bool `json:"skip_stream,omitempty"` // Optional: Controls skipping of stream chunk
}

StreamControl represents stream control options.

type TextCompletionInput

type TextCompletionInput struct {
	PromptStr   *string
	PromptArray []string
}

func (*TextCompletionInput) MarshalJSON

func (t *TextCompletionInput) MarshalJSON() ([]byte, error)

func (*TextCompletionInput) UnmarshalJSON

func (t *TextCompletionInput) UnmarshalJSON(data []byte) error

type TextCompletionLogProb

type TextCompletionLogProb struct {
	TextOffset    []int                `json:"text_offset"`
	TokenLogProbs []float64            `json:"token_logprobs"`
	Tokens        []string             `json:"tokens"`
	TopLogProbs   []map[string]float64 `json:"top_logprobs"`
}

TextCompletionLogProb represents log probability information for text completion.

type TextCompletionParameters

type TextCompletionParameters struct {
	BestOf           *int                `json:"best_of,omitempty"`
	Echo             *bool               `json:"echo,omitempty"`
	FrequencyPenalty *float64            `json:"frequency_penalty,omitempty"`
	LogitBias        *map[string]float64 `json:"logit_bias,omitempty"`
	LogProbs         *int                `json:"logprobs,omitempty"`
	MaxTokens        *int                `json:"max_tokens,omitempty"`
	N                *int                `json:"n,omitempty"`
	PresencePenalty  *float64            `json:"presence_penalty,omitempty"`
	Seed             *int                `json:"seed,omitempty"`
	Stop             []string            `json:"stop,omitempty"`
	Suffix           *string             `json:"suffix,omitempty"`
	StreamOptions    *ChatStreamOptions  `json:"stream_options,omitempty"`
	Temperature      *float64            `json:"temperature,omitempty"`
	TopP             *float64            `json:"top_p,omitempty"`
	User             *string             `json:"user,omitempty"`

	// Dynamic parameters that can be provider-specific, they are directly
	// added to the request as is.
	ExtraParams map[string]interface{} `json:"-"`
}

type TextCompletionResponseChoice

type TextCompletionResponseChoice struct {
	Text *string `json:"text,omitempty"`
}

type ToolFunctionParameters

type ToolFunctionParameters struct {
	Type                 string                      `json:"type"`                           // Type of the parameters
	Description          *string                     `json:"description,omitempty"`          // Description of the parameters
	Properties           *OrderedMap                 `json:"properties"`                     // Parameter properties - always include even if empty (required by JSON Schema and some providers like OpenAI)
	Required             []string                    `json:"required,omitempty"`             // Required parameter names
	AdditionalProperties *AdditionalPropertiesStruct `json:"additionalProperties,omitempty"` // Whether to allow additional properties
	Enum                 []string                    `json:"enum,omitempty"`                 // Enum values for the parameters

	// JSON Schema definition fields
	Defs        *OrderedMap `json:"$defs,omitempty"`       // JSON Schema draft 2019-09+ definitions
	Definitions *OrderedMap `json:"definitions,omitempty"` // Legacy JSON Schema draft-07 definitions
	Ref         *string     `json:"$ref,omitempty"`        // Reference to definition

	// Array schema fields
	Items    *OrderedMap `json:"items,omitempty"`    // Array element schema
	MinItems *int64      `json:"minItems,omitempty"` // Minimum array length
	MaxItems *int64      `json:"maxItems,omitempty"` // Maximum array length

	// Composition fields (union types)
	AnyOf []OrderedMap `json:"anyOf,omitempty"` // Union types (any of these schemas)
	OneOf []OrderedMap `json:"oneOf,omitempty"` // Exclusive union types (exactly one of these)
	AllOf []OrderedMap `json:"allOf,omitempty"` // Schema intersection (all of these)

	// String validation fields
	Format    *string `json:"format,omitempty"`    // String format (email, date, uri, etc.)
	Pattern   *string `json:"pattern,omitempty"`   // Regex pattern for strings
	MinLength *int64  `json:"minLength,omitempty"` // Minimum string length
	MaxLength *int64  `json:"maxLength,omitempty"` // Maximum string length

	// Number validation fields
	Minimum *float64 `json:"minimum,omitempty"` // Minimum number value
	Maximum *float64 `json:"maximum,omitempty"` // Maximum number value

	// Misc fields
	Title    *string     `json:"title,omitempty"`    // Schema title
	Default  interface{} `json:"default,omitempty"`  // Default value
	Nullable *bool       `json:"nullable,omitempty"` // Nullable indicator (OpenAPI 3.0 style)
	// contains filtered or unexported fields
}

ToolFunctionParameters represents the parameters for a function definition. It supports JSON Schema fields used by various providers (OpenAI, Anthropic, Gemini, etc.). Field order follows JSON Schema / OpenAI conventions for consistent serialization.

IMPORTANT: When marshalling to JSON, key order is preserved from the original input (captured during UnmarshalJSON). When constructing programmatically, the default struct field declaration order is used. This is critical because LLMs are sensitive to JSON key ordering in tool schemas.

func (ToolFunctionParameters) MarshalJSON

func (t ToolFunctionParameters) MarshalJSON() ([]byte, error)

MarshalJSON serializes ToolFunctionParameters to JSON, preserving the original key order from the input JSON. If no original order was captured (programmatic construction), it falls back to the default struct field declaration order. Properties is always emitted as an object, never null.

func (*ToolFunctionParameters) UnmarshalJSON

func (t *ToolFunctionParameters) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling for ToolFunctionParameters. It handles both JSON object format (standard) and JSON string format (used by some providers like xAI). It captures the original key order for order-preserving re-serialization.

type TopProvider

type TopProvider struct {
	IsModerated         *bool `json:"is_moderated,omitempty"`
	ContextLength       *int  `json:"context_length,omitempty"`
	MaxCompletionTokens *int  `json:"max_completion_tokens,omitempty"`
}

type Trace

type Trace struct {
	TraceID    string         // Unique identifier for this trace
	ParentID   string         // Parent trace ID from incoming W3C traceparent header
	RootSpan   *Span          // The root span of this trace
	Spans      []*Span        // All spans in this trace
	StartTime  time.Time      // When the trace started
	EndTime    time.Time      // When the trace completed
	Attributes map[string]any // Additional attributes for the trace
	// contains filtered or unexported fields
}

Trace represents a distributed trace that captures the full lifecycle of a request

func (*Trace) AddSpan

func (t *Trace) AddSpan(span *Span)

AddSpan adds a span to the trace in a thread-safe manner

func (*Trace) GetSpan

func (t *Trace) GetSpan(spanID string) *Span

GetSpan retrieves a span by ID

func (*Trace) Reset

func (t *Trace) Reset()

Reset clears the trace for reuse from pool

type Tracer

type Tracer interface {
	// CreateTrace creates a new trace with optional parent ID and returns the trace ID.
	// The parentID can be extracted from W3C traceparent headers for distributed tracing.
	CreateTrace(parentID string) string

	// EndTrace completes a trace and returns the trace data for observation/export.
	// After this call, the trace is removed from active tracking and returned for cleanup.
	// Returns nil if trace not found.
	EndTrace(traceID string) *Trace

	// StartSpan creates a new span as a child of the current span in context.
	// Returns updated context with new span and a handle for the span.
	// The context should be used for subsequent operations to maintain span hierarchy.
	StartSpan(ctx context.Context, name string, kind SpanKind) (context.Context, SpanHandle)

	// EndSpan completes a span with status and optional message.
	// Should be called when the operation represented by the span is complete.
	EndSpan(handle SpanHandle, status SpanStatus, statusMsg string)

	// SetAttribute sets an attribute on the span.
	// Attributes provide additional context about the operation.
	SetAttribute(handle SpanHandle, key string, value any)

	// AddEvent adds a timestamped event to the span.
	// Events represent discrete occurrences during the span's lifetime.
	AddEvent(handle SpanHandle, name string, attrs map[string]any)

	// PopulateLLMRequestAttributes populates all LLM-specific request attributes on the span.
	// This includes model parameters, input messages, temperature, max tokens, etc.
	PopulateLLMRequestAttributes(handle SpanHandle, req *BifrostRequest)

	// PopulateLLMResponseAttributes populates all LLM-specific response attributes on the span.
	// This includes output messages, tokens, usage stats, and error information if present.
	PopulateLLMResponseAttributes(handle SpanHandle, resp *BifrostResponse, err *BifrostError)

	// StoreDeferredSpan stores a span handle for later completion (used for streaming requests).
	// The span handle is stored keyed by trace ID so it can be retrieved when the stream completes.
	StoreDeferredSpan(traceID string, handle SpanHandle)

	// GetDeferredSpanHandle retrieves a deferred span handle by trace ID.
	// Returns nil if no deferred span exists for the given trace ID.
	GetDeferredSpanHandle(traceID string) SpanHandle

	// ClearDeferredSpan removes the deferred span handle for a trace ID.
	// Should be called after the deferred span has been completed.
	ClearDeferredSpan(traceID string)

	// GetDeferredSpanID returns the span ID for the deferred span.
	// Returns empty string if no deferred span exists.
	GetDeferredSpanID(traceID string) string

	// AddStreamingChunk accumulates a streaming chunk for the deferred span.
	// Pass the full BifrostResponse to capture content, tool calls, reasoning, etc.
	// This is called for each streaming chunk to build up the complete response.
	AddStreamingChunk(traceID string, response *BifrostResponse)

	// GetAccumulatedChunks returns the accumulated BifrostResponse, TTFT, and chunk count for a deferred span.
	// Returns the built response (with content, tool calls, etc.), time-to-first-token in ms, and total chunk count.
	// Returns nil, 0, 0 if no accumulated data exists.
	GetAccumulatedChunks(traceID string) (response *BifrostResponse, ttftMs int64, chunkCount int)

	// CreateStreamAccumulator creates a new stream accumulator for the given trace ID.
	// This should be called at the start of a streaming request.
	CreateStreamAccumulator(traceID string, startTime time.Time)

	// CleanupStreamAccumulator removes the stream accumulator for the given trace ID.
	// This should be called after the streaming request is complete.
	CleanupStreamAccumulator(traceID string)

	// ProcessStreamingChunk processes a streaming chunk and accumulates it.
	// Returns the accumulated result. IsFinal will be true when the stream is complete.
	// This method is used by plugins to access accumulated streaming data.
	// The ctx parameter must contain the stream end indicator for proper final chunk detection.
	ProcessStreamingChunk(traceID string, isFinalChunk bool, result *BifrostResponse, err *BifrostError) *StreamAccumulatorResult

	// Stop releases resources associated with the tracer.
	// Should be called during shutdown to stop background goroutines.
	Stop()
}

Tracer defines the interface for distributed tracing in Bifrost. Implementations can be injected via BifrostConfig to enable automatic instrumentation. The interface is designed to be minimal and implementation-agnostic.

func DefaultTracer

func DefaultTracer() Tracer

DefaultTracer returns a no-op tracer for use when tracing is disabled.

type TranscriptionAdditionalFormat

type TranscriptionAdditionalFormat struct {
	Format                      TranscriptionExportOptions `json:"format"`
	IncludeSpeakers             *bool                      `json:"include_speakers,omitempty"`
	IncludeTimestamps           *bool                      `json:"include_timestamps,omitempty"`
	SegmentOnSilenceLongerThanS *float64                   `json:"segment_on_silence_longer_than_s,omitempty"`
	MaxSegmentDurationS         *float64                   `json:"max_segment_duration_s,omitempty"`
	MaxSegmentChars             *int                       `json:"max_segment_chars,omitempty"`
	MaxCharactersPerLine        *int                       `json:"max_characters_per_line,omitempty"`
}

type TranscriptionExportOptions

type TranscriptionExportOptions string
const (
	TranscriptionExportOptionsSegmentedJson TranscriptionExportOptions = "segmented_json"
	TranscriptionExportOptionsDocx          TranscriptionExportOptions = "docx"
	TranscriptionExportOptionsPdf           TranscriptionExportOptions = "pdf"
	TranscriptionExportOptionsTxt           TranscriptionExportOptions = "txt"
	TranscriptionExportOptionsHtml          TranscriptionExportOptions = "html"
	TranscriptionExportOptionsSrt           TranscriptionExportOptions = "srt"
)

type TranscriptionInput

type TranscriptionInput struct {
	File []byte `json:"file"`
}

type TranscriptionLogProb

type TranscriptionLogProb struct {
	Token   string  `json:"token"`
	LogProb float64 `json:"logprob"`
	Bytes   []int   `json:"bytes"`
}

TranscriptionLogProb represents log probability information for transcription

type TranscriptionParameters

type TranscriptionParameters struct {
	Language               *string  `json:"language,omitempty"`
	Prompt                 *string  `json:"prompt,omitempty"`
	ResponseFormat         *string  `json:"response_format,omitempty"`         // Default is "json"
	Temperature            *float64 `json:"temperature,omitempty"`             // Sampling temperature (0.0-1.0)
	TimestampGranularities []string `json:"timestamp_granularities,omitempty"` // "word" and/or "segment"; requires response_format=verbose_json
	Include                []string `json:"include,omitempty"`                 // Additional response info (e.g., logprobs)
	Format                 *string  `json:"file_format,omitempty"`             // Type of file, not required in openai, but required in gemini
	MaxLength              *int     `json:"max_length,omitempty"`              // Maximum length of the transcription used by HuggingFace
	MinLength              *int     `json:"min_length,omitempty"`              // Minimum length of the transcription used by HuggingFace
	MaxNewTokens           *int     `json:"max_new_tokens,omitempty"`          // Maximum new tokens to generate used by HuggingFace
	MinNewTokens           *int     `json:"min_new_tokens,omitempty"`          // Minimum new tokens to generate used by HuggingFace

	// Elevenlabs-specific fields
	AdditionalFormats []TranscriptionAdditionalFormat `json:"additional_formats,omitempty"`
	WebhookMetadata   interface{}                     `json:"webhook_metadata,omitempty"`

	// Dynamic parameters that can be provider-specific, they are directly
	// added to the request as is.
	ExtraParams map[string]interface{} `json:"-"`
}

type TranscriptionSegment

type TranscriptionSegment struct {
	ID               int     `json:"id"`
	Seek             int     `json:"seek"`
	Start            float64 `json:"start"`
	End              float64 `json:"end"`
	Text             string  `json:"text"`
	Tokens           []int   `json:"tokens"`
	Temperature      float64 `json:"temperature"`
	AvgLogProb       float64 `json:"avg_logprob"`
	CompressionRatio float64 `json:"compression_ratio"`
	NoSpeechProb     float64 `json:"no_speech_prob"`
}

TranscriptionSegment represents segment-level transcription information

type TranscriptionStreamResponseType

type TranscriptionStreamResponseType string
const (
	TranscriptionStreamResponseTypeDelta TranscriptionStreamResponseType = "transcript.text.delta"
	TranscriptionStreamResponseTypeDone  TranscriptionStreamResponseType = "transcript.text.done"
)

type TranscriptionUsage

type TranscriptionUsage struct {
	Type              string                               `json:"type"` // "tokens" or "duration"
	InputTokens       *int                                 `json:"input_tokens,omitempty"`
	InputTokenDetails *TranscriptionUsageInputTokenDetails `json:"input_token_details,omitempty"`
	OutputTokens      *int                                 `json:"output_tokens,omitempty"`
	TotalTokens       *int                                 `json:"total_tokens,omitempty"`
	Seconds           *int                                 `json:"seconds,omitempty"` // For duration-based usage
}

TranscriptionUsage represents usage information for transcription

type TranscriptionUsageInputTokenDetails

type TranscriptionUsageInputTokenDetails struct {
	TextTokens  int `json:"text_tokens"`
	AudioTokens int `json:"audio_tokens"`
}

type TranscriptionWord

type TranscriptionWord struct {
	Word  string  `json:"word"`
	Start float64 `json:"start"`
	End   float64 `json:"end"`
}

TranscriptionWord represents word-level timing information

type URLTypeInfo

type URLTypeInfo struct {
	Type                 ImageContentType
	MediaType            *string
	DataURLWithoutPrefix *string // URL without the prefix (eg data:image/png;base64,iVBORw0KGgo...)
}

URLTypeInfo contains extracted information about a URL

func ExtractURLTypeInfo

func ExtractURLTypeInfo(sanitizedURL string) URLTypeInfo

ExtractURLTypeInfo extracts type and media type information from a sanitized URL. For data URLs, it parses the media type and encoding. For regular URLs, it attempts to infer the media type from the file extension.

type VLLMKeyConfig

type VLLMKeyConfig struct {
	URL       EnvVar `json:"url"`        // VLLM server base URL (required, supports env. prefix)
	ModelName string `json:"model_name"` // Exact model name served on this VLLM instance (used for key selection)
}

VLLMKeyConfig represents the vLLM-specific key configuration. It allows each key to target a different vLLM server URL and model name, enabling per-key routing and round-robin load balancing across multiple vLLM instances.

type VertexKeyConfig

type VertexKeyConfig struct {
	ProjectID       EnvVar            `json:"project_id"`
	ProjectNumber   EnvVar            `json:"project_number"`
	Region          EnvVar            `json:"region"`
	AuthCredentials EnvVar            `json:"auth_credentials"`
	Deployments     map[string]string `json:"deployments,omitempty"` // Mapping of model identifiers to inference profiles
}

VertexKeyConfig represents the Vertex-specific configuration. It contains Vertex-specific settings required for authentication and service access.

type VideoCreateError

type VideoCreateError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

VideoCreateError is the error payload when video generation fails.

type VideoDownloadVariant

type VideoDownloadVariant string
const (
	VideoDownloadVariantVideo       VideoDownloadVariant = "video"
	VideoDownloadVariantThumbnail   VideoDownloadVariant = "thumbnail"
	VideoDownloadVariantSpriteSheet VideoDownloadVariant = "sprite_sheet"
)

type VideoGenerationInput

type VideoGenerationInput struct {
	Prompt         string  `json:"prompt"`
	InputReference *string `json:"input_reference,omitempty"` // Primary image for image-to-video (OpenAI-compatible)
}

type VideoGenerationParameters

type VideoGenerationParameters struct {
	Seconds *string `json:"seconds,omitempty"`
	Size    string  `json:"size,omitempty"`

	NegativePrompt *string        `json:"negative_prompt,omitempty"`
	Seed           *int           `json:"seed,omitempty"`
	VideoURI       *string        `json:"video_uri,omitempty"` // for video to video generation
	Audio          *bool          `json:"audio,omitempty"`
	ExtraParams    map[string]any `json:"-"`
}

type VideoLogParams

type VideoLogParams struct {
	VideoID string `json:"video_id"`
}

type VideoObject

type VideoObject struct {
	ID                 string            `json:"id"`
	Object             string            `json:"object"` // always "video"
	Model              string            `json:"model"`
	Status             VideoStatus       `json:"status"`
	CreatedAt          int64             `json:"created_at"`
	CompletedAt        *int64            `json:"completed_at,omitempty"`
	ExpiresAt          *int64            `json:"expires_at,omitempty"`
	Progress           *float64          `json:"progress,omitempty"`
	Prompt             string            `json:"prompt"`
	RemixedFromVideoID *string           `json:"remixed_from_video_id,omitempty"`
	Seconds            *string           `json:"seconds"`
	Size               string            `json:"size"`
	Error              *VideoCreateError `json:"error,omitempty"`
}

type VideoOutput

type VideoOutput struct {
	Type        VideoOutputType `json:"type"` // "url" | "base64"
	URL         *string         `json:"url,omitempty"`
	Base64Data  *string         `json:"base64,omitempty"`
	ContentType string          `json:"content_type"`
}

type VideoOutputType

type VideoOutputType string
const (
	VideoOutputTypeBase64 VideoOutputType = "base64"
	VideoOutputTypeURL    VideoOutputType = "url"
)

type VideoReferenceInput

type VideoReferenceInput struct {
	Image         []byte `json:"image"`                    // Image bytes
	ReferenceType string `json:"reference_type,omitempty"` // "style" or "asset" (Gemini: "REFERENCE_TYPE_STYLE" or "REFERENCE_TYPE_ASSET")
}

VideoReferenceInput represents a reference image for video generation

type VideoResult

type VideoResult struct {
	URL             string   `json:"url"`
	ThumbnailURL    *string  `json:"thumbnail_url,omitempty"`
	ThumbnailWidth  *int     `json:"thumbnail_width,omitempty"`
	ThumbnailHeight *int     `json:"thumbnail_height,omitempty"`
	Duration        *float64 `json:"duration,omitempty"`
}

type VideoStatus

type VideoStatus string

VideoStatus is the lifecycle status of a video job.

const (
	VideoStatusQueued     VideoStatus = "queued"
	VideoStatusInProgress VideoStatus = "in_progress"
	VideoStatusCompleted  VideoStatus = "completed"
	VideoStatusFailed     VideoStatus = "failed"
)

type VoiceConfig

type VoiceConfig struct {
	Speaker string `json:"speaker"`
	Voice   string `json:"voice"`
}

Jump to

Keyboard shortcuts

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