Documentation
¶
Overview ¶
Package routing turns the model name a client asked for into the model and accounts that serve it: model mapping rules, the catalog with admin overrides, and access checks.
Index ¶
Constants ¶
const ( PayloadDefault = "default" // set the field only when the request doesn't have it PayloadOverride = "override" // always set the field PayloadRemove = "remove" // delete the field )
Payload rule modes.
const ( StrategyRoundRobin = "round_robin" // rotate, least recently used first StrategyFill = "fill" // always the first account until it's limited StrategyMostRemaining = "most_remaining" // the account with the most quota left StrategyRandom = "random" )
Account selection strategies within a provider's highest available priority tier.
const ( FormatAnthropic = "anthropic" FormatOpenAI = "openai" FormatResponses = "responses" FormatOpenRouter = "openrouter" )
Client API formats, used to scope mapping rules.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type CustomModel ¶
type ImageSettings ¶
type ImageSettings struct {
Enabled bool `json:"enabled"`
// Model is the Responses model that runs the tool; requests are routed and checked
// against key allow-lists as this model.
Model string `json:"model"`
// ToolModel is the image model used when the request doesn't name a gpt-image one.
ToolModel string `json:"toolModel"`
// AutoTool adds the image_generation tool to Responses API requests sent to Codex.
AutoTool bool `json:"autoTool"`
}
ImageSettings control /v1/images, served by Codex's image_generation tool.
type ModelOverride ¶
type ModelOverride struct {
Disabled bool `json:"disabled"`
Name string `json:"name"`
// Accounts limits which accounts may serve the model; empty means any.
Accounts []int64 `json:"accounts"`
Strategy string `json:"strategy"`
// Effort applies when the request doesn't set one.
Effort string `json:"effort"`
}
type PayloadRule ¶
type PayloadRule struct {
ID string `json:"id"`
Enabled bool `json:"enabled"`
// Match is a model glob (bare or lab-prefixed); empty matches every model.
Match string `json:"match"`
Provider string `json:"provider"` // "" any, "claude", "codex"
Formats []string `json:"formats"` // client API formats; empty = all
Mode string `json:"mode"`
Path string `json:"path"` // dot path, e.g. "service_tier" or "reasoning.effort"
Value json.RawMessage `json:"value"`
Note string `json:"note"`
}
PayloadRule edits the final upstream request body, after all translation.
type Request ¶
type Request struct {
Model string
Format string
KeyRules KeyRules
Allowed []string
// Providers optionally restricts which providers may serve it (OpenRouter's provider.only).
Providers []string
}
Request is what the resolver needs to know about an incoming call.
type Route ¶
type Route struct {
Requested string `json:"requested"`
Mapped string `json:"mapped,omitempty"` // set when a rule rewrote the name
Rule string `json:"rule,omitempty"` // "key" or "global"
Model models.Model `json:"model"`
Effort string `json:"effort,omitempty"`
// DefaultEffort applies only when the request itself doesn't ask for a reasoning level.
DefaultEffort string `json:"defaultEffort,omitempty"`
Accounts []int64 `json:"accounts,omitempty"`
Strategy string `json:"strategy"`
Catalog bool `json:"inCatalog"`
}
type Rule ¶
type Rule struct {
ID string `json:"id"`
Enabled bool `json:"enabled"`
// Match is a case-insensitive glob over the requested name, with or without a lab prefix.
Match string `json:"match"`
Target string `json:"target"`
// Effort overrides the reasoning effort; empty keeps the requested one.
Effort string `json:"effort"`
// Formats limits the rule to some client API formats; empty means all.
Formats []string `json:"formats"`
Note string `json:"note"`
}
Rule rewrites a requested model name before resolution.
type Settings ¶
type Settings struct {
// Strategy is the default account selection; ProviderStrategy overrides it per provider.
Strategy string `json:"strategy"`
ProviderStrategy map[string]string `json:"providerStrategy"`
// Affinity keeps related requests on the same account for StickyMinutes after their last
// use, which keeps upstream prompt caches warm and thinking signatures valid:
// "session" (per conversation), "key" (per API key) or "off". The binding is dropped if the
// account becomes unavailable.
Affinity string `json:"affinity"`
// Sticky is the pre-affinity setting, kept so older saved settings still load.
Sticky bool `json:"sticky,omitempty"`
StickyMinutes int `json:"stickyMinutes"`
// ModelList picks names in /v1/models: "bare" (claude-opus-5), "canonical"
// (anthropic/claude-opus-5) or "both". OpenRouter-style paths always list canonical names.
ModelList string `json:"modelList"`
// UnknownModels decides whether names missing from the catalog are passed through to the
// provider their family suggests ("claude-…" → Claude).
UnknownModels bool `json:"unknownModels"`
// ReasoningField is where Chat Completions responses put reasoning text:
// "reasoning_content", "reasoning" (OpenRouter style) or "both".
ReasoningField string `json:"reasoningField"`
Models map[string]ModelOverride `json:"models"` // keyed by canonical name
Custom []CustomModel `json:"custom"`
Mappings []Rule `json:"mappings"`
// PayloadRules edit upstream request bodies after translation.
PayloadRules []PayloadRule `json:"payloadRules"`
Images ImageSettings `json:"images"`
}
func DefaultSettings ¶
func DefaultSettings() Settings
func (Settings) ApplyPayloadRules ¶
ApplyPayloadRules runs every matching rule over an upstream body and reports whether it changed.
func (Settings) Catalog ¶
Catalog is every model: built-ins, then custom ones, with display-name overrides applied.