registry

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LevelBasic      = "basic"
	LevelProficient = "proficient"
	LevelExpert     = "expert"

	// TopicGeneral is the topic efforts stand for: low, medium and high are
	// general at basic, proficient and expert.
	TopicGeneral = "general"
)

Levels of a competency or a need, in order: a model meets a need at its level or above.

View Source
const (
	MCPStreamableHTTP = "streamable_http"
	MCPSSE            = "sse"
)

MCP transports.

View Source
const (
	DefaultMCPTimeout          = 60 * time.Second
	DefaultMCPMaxResponseBytes = 4 << 20
)

MCP server defaults for the 0 values of the spec.

View Source
const (
	VendorOpenAI    = "openai"
	VendorGoogle    = "google"
	VendorDeepSeek  = "deepseek"
	VendorOllama    = "ollama"
	VendorTypeSafe  = "typesafe"
	VendorAnthropic = "anthropic"
	VendorLocal     = "local"
	VendorGroq      = "groq"
	VendorMistral   = "mistral"
	VendorAzure     = "azure"
	VendorBedrock   = "bedrock"
)

Vendors the engine can construct adapters for. DeepSeek and Ollama ride the OpenAI adapter with a different base URL; Ollama is any self-hosted OpenAI-compatible server, so its endpoint is required and its key is its own. Local routes to self-registering local inference nodes.

View Source
const (
	EffortLow    = "low"
	EffortMedium = "medium"
	EffortHigh   = "high"
)

Efforts a model may serve and a request may ask for.

View Source
const (
	CapabilityTTS   = "tts"
	CapabilityImage = "image"
)

CapabilityTTS and CapabilityImage mark models that can serve the speech and image RPCs. Opt-in: a chain filtered for one of these keeps only models that declare it, so a text model can never be handed audio work.

View Source
const (
	CapabilityVision     = "vision"
	CapabilityAudioInput = "audio_input"
	CapabilityPDFInput   = "pdf_input"
)

Multimodal input capabilities mark chat models capable of handling specific media. Opt-in: request parts require the matching capability on the candidate model.

View Source
const AnthropicDefaultEndpoint = "https://api.anthropic.com"

AnthropicDefaultEndpoint is used when an anthropic model has no endpoint override.

View Source
const AnyLanguage = "*"

AnyLanguage in a model's languages matches every tag.

View Source
const AzureDefaultAPIVersion = "2024-06-01"

AzureDefaultAPIVersion is used when an azure model has no api-version query override.

View Source
const BedrockDefaultRegion = "us-east-1"

BedrockDefaultRegion is used when a bedrock credential does not specify a region.

View Source
const CapabilityBatch = "batch"

CapabilityBatch marks models that support batch processing.

View Source
const CapabilityEmbedding = "embedding"

CapabilityEmbedding marks models that compute text vector embeddings.

View Source
const CapabilityEmbeddingInput = "embedding_input"

CapabilityEmbeddingInput marks judge models that score raw latent vectors. No text model reads one, so it is opt-in even among judges.

View Source
const CapabilityGoogleSearch = "google_search"

CapabilityGoogleSearch marks models that can serve enable_google_search.

View Source
const CapabilityJudge = "judge"

CapabilityJudge marks models that answer typed questions instead of writing text. Opt-in like the other modalities: a judge chain keeps only models that declare it, so a chat model can never be handed a judgment.

View Source
const CapabilityNoSampling = "no_sampling"

CapabilityNoSampling marks a model whose API rejects sampling fields the table below would send it: the proxy then sends none of them.

View Source
const CapabilityNoStructuredOutput = "no_structured_output"

CapabilityNoStructuredOutput marks models whose API cannot be handed a JSON schema (DeepSeek rejects response_format json_schema outright). The shape is asked for in the prompt and checked by the router instead. Stated as the exception so a model that says nothing keeps the enforced behaviour.

View Source
const CapabilityNoThinking = "no_thinking"

CapabilityNoThinking marks models that reason by default unless told not to (DeepSeek V4 thinks at high effort, billed as output). The proxy turns it off the way the vendor understands.

View Source
const CapabilityPromptCache = "prompt_cache"

CapabilityPromptCache asks Anthropic to cache each call's tools and system prompt: worth it for long instructions that repeat across calls.

