registry

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 27 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 (
	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 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 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 DeepSeekDefaultEndpoint = "https://api.deepseek.com"

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

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 TypeSafeDefaultEndpoint = "https://api.typesafe.ai"

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

Variables

This section is empty.

Functions

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 HasCapability

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

HasCapability reports whether a model lists the capability.

func Serves

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

Serves reports whether a model lists the effort.

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 takes 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 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 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 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
	// 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.

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