Documentation
¶
Overview ¶
Package bifrost is remora's client for the front door's management API. It speaks to the engine over loopback HTTP with the admin credentials remora generated; nothing it returns is meant for a remora user.
Index ¶
- Constants
- Variables
- func IsStandardProvider(name string) bool
- type APIError
- type Client
- func (c *Client) CreateKey(ctx context.Context, provider string, k Key) error
- func (c *Client) CreateProvider(ctx context.Context, p Provider) error
- func (c *Client) CreateRoutingRule(ctx context.Context, r RoutingRule) (RoutingRule, error)
- func (c *Client) CreateVirtualKey(ctx context.Context, v VirtualKey) (VirtualKey, error)
- func (c *Client) DeleteKey(ctx context.Context, provider, id string) error
- func (c *Client) DeleteProvider(ctx context.Context, name string) error
- func (c *Client) DeleteRoutingRule(ctx context.Context, id string) error
- func (c *Client) DeleteVirtualKey(ctx context.Context, id string) error
- func (c *Client) GetLog(ctx context.Context, id string) (Log, error)
- func (c *Client) Health(ctx context.Context) error
- func (c *Client) Histogram(ctx context.Context, f LogFilter) ([]HistogramBucket, error)
- func (c *Client) ListKeys(ctx context.Context, provider string) ([]Key, error)
- func (c *Client) ListProviders(ctx context.Context) ([]Provider, error)
- func (c *Client) ListRoutingRules(ctx context.Context) ([]RoutingRule, error)
- func (c *Client) ListVirtualKeys(ctx context.Context) ([]VirtualKey, error)
- func (c *Client) LogStats(ctx context.Context, f LogFilter) (LogStats, error)
- func (c *Client) SearchLogs(ctx context.Context, f LogFilter) (LogPage, error)
- func (c *Client) UpdateKey(ctx context.Context, provider string, k Key) error
- func (c *Client) UpdateProvider(ctx context.Context, p Provider) error
- func (c *Client) UpdateRoutingRule(ctx context.Context, r RoutingRule) error
- func (c *Client) UpdateVirtualKey(ctx context.Context, v VirtualKey) error
- type HistogramBucket
- type Key
- type Log
- type LogFilter
- type LogPage
- type LogSource
- type LogStats
- type Provider
- type Route
- type RoutingRule
- type Tail
- type TokenUsage
- type VirtualKey
Constants ¶
const MaxLogLimit = 1000
MaxLogLimit is the largest page the front door's log search accepts; a larger limit is answered 400.
const OAuthProvider = "remora-oauth"
OAuthProvider is the OAuth engine's front-door provider (plan 03); its routing rules are named "remora-oauth-<name>".
Variables ¶
var ErrNotFound = errors.New("bifrost: not found")
ErrNotFound is matched by errors.Is when the engine answers 404.
Functions ¶
func IsStandardProvider ¶
IsStandardProvider reports whether name is one of the engine's built-in providers.
Types ¶
type APIError ¶
APIError is a non-2xx answer from the engine. Its text never reaches a client: the proxy maps errors itself.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the front door's management API.
func New ¶
New returns a client for the engine at baseURL (for example "http://127.0.0.1:18080"). A nil hc uses a fresh http.Client with no timeout; callers bound each call with its context.
func (*Client) CreateKey ¶
CreateKey adds a key to a provider. An empty ID lets the engine generate one. The engine wants key IDs and names unique across all providers.
func (*Client) CreateProvider ¶
CreateProvider adds a provider.
func (*Client) CreateRoutingRule ¶
func (c *Client) CreateRoutingRule(ctx context.Context, r RoutingRule) (RoutingRule, error)
CreateRoutingRule adds a routing rule and returns it with the engine's ID.
func (*Client) CreateVirtualKey ¶
func (c *Client) CreateVirtualKey(ctx context.Context, v VirtualKey) (VirtualKey, error)
CreateVirtualKey adds a virtual key and returns it with the engine's ID and Value.
func (*Client) DeleteProvider ¶
DeleteProvider removes a provider and its keys. The engine answers success for a provider it does not have.
func (*Client) DeleteRoutingRule ¶
DeleteRoutingRule removes a routing rule.
func (*Client) DeleteVirtualKey ¶
DeleteVirtualKey removes a virtual key.
func (*Client) GetLog ¶
GetLog calls GET /api/logs/{id}, which carries the row's error details. A missing row matches ErrNotFound.
func (*Client) Histogram ¶
Histogram calls GET /api/logs/histogram; the engine chooses the bucket size from the time range. Paging and sorting fields of f are ignored.
func (*Client) ListProviders ¶
ListProviders returns every provider the engine has configured.
func (*Client) ListRoutingRules ¶
func (c *Client) ListRoutingRules(ctx context.Context) ([]RoutingRule, error)
ListRoutingRules returns every routing rule.
func (*Client) ListVirtualKeys ¶
func (c *Client) ListVirtualKeys(ctx context.Context) ([]VirtualKey, error)
ListVirtualKeys returns every virtual key.
func (*Client) LogStats ¶
LogStats calls GET /api/logs/stats; paging and sorting fields of f are ignored.
func (*Client) SearchLogs ¶
SearchLogs calls GET /api/logs.
func (*Client) UpdateProvider ¶
UpdateProvider replaces a provider's network, concurrency and (for a custom provider) custom configuration. The engine creates the provider when it does not have it.
func (*Client) UpdateRoutingRule ¶
func (c *Client) UpdateRoutingRule(ctx context.Context, r RoutingRule) error
UpdateRoutingRule replaces a routing rule's name, expression, target, fallbacks and priority.
func (*Client) UpdateVirtualKey ¶
func (c *Client) UpdateVirtualKey(ctx context.Context, v VirtualKey) error
UpdateVirtualKey sets a virtual key's name and active flag.
type HistogramBucket ¶
type HistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
Count int64 `json:"count"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
HistogramBucket is one time bucket of GET /api/logs/histogram: the rows that started in it, by outcome.
type Key ¶
Key is one upstream key of a provider. Value is write-only: lists leave it empty, and the engine refuses an update without it.
type Log ¶
type Log struct {
ID string `json:"id"`
ParentRequestID *string `json:"parent_request_id"`
Timestamp time.Time `json:"timestamp"`
Provider string `json:"provider"`
Model string `json:"model"`
Status string `json:"status"` // "processing", "success" or "error"
// FallbackIndex is the attempt: 0 for the request itself, n for its nth fallback, whose ParentRequestID is the
// request's id.
FallbackIndex int `json:"fallback_index"`
VirtualKeyID *string `json:"virtual_key_id"`
RoutingRuleID *string `json:"routing_rule_id"`
Latency *float64 `json:"latency"` // milliseconds
Cost *float64 `json:"cost"` // dollars
Stream bool `json:"stream"`
TokenUsage *TokenUsage `json:"token_usage"`
// ErrorDetails is filled by GetLog only: the list leaves it out.
ErrorDetails json.RawMessage `json:"error_details,omitempty"`
// The bodies, filled by GetLog only.
InputHistory json.RawMessage `json:"input_history,omitempty"`
OutputMessage json.RawMessage `json:"output_message,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
}
Log is one row of the front door's request log. Timestamp is when the request started; the row is written when it completes.
type LogFilter ¶
type LogFilter struct {
Status []string // "processing", "success", "error"
Providers []string // front-door provider names
Models []string // front-door model names
VirtualKeyIDs []string // the virtual keys the requests came in on
RoutingRuleIDs []string // the routing rules that routed the requests
Start *time.Time // rows whose timestamp is at or after Start
End *time.Time // rows whose timestamp is at or before End
ContentSearch string // free text over the request and response content
ParentRequestID string // the fallback attempts of one request
Limit int // 1..MaxLogLimit
Offset int
SortBy string // "timestamp", "latency", "tokens" or "cost"
Order string // "asc" or "desc"
}
LogFilter narrows GET /api/logs and the stats and histogram built on the same filters. Zero fields are left out of the query, so the engine's defaults apply (limit 50, sort_by timestamp, order desc). List fields are sent comma-joined.
type LogStats ¶
type LogStats struct {
UserFacingTotalRequests int64 `json:"user_facing_total_requests"`
UserFacingSuccessRate float64 `json:"user_facing_success_rate"`
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
TotalCost float64 `json:"total_cost"`
}
LogStats is GET /api/logs/stats over a filter. The user-facing figures count a fallback chain once, as its root request; UserFacingSuccessRate is a percentage.
type Provider ¶
type Provider struct {
Name string
BaseType string
BaseURL string
AllowPrivateNetwork bool
AllowedRequests []string // custom_provider_config.allowed_requests as {"<type>": true}; nil = omitted (all allowed)
RequestTimeout time.Duration // network_config.default_request_timeout_in_seconds; 0 = 600 s
}
Provider is one front-door provider. BaseType "" is a standard provider; "openai" or "typesafe" makes a custom provider on that base.
type Route ¶
type Route struct{ Provider, Model string }
Route is a provider and model. In a rule target, Model "" is sent as null: the incoming model.
type RoutingRule ¶
RoutingRule is a global front-door routing rule with one target and an ordered fallback chain. The engine refuses two global rules with the same Priority, so each rule needs its own; rules whose CEL expressions never match the same request may take any distinct priorities.
type Tail ¶
type Tail struct {
// contains filtered or unexported fields
}
Tail follows the front door's request log by polling it, since the engine pushes no log rows. It delivers each completed row once to every subscriber, polls only while someone is subscribed, and never blocks on a subscriber.
func NewTail ¶
NewTail returns a Tail over src that polls every interval (1s when interval ≤ 0). A nil log discards.
func (*Tail) Run ¶
Run polls every interval until ctx is done, skipping ticks while nobody is subscribed.
type TokenUsage ¶
type TokenUsage struct {
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
}
TokenUsage is a row's token counts.
type VirtualKey ¶
VirtualKey is a front-door virtual key. Value (the engine's own key, sent upstream in x-bf-vk) is set by the engine and never reaches a user.