View Source
const CapabilitySampling = "sampling"

CapabilitySampling marks a model that takes its vendor's sampling fields although its id looks like one that does not: an Azure deployment name, a Claude alias, a reasoning model run without reasoning.

View Source
const CapabilityTranslate = "translate"

CapabilityTranslate marks models that serve Translate: MT engines natively, chat models through a prompt. Their languages narrow which pairs they take.

View Source
const DeepSeekDefaultEndpoint = "https://api.deepseek.com"

DeepSeekDefaultEndpoint is used when a deepseek model has no endpoint override.

View Source
const EngineFreeToken = "freetoken"

EngineFreeToken is the node engine name of a FreeToken server (`ft serve`).

View Source
const EngineMT = "mt"

EngineMT is the node engine name of a machine-translation server speaking KTMS's MT contract (GET /v1/models, POST /v1/translate), such as ktms-mt.

View Source
const GroqDefaultEndpoint = "https://api.groq.com/openai/v1"

GroqDefaultEndpoint is used when a groq model has no endpoint override.

View Source
const MistralDefaultEndpoint = "https://api.mistral.ai/v1"

MistralDefaultEndpoint is used when a mistral model has no endpoint override.

View Source
const OpenAIDefaultEndpoint = "https://api.openai.com"

OpenAIDefaultEndpoint is used when an openai model has no endpoint override.

View Source
const ReservedMCPServer = "agents"

ReservedMCPServer is the built-in server of the agents' inbox (agents.Server).

View Source
const TypeSafeDefaultEndpoint = "https://api.typesafe.ai"

TypeSafeDefaultEndpoint is used when a typesafe model has no endpoint override.

Variables

This section is empty.

Functions

func BlendedPrice added in v1.7.0

func BlendedPrice(m *proxydb.Model) float64

BlendedPrice is the price per million tokens selection ranks by: (3 x input + output) / 4 at the standard rate, as chats read more than they write.

func Competencies added in v1.7.0

func Competencies(m *proxydb.Model) map[string]string

Competencies returns m's competencies with its efforts read as general at the highest effort listed, unless general is set explicitly.

func ConfigureOpenAI

func ConfigureOpenAI(a *adapters.OpenAIAdapter, m *proxydb.Model, engine string)

ConfigureOpenAI applies the model's capabilities to an OpenAI-compatible adapter. Pool adapters pass the node's engine; direct vendors pass "".

func EffortLevel added in v1.7.0

func EffortLevel(effort string) string

EffortLevel maps an effort to the general level it stands for.

func Excess added in v1.7.0

func Excess(m *proxydb.Model, needs map[string]string) int

Excess sums, over the needed topics, how many levels m has above the need, so an expert is not spent where a basic model does; 0 for an exact fit. Efforts count at the highest one listed, as in Competencies, so a model described by efforts does not win a selection on price alone.

func FormatNeeds added in v1.7.0

func FormatNeeds(needs map[string]string) string

FormatNeeds writes needs as "general=basic,medical=proficient", sorted by topic: the form of usage meta, X-KTMS-Needs and the auto: model name.

func HasCapability

func HasCapability(m *proxydb.Model, capability string) bool

HasCapability reports whether a model lists the capability.

func LevelEffort added in v1.7.0

func LevelEffort(level string) string

LevelEffort is EffortLevel backwards, for meta["effort"] and old clients.

func LevelRank added in v1.7.0

func LevelRank(level string) int

LevelRank orders levels from 1 (basic) to 3 (expert); 0 is not a level.

func Meets added in v1.7.0

func Meets(m *proxydb.Model, topic, level string) bool

Meets reports whether m meets the need topic >= level. A model whose general comes from efforts meets a general need only at an effort it lists.

func MeetsAll added in v1.7.0

func MeetsAll(m *proxydb.Model, needs map[string]string) bool

MeetsAll reports whether m meets every need.

func ParseNeeds added in v1.7.0

func ParseNeeds(s string) (map[string]string, error)

ParseNeeds reads FormatNeeds' form; spaces around items are allowed.

func RequestNeeds added in v1.7.0

func RequestNeeds(needs map[string]string, effort string) (map[string]string, error)

RequestNeeds merges a request's needs with its deprecated effort, read as general unless the needs name general themselves, and validates them.

