Documentation
¶
Overview ¶
Package alias holds remora's model aliases and compiles them into a flat chain of provider targets.
Index ¶
- Constants
- Variables
- func CheckThinking(ref string, isSubscription func(provider string) bool) error
- func EngineModel(name string) string
- func ParseThinking(ref string) (base, level string, ok bool)
- func ValidName(name string) error
- type Alias
- type Chain
- type CostMix
- type Kind
- type Member
- type Strategy
- type Target
Constants ¶
const AnyModel = "*"
AnyModel matches every model of a provider, used for provider-wide cooling.
const DefaultMaxDepth = 5
DefaultMaxDepth is the nesting limit used when Compile is given maxDepth <= 0.
const FirstHeader = "X-Remora-First"
FirstHeader names the member a spreading alias's request tries first; set only by the proxy.
Variables ¶
var ( ErrCycle = errors.New("alias: cycle") ErrDepth = errors.New("alias: nesting too deep") ErrUnknownMember = errors.New("alias: unknown member") ErrEmpty = errors.New("alias: no members") )
Compile errors. Returned errors wrap one of these and name the alias path.
var AliasStrategies = append(slices.Clone(Strategies), StrategyCost)
AliasStrategies lists every strategy an alias may use, in UI and documentation order.
var ErrInvalidName = errors.New("alias: invalid name")
ErrInvalidName means an alias name does not match the allowed pattern.
var Strategies = []Strategy{StrategyPriority, StrategyFillFirst, StrategyRoundRobin, StrategyRandom, StrategyP2C, StrategyLeastUsed}
Strategies lists the six routing strategies shared by aliases and account pools, in documentation order.
Functions ¶
func CheckThinking ¶ added in v0.2.1
CheckThinking refuses a member ref whose thinking suffix is not a valid level, or that carries one on a provider isSubscription does not name: there it would reach the provider as an unknown model. Alias names pass.
func EngineModel ¶ added in v0.1.3
EngineModel is the model remora sends the front door for an alias. The front door reads "<provider>/<model>" as a direct provider model whenever the prefix names one of its providers, so "openai/fast" would never reach its routing rule; behind the prefix the whole alias stays one model name.
func ParseThinking ¶ added in v0.2.1
ParseThinking splits a member ref "<provider>/<model>(<level>)" into the ref without the suffix and the level, the way the OAuth engine reads it: the last "(" of a ref that ends in ")". level is "" when the ref has no suffix. ok is false when a suffix is present but is not one of minimal, low, medium, high, or a whole number of thinking tokens (0 = off).
Types ¶
type Alias ¶
type Alias struct {
Name string
Kind Kind
Members []Member
Capabilities []string // advertised supported_parameters, e.g. "structured_outputs", "tools"
ContextWindow int // 0 = unset
Strategy Strategy // how the alias's own compiled chain is used; a nested alias is flattened in order
CostMix *CostMix // nil = learned from traffic; allowed only for StrategyCost
}
Alias is a named, ordered list of members that clients call as a model.
type Chain ¶ added in v0.3.0
type Chain struct {
Strategy Strategy
Members []string
Prices []int64 // per member, effective micro-USD per 1 M tokens, -1 = unpriced; set only for cost
}
Chain is the live chain of one alias with member rules as the reconciler last pushed it: distinct member refs "<provider>/<model>" (user-facing), in ranked/declared order, each with its own rule.
type CostMix ¶ added in v0.11.0
type CostMix struct {
In float64 `json:"in" yaml:"in"`
Out float64 `json:"out" yaml:"out"`
Cache float64 `json:"cache" yaml:"cache"`
}
CostMix holds token-type shares for pricing a cost alias; shares are normalized on use.
type Member ¶
type Member struct{ Ref string }
Member is one entry of an alias: an alias name, or "<provider>/<model>".
type Strategy ¶ added in v0.2.0
type Strategy string
Strategy is how an alias picks the first member a request tries.
const ( StrategyPriority Strategy = "priority" StrategyFillFirst Strategy = "fill-first" StrategyRoundRobin Strategy = "round-robin" StrategyRandom Strategy = "random" StrategyP2C Strategy = "p2c" StrategyLeastUsed Strategy = "least-used" StrategyCost Strategy = "cost" )
Routing strategies, the same six names at alias and account level, plus StrategyCost for aliases only. At alias level priority and fill-first behave the same: cooling already moves a request past a member that stopped answering.
func (Strategy) MemberRules ¶ added in v0.11.0
MemberRules reports whether the strategy uses per-member rules selected by FirstHeader.
func (Strategy) Spreads ¶ added in v0.3.0
Spreads reports a strategy that spreads first tries over the live members.
func (Strategy) Valid ¶ added in v0.2.0
Valid reports whether s is one of Strategies; "" is not, callers default it first.
func (Strategy) ValidForAlias ¶ added in v0.11.0
ValidForAlias reports whether s may be set on an alias.
type Target ¶
type Target struct{ Provider, Model string }
Target is a provider model an alias resolves to.
func Compile ¶
Compile expands the alias name into a flat, ordered chain of provider targets. Nested aliases are expanded depth first in member order, and a target already in the chain is dropped. A member ref is an alias when all has that key, otherwise "<provider>/<model>" split at the first "/". The named alias is depth 1; maxDepth <= 0 means DefaultMaxDepth.