func RuleMatchesNeeds added in v1.7.0

func RuleMatchesNeeds(ruleNeeds, needs map[string]string) bool

RuleMatchesNeeds reports whether a request's needs reach a rule's: each topic the rule names at least at the rule's level.

func SamplingSupport added in v1.5.0

func SamplingSupport(m *proxydb.Model) llm.SamplingSupport

SamplingSupport is the sampling a model's API takes. Adapters send only that, and responses name the rest in ignored_parameters.

func Serves

func Serves(m *proxydb.Model, effort string) bool

Serves reports whether a model lists the effort.

func ServesLanguagePair added in v1.6.0

func ServesLanguagePair(m *proxydb.Model, source, target string) bool

ServesLanguagePair reports whether m declares the pair. An empty source in the request matches any: the engine detects it. A declared tag covers its longer variants; an empty list (never on a valid translate model) is any.

func SoftSchema

func SoftSchema(m *proxydb.Model) bool

SoftSchema reports whether this model needs the prompt-and-verify path.

func ThinkingOff

func ThinkingOff(vendor, engine string) map[string]any

ThinkingOff returns the request fields that turn a vendor's default reasoning off: Ollama and FreeToken take reasoning_effort, DeepSeek a thinking switch. A local node is judged by its engine; engines without a known switch get none.

func ValidEffort

func ValidEffort(e string) bool

func ValidLanguageTag added in v1.6.0

func ValidLanguageTag(tag string) bool

ValidLanguageTag accepts "*" and BCP-47-shaped tags: letters, digits and hyphens, a 2-3 letter primary subtag. Full registry validation is the engine's job; this catches typos such as "german" or "de_DE".

func ValidLevel added in v1.7.0

func ValidLevel(level string) bool

ValidLevel reports whether level is basic, proficient or expert.

func ValidMCPName added in v1.4.0

func ValidMCPName(name string) bool

ValidMCPName reports whether name may name an MCP server.

func ValidTopic added in v1.7.0

func ValidTopic(t string) bool

ValidTopic reports whether t is a topic name: lowercase letters, digits, "_" and "-", up to 64 characters. Topics are free; an unknown one is no error.

func ValidVendor

func ValidVendor(v string) bool

func Validate

func Validate(models []*proxydb.Model, rules []*proxydb.Rule) error

Validate checks the full config as it would take effect: enabled rules with chains filtered to enabled models. Runs inside every admin mutation transaction and on load, so an invalid state can never become active.

func ValidateLevels added in v1.7.0

func ValidateLevels(m map[string]string) error

ValidateLevels checks a topic -> level map of a model, rule or request.

func ValidateMCPServer added in v1.4.0

func ValidateMCPServer(m *proxydb.MCPServer) error

ValidateMCPServer checks a spec on its own; whether its host resolves to a private address is checked where the network is (the Admin API).

func ValidateModel

func ValidateModel(m *proxydb.Model) error

ValidateModel checks a single spec before it reaches the database.

Types

type Loader

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

Loader keeps the active Snapshot fresh: it polls config_state and rebuilds on version change. A failed rebuild keeps the last good snapshot serving.

func NewLoader

func NewLoader(db *proxydb.DB, keyring *crypto.Keyring, tracker llm.UsageTracker) *Loader

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) error

Load rebuilds the snapshot unconditionally. Called once at startup (an error is fatal there) and by the poll loop.

func (*Loader) Refresh

func (l *Loader) Refresh()

Refresh asks the poll loop to rebuild now (after an admin mutation in this replica). Non-blocking; a pending request is enough.

func (*Loader) SetNodePool

func (l *Loader) SetNodePool(np NodePoolResolver)

func (*Loader) Snapshot

func (l *Loader) Snapshot() *Snapshot

Snapshot returns the active config view; never nil.

func (*Loader) Start

func (l *Loader) Start(ctx context.Context, interval time.Duration)

Start polls for config changes every interval until ctx is cancelled.

type MCPServer added in v1.4.0

type MCPServer struct {
	proxydb.MCPServer
	Header string // "" when the server has no credential
	Value  string
}

MCPServer is an enabled MCP server with its decrypted credential.

func (*MCPServer) Fingerprint added in v1.4.0

func (m *MCPServer) Fingerprint() string

Fingerprint changes whenever anything a connection depends on does, so the gateway knows to drop a connection made with an older spec or credential.

func (*MCPServer) MaxResponse added in v1.4.0

func (m *MCPServer) MaxResponse() int64

MaxResponse bounds one tool result.

func (*MCPServer) Timeout added in v1.4.0

func (m *MCPServer) Timeout() time.Duration

Timeout bounds one tool call.

type NodePoolResolver

type NodePoolResolver interface {
	PoolAdapter(m *proxydb.Model) (llm.ClientAdapter, error)
}

NodePoolResolver builds an adapter for a local node pool model.

type Snapshot

type Snapshot struct {
	Version int64
	Models  map[string]*proxydb.Model // enabled only
	Rules   []*proxydb.Rule           // enabled only, sorted by priority desc

	// UserRateLimits[userID][modelID] = user rate limit overrides.
	UserRateLimits map[string]map[string]*proxydb.UserRateLimit
	// SpendLimits[subjectType+"\x00"+subjectID][period] = cap in nano-USD.
	SpendLimits map[string]map[string]int64
	// MCPServers[name] = enabled MCP server with its credential.
	MCPServers map[string]*MCPServer
	// contains filtered or unexported fields
}

Snapshot is one immutable view of the routing config: enabled models and rules plus decrypted vendor keys. Replaced wholesale on config change; decrypted keys live only here, in process memory.

func NewSnapshotForTest

func NewSnapshotForTest(models []*proxydb.Model, rules []*proxydb.Rule,
	vendorKeys map[string]map[string]string, tracker llm.UsageTracker) *Snapshot

NewSnapshotForTest builds a snapshot without a database — for tests only. vendorKeys is keyed [apiKeyID][vendor] = plain credential.

func (*Snapshot) Adapter

func (s *Snapshot) Adapter(apiKeyID string, m *proxydb.Model) (llm.ClientAdapter, error)

Adapter returns the vendor adapter for a (client, model) pair, built with the client's own decrypted credential and cached for the snapshot's lifetime. Concurrent first calls may build twice; LoadOrStore keeps one.

func (*Snapshot) CanCall

func (s *Snapshot) CanCall(apiKeyID string, m *proxydb.Model) bool

CanCall reports whether the client may use m. Local models reach nodes with the node's own token, so they need no vendor key.

func (*Snapshot) ClientModels

func (s *Snapshot) ClientModels(apiKeyID string) []*proxydb.Model

ClientModels lists enabled models the client can call, sorted by id for stable ListModels output.

func (*Snapshot) Configured

func (s *Snapshot) Configured() bool

Configured reports whether any routing config exists at all: models and either rules or competencies to select by.

func (*Snapshot) Selects added in v1.7.0

func (s *Snapshot) Selects() bool

Selects reports whether requests no rule matches are routed by selection: some enabled model declares competencies. Configs from before 1.7 never do, and keep needing a catch-all rule.

func (*Snapshot) SetAdapter

func (s *Snapshot) SetAdapter(apiKeyID, modelID string, adapter llm.ClientAdapter)

SetAdapter stores a mock adapter for tests.

func (*Snapshot) SetNodePool

func (s *Snapshot) SetNodePool(np NodePoolResolver)

func (*Snapshot) SpendLimit

func (s *Snapshot) SpendLimit(subjectType, subjectID, period string) int64

SpendLimit returns the cap in nano-USD for a subject and period, falling back to the subject type's "*" default; 0 means no cap.

func (*Snapshot) Tracker

func (s *Snapshot) Tracker() llm.UsageTracker

Tracker returns the usage tracker configured on the snapshot.

func (*Snapshot) UserRateLimit

func (s *Snapshot) UserRateLimit(userID, modelID string) *proxydb.UserRateLimit

UserRateLimit returns the rate limit override for a user and model, or for the user wildcard "*".

func (*Snapshot) VendorKey

func (s *Snapshot) VendorKey(apiKeyID, vendor string) (string, bool)

VendorKey returns the calling client's decrypted credential for a vendor.

func (*Snapshot) VendorKeyFingerprint added in v0.13.1

func (s *Snapshot) VendorKeyFingerprint(apiKeyID, vendor string) string

VendorKeyFingerprint names the client's credential for vendor without revealing it, so clients sharing one vendor key share its rate limits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL