config

package
v0.3.2-test-update Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 10 Imported by: ? 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

Overview

Package config loads context-guru's configuration and builds a pipeline from it. One strict YAML struct serves both hosts (design D9): the proxy loads a file; a sidecar plugin hands its config: subtree to LoadBytes; a k8s ConfigMap/CRD just renders the same YAML.

The pipeline: name-list controls order + enablement. Each component's own typed config lives under components:<name>; it's handed to the component's constructor verbatim, so adding a component makes it configurable with no change here. A preset expands to a default pipeline + component configs, which the explicit fields then override.

Index

Constants

View Source
const (
	DefaultKeepAliveIdle          = 280
	DefaultKeepAliveMaxPings      = 2
	DefaultKeepAliveMaxUSDPerPing = 0.25
	DefaultKeepAliveMinPrefix     = 20000
	DefaultHeadTTLMinTokens       = 50000
)

Keep-alive and head-TTL defaults. Named constants because the same numbers are asserted in tests and quoted in the settings page, and three copies of 280 is how one of them becomes 240.

View Source
const (
	DialectAnthropic = "anthropic"
	DialectOpenAI    = "openai"
	DialectBob       = "bob"
)

Dialects an upstream may declare.

Variables

This section is empty.

Functions

func ApplyForm added in v0.1.1

func ApplyForm(doc string, f Form) (string, error)

ApplyForm writes the form's fields into doc and returns the new document, validated.

Unknown keys survive: doc is decoded into a generic map, the declared keys are set on it, and the whole thing is re-marshalled. So a manager's `store:` block or a component the form does not know is still there afterwards, which the old string surgery only achieved for the one block it special-cased.

func PresetNames added in v0.1.1

func PresetNames() []string

PresetNames lists every registered preset, sorted. Served to the settings page so a user can only choose a preset the server will actually accept — a dropdown built from a hardcoded list in the UI is a dropdown that goes stale the moment a preset is added or removed.

func PresetPipeline

func PresetPipeline(name string) ([]string, bool)

PresetPipeline returns the default pipeline (ordered component names) for a named preset. It's the safe way to resolve a caller-supplied preset name (e.g. a /compact ?preset= query param) — a plain map lookup, no YAML parsing of untrusted input.

func RecommendedComponents added in v0.1.1

func RecommendedComponents() map[string]map[string]any

RecommendedComponents renders the recommended prefill as form values, keyed the way the form is: dotted paths inside a component's block. Served at /api/options so the page offers one recommendation from one place rather than a second copy of it in JavaScript.

func Validate added in v0.1.1

func Validate(b []byte) error

Validate reports whether a configuration document is usable, without keeping anything it builds. It is the full check, not just a parse: LoadBytes catches typos, an unknown preset and a bad mode, but only Build catches an unknown component name or a malformed per-component block. A hosted deployment saving a user-supplied config needs the strict answer at write time, so the failure is a 400 on their settings page rather than a surprise on their next agent turn.

Types

type CacheConfig added in v0.1.1

type CacheConfig struct {
	// KeepAlive turns on the idle keep-alive: for a session that has been idle
	// IdleSeconds, re-read its cached prefix once so the provider refreshes the TTL.
	//
	// Off by default and deliberately so. A ping is a real upstream request that costs
	// real money on the caller's own credential — small money (a cache read is 0.1x base
	// input where re-creating the prefix is 1.25x, so the saving:ping ratio is 11.5:1),
	// but money the caller did not ask to spend. That is a consent decision, not a
	// default.
	KeepAlive bool `yaml:"keepalive"`
	// KeepAliveIdleSeconds is X: how long a session must be idle before the first ping.
	// 0 = DefaultKeepAliveIdle (280).
	//
	// 280 rather than 240 is measured, not tuned by feel. The provider's default lifetime
	// is 5 minutes and "the lifetime is measured from the start of the request that writes
	// or reads the cache entry, not from the end of its response", so the budget is 300s
	// from the previous request's START. Simulated over the production window: X=240 wastes
	// 111 pings on gaps that would have hit anyway, X=280 wastes 53, and the net moves from
	// +$94.85 to +$125.08.
	KeepAliveIdleSeconds int `yaml:"keepalive_idle_seconds"`
	// KeepAliveMaxPings is K: the most pings one idle span may send. 0 =
	// DefaultKeepAliveMaxPings (2).
	//
	// K is the main control on the one waste this mechanism cannot avoid — a session that has
	// ENDED looks exactly like one that is thinking.
	//
	// 2 rather than 3, and NOT as a dollars-for-volume trade: the dollars are not real. K=3's
	// +$5.72 over the 4.47-day window is $1.28/day against a bootstrap CI of [$95, $237] and a
	// 1.4x split-half swing — statistically indistinguishable. What K=3 costs IS measurable:
	// +34% pings (1,226 against 912) onto a gateway path that returned 180 HTTP 429s in the same
	// window; the worst single session goes −$2.42 to −$3.63, 50% worse, with total losses +41%,
	// against a promise to save money and not raise anyone's bill while 85 of 119 pinged sessions
	// already lose; and the credential hold window grows 33%, 14 to 18.7 minutes.
	//
	// The decisive one: K=3's extra value comes from pings FURTHER from the last real request,
	// which is exactly where the ping-onto-a-dead-entry failure lives — the single mode that
	// inverts the feature from saving 11.5x to paying 12.5x.
	//
	// If K=3's dollars are ever wanted, the lever is the prefix floor rather than K:
	// KeepAliveMinPrefixTokens at 50,000 with K=2 gives +$125.12 on 908 pings — the same money
	// for fewer requests, a shorter hold, and no extra exposure to the dead-entry mode.
	KeepAliveMaxPings int `yaml:"keepalive_max_pings"`
	// KeepAliveMaxUSDPerPing refuses a ping whose projected cost exceeds this. 0 =
	// DefaultKeepAliveMaxUSDPerPing.
	//
	// PER PING and not per session, which is the opposite of the obvious design and is
	// measured. Ping cost is bimodal — p50 $0.0004, mean $0.0084, p99 $0.2275, max $0.3780 —
	// because 45.7% of pings fire on single-request sessions with ~1k-token prefixes, so the
	// variance to guard is between pings and not between sessions. A per-SESSION budget, by
	// contrast, truncates exactly the long large-prefix sessions that hold the value: capping
	// the window's pings per session at 20 drops the net from +$164 to $92.34, and at 10 to
	// $54.04. So the guard bounds the outlier ping and never the productive session.
	KeepAliveMaxUSDPerPing float64 `yaml:"keepalive_max_usd_per_ping"`
	// KeepAliveMinPrefixTokens is the billed-prefix floor a session must reach before it is
	// pinged at all, in the provider's own units (cache_read + cache_write of the previous
	// request). 0 = DefaultKeepAliveMinPrefix.
	//
	// This is the gate that makes the policy deployable rather than merely profitable.
	// Combined with skipping a session's FIRST request, it sends 9.8x fewer pings (912 against
	// 8,915 over the production window) for 1.7% less money, because what it drops is the
	// near-free pings on tiny prefixes. That matters twice over: those 8,000 requests are
	// real load on a gateway that already returned 180 HTTP 429s in the same window, and the
	// gate leaves 3,748 of 3,891 sessions untouched entirely — which is the fairness answer as
	// well as the efficiency one.
	KeepAliveMinPrefixTokens int `yaml:"keepalive_min_prefix_tokens"`

	// HeadTTL1h asks for the ONE-HOUR tier on the request's HEAD breakpoints (`tools` and
	// `system`) while leaving the trailing message breakpoint at 5 minutes — the provider's
	// documented mixed-TTL shape, in the order it requires (1h entries must precede 5m
	// ones, and the head precedes the messages by construction).
	//
	// Off by default for a measured reason, and NOT the one people expect. A blanket 1h TTL
	// loses money: the 2.0x write premium falls on every cache-creating request (14,499 of
	// them, −$773.00) while the benefit lands on 290 (+$754.66), net −$18.34. Re-labelling
	// only the head fixes that arithmetic — the premium is paid on 769 head-write events
	// instead — and simulates net positive at every head share, +$20.19 at f=0.10 to
	// +$60.56 at f=0.30.
	//
	// It is still off, because on the models that carry this service's spend the tier does not
	// arrive. Measured live, one request each with the head labelled 1h:
	// aws/claude-haiku-4-5 was GRANTED (ephemeral_1h_input_tokens 36,251 of 36,574 written),
	// aws/claude-sonnet-5 was silently downgraded (0 of 48,212, and an otherwise normal 200).
	// So the ttl field DOES reach the provider — Haiku honouring it proves that — and it is
	// Bedrock's model coverage that refuses: the Claude 4.5 family, not the Opus 5 / 4.8 /
	// Sonnet 5 this service runs. Zero 1h writes appear in 19,805 production requests, which is
	// the same fact from the billing side. So this ships implemented, verifiable and off:
	// Usage.CacheWrite1h is what says whether flipping it on did anything, and while that is
	// zero on a model the honest projection for it is $0.
	HeadTTL1h bool `yaml:"head_ttl_1h"`
	// HeadTTLMinTokens gates the 1h head on the request's own size. 0 =
	// DefaultHeadTTLMinTokens (50,000).
	//
	// A dollar filter, not a probability filter, and that distinction is the whole result.
	// Gating 1h on the best available predictor of a long gap leaves the net unchanged
	// (−$18.32 against −$18.34 blanket) because the premium and the benefit scale with the
	// SAME cache_write on the same requests, so multiplying both by a probability cannot
	// flip the sign. Gating on size does flip it (+$48.81): it excludes small-prefix
	// requests that pay the premium and can never produce a large miss.
	HeadTTLMinTokens int `yaml:"head_ttl_min_tokens"`
}

CacheConfig is the `cache:` block: provider prompt-cache policy that lives above the pipeline.

It is not a component and could not be. A component runs while a request is in flight, and the expensive event here happens when NO request is in flight — a session goes idle, its cached prefix lapses, and the next turn re-bills the whole prefix at the creation rate. Measured on this service over 19,805 requests: 742 such requests (3.7% of traffic) cost $741.07, which is 23.6% of all spend, at $0.9987 each against $0.1178 for a request that hit — an 8.5x penalty. $584.83 of it sits in misses whose idle gap was under an hour.

Every field is off or zero by default. KeepAlive spends the caller's money without the caller asking, so it is opt-in per account, capped, and reported per ping.

func (CacheConfig) Resolved added in v0.1.1

func (c CacheConfig) Resolved() CacheConfig

Resolved returns the block with every zero replaced by its default, so callers never repeat the fallbacks. Disabled flags are left alone: `enabled: false` with a tuned interval is a legitimate parked configuration.

type CacheForm added in v0.1.1

type CacheForm struct {
	KeepAlive                bool    `json:"keepalive"`
	KeepAliveIdleSeconds     int     `json:"keepalive_idle_seconds,omitempty"`
	KeepAliveMaxPings        int     `json:"keepalive_max_pings,omitempty"`
	KeepAliveMaxUSDPerPing   float64 `json:"keepalive_max_usd_per_ping,omitempty"`
	KeepAliveMinPrefixTokens int     `json:"keepalive_min_prefix_tokens,omitempty"`
	HeadTTL1h                bool    `json:"head_ttl_1h"`
	HeadTTLMinTokens         int     `json:"head_ttl_min_tokens,omitempty"`
}

CacheForm is the settings page's view of the `cache:` block.

type Config

type Config struct {
	Preset     string               `yaml:"preset"`
	Pipeline   []string             `yaml:"pipeline"`
	Components map[string]yaml.Node `yaml:"components"`
	Store      store.Options        `yaml:"store"`
	// Mode is the operating mode: sync (default) | observe. See #31 and
	// docs/how-to/operating-modes.md. Empty = sync, which is byte-identical to the
	// behavior before modes existed.
	Mode string `yaml:"mode"`
	// Observe tunes observe mode's off-path measurement; ignored in sync mode.
	Observe ObserveConfig `yaml:"observe"`
	// Cache holds the provider prompt-cache policies the HOST applies between and
	// around requests, which no component can reach: keeping an idle session's cached
	// prefix alive, and which TTL tier its breakpoints ask for. Both default to off.
	Cache CacheConfig `yaml:"cache"`
}

Config is the whole configuration document.

func Load

func Load(path string) (*Config, error)

Load reads and parses a YAML config file (strict: unknown keys are rejected).

func LoadBytes

func LoadBytes(b []byte) (*Config, error)

LoadBytes parses a YAML config document (strict). Used by a sidecar plugin's Configure, which receives its subtree as bytes.

func (*Config) Build

Build constructs the ordered pipeline from the config, wiring each named component with its raw config block.

func (*Config) NewStore

func (c *Config) NewStore() store.Store

NewStore builds the configured state store: an in-memory TTL+LRU by default, or a no-op store when store.enabled is false (disables offload reversibility).

func (*Config) OperatingMode added in v0.1.1

func (c *Config) OperatingMode() (components.Mode, error)

OperatingMode validates and returns the configured mode.

type ExtractLLMForm added in v0.1.1

type ExtractLLMForm struct {
	// ColdEnabled asks for the cold sweep, which is now a SEPARATE component
	// (extract_llm_sweep) rather than a key inside this one. It therefore means "put that
	// component in the pipeline", and the fields below that describe it (ColdMinTokens) are
	// written into its block, not into extract_llm's.
	//
	// There is no PerOutput any more: extract_llm IS the warm/tail pass, so the only way to
	// switch it off is to take it out of the pipeline, which is what every other component's
	// checkbox already means. That removes the one per-component exception this form carried.
	ColdEnabled bool `json:"cold_enabled"`
	// SizeTrigger picks fire_on: size over the default pressure trigger. Named for what
	// the operator is choosing, not for the YAML value, because it also demotes the
	// economic gate to advisory and the UI has to say so.
	SizeTrigger     bool   `json:"size_trigger"`
	MinTokens       int    `json:"min_tokens"`
	MaxPerRequest   int    `json:"max_per_request"`
	MaxPerSession   int    `json:"max_per_session"`
	Aggressiveness  string `json:"aggressiveness"`
	Context         string `json:"context"`
	ContextMessages int    `json:"context_messages"`
	ColdMinTokens   int    `json:"cold_min_tokens"`

	// The three below decide whether the component can act AT ALL. Every one of them was,
	// on a real account, silently the reason a fully configured extract_llm did nothing:
	//
	//	AllowOnCachingBackend — unset means FALSE, and the economic gate then hard-declines
	//	  every candidate whose tokens are prompt-cached. On Claude Code against Anthropic
	//	  that is the whole workload, so the component ran 251 times and acted 0 times.
	//	ModelSource — "config" selects an operator-configured compaction model, and the
	//	  hosted service HAS none (it would be spending the operator's credential on a
	//	  tenant's traffic). So "config" there means "no model", i.e. never call anything.
	//	  "incoming" uses the caller's own model and key, which is what a tenant wants.
	//	Strategy / EveryNRequests / TriggerMinTokens — already in real stored documents.
	AllowOnCachingBackend bool   `json:"allow_on_caching_backend"`
	ModelSource           string `json:"model_source"`
	// ModelName is the model to COMPACT with, on the source's endpoint and credential.
	// Empty means "whatever the source's own model is", which for `incoming` is the agent's
	// frontier model — and compaction on one does not pay: a measured cold-cache sweep cut
	// the provider bill by $0.63 and spent $1.25 of opus doing it. This field is how the
	// same work runs on a cheap model without the operator paying for it.
	ModelName        string `json:"model_name"`
	Strategy         string `json:"strategy"`
	EveryNRequests   int    `json:"every_n_requests"`
	TriggerMinTokens int    `json:"trigger_min_tokens"`
}

ExtractLLMForm is the RECOMMENDED prefill for the compaction-model component — a policy layer, deliberately not the same thing as the component's own defaults.

components.Field.Default answers "what does an absent key mean?" (min_tokens 300, cold cache off). This answers "what should the settings page offer somebody switching the component on for the first time?", which is a different question with a different source: our own measurements. Conflating the two is how a form ends up writing its opinion over an operator's deliberate value.

func DefaultExtractLLMForm added in v0.1.1

func DefaultExtractLLMForm() ExtractLLMForm

DefaultExtractLLMForm is what the settings page pre-fills. The sweep on, the hot path off: the cold turn is the regime where our own measurements say a model call pays, and the per-output pass on a warm cache is the one they say loses.

These are housellm's values, and as of the cold-floor change they no longer deviate from it anywhere — including AllowOnCachingBackend, which this function has always returned false and which the preset now also omits. housellm is the one extract_llm configuration this service has actually run and measured, so the form offers what production runs.

extract_llm's warm/tail path genuinely pays here, which is why it is offered at all: savedTokenValueAt prices a candidate by position, so a tail candidate is valued at the cache-WRITE rate rather than the request-level cache-READ rate.

MinTokens 8000 is what makes that safe, and it is derived from measurement rather than picked: a call costs ~$0.0193 per ACCEPTED result (output-dominated, and including the 1-in-5 that is rejected outright), which needs 4,060 saved tokens at the cache-write rate, which at the observed ~65% reduction needs a ~6,250-token candidate. At MinTokens 1000 the same real sessions lost $0.036 — every call allowed by the exploration budget rather than by the arithmetic. Lower this and the form starts recommending a measured loss.

AllowOnCachingBackend stays false and is vestigial either way: the check it lifts no longer fires on a warm turn (the tail is not cached; depth is refused by the tail gate first).

ColdMinTokens 1000 is the value that decides whether the compaction-model pass does anything at all on this service: every extraction call production has ever made was a cold one, and at 3000 the sweep refused every candidate it saw (below_output_floor on all 36 sweeping turns, 0 extractions across 3,437 requests). It is written into extract_llm_sweep's own min_tokens now. That component's max_calls is still not modelled here, so an account prefilled from this form gets its default of one concurrency round.

MaxPerSession 0 is read by extract_llm as UNLIMITED — an operator decision, and a live one: with the sweep split out, extract_llm has only the hot arm and it reads this on every turn it fires. What bounds a long session in practice is eligibility rather than this cap: 132 calls across three days of heavy use, under a per-session cap of 40 that was never approached.

type Form added in v0.1.1

type Form struct {
	// Pipeline is the component run order, resolved: for a `preset:` document it is what
	// the preset expands to, not the empty list the text literally contains. It is also
	// the ONLY statement of what is enabled — see R2 in the docs: a block is configuration,
	// not enablement, and reading "no block" as "off" silently removed components from
	// bare-preset accounts on save.
	Pipeline []string `json:"pipeline"`
	// PipelineKnown lists the component names the CLIENT rendered a control for. Any name in
	// the STORED pipeline that is not in this list is preserved at its original index,
	// whatever Pipeline says — so removing a component is an act a client has to CLAIM, and a
	// client that cannot see one cannot take it out.
	//
	// It exists because a save silently reverted an operator's pipeline: `linecap` was
	// dropped and `toon` re-added. The server never knew either name — the pipeline is a
	// wholesale write of whatever the browser rebuilt out of its checkbox grid — so a stale
	// render or a cached bundle whose /api/options predated a component produces exactly that
	// diff, and the server had no way to tell it from a deliberate removal. Now it does.
	//
	// Empty or absent means "this client declared nothing", and then NOTHING may be removed.
	// That is the safe direction for an old bundle and for a hand-rolled API client: both can
	// still add and reorder.
	PipelineKnown []string `json:"pipeline_known,omitempty"`
	// PipelineBase is the pipeline the page RENDERED from. A mismatch against the stored
	// document means the document moved under the page, and the save is refused with a 409 —
	// which is what stops a stale page ADDING a component back. Preserving the unmodelled
	// only defends against dropping.
	//
	// nil is accepted (an older bundle does not send it) and then PipelineKnown is the only
	// defence, which is again the safe direction. Checked at the HTTP layer, where the stored
	// document is: see proxy.Handler.ctlUpdateMe.
	PipelineBase []string `json:"pipeline_base,omitempty"`
	Mode         string   `json:"mode"`
	// Cache is the `cache:` block — host-level prompt-cache policy (the idle keep-alive and
	// the mixed-TTL head), which is not a component and so has no descriptor to be drawn
	// from. nil means the form does not state it and ApplyForm leaves the document's own
	// block alone, exactly as an absent component block does.
	//
	// A pointer rather than a value for that reason alone: `keepalive: false` and "this form
	// has nothing to say about the cache" are different instructions, and with a value type
	// every save from a page that had not drawn the control would switch a tenant's
	// keep-alive off.
	//
	// Reachable only from a direct Go or API caller, in practice. ParseForm's strict path
	// always fills it in (cacheForm is unconditional), and its loose path leaves it nil but
	// also sets ParseError — which the save route answers with a 409 before ApplyForm is ever
	// called. So the nil branch in ApplyForm is a contract for library callers, not a state
	// the settings page can produce.
	Cache *CacheForm `json:"cache,omitempty"`
	// Components holds, per component name, the DOTTED key paths that component's block
	// actually states — `{"extract_llm": {"trigger.min_request_tokens": 800}}`. Only keys the
	// document really carries are present: an absent key means "the component's default",
	// which is a different thing from a value, and prefilling defaults here is how a save
	// wrote 20 over a deliberate `llm_max_per_session: 0` (R3).
	//
	// A component missing from this map is not touched by ApplyForm at all.
	Components map[string]map[string]any `json:"components"`
	// ParseError is set when the stored document did not load strictly and these fields
	// came from a best-effort read of it. The settings page must say so and refuse to
	// save: a save from a misread form would post whatever the fallback managed to see,
	// and with the YAML box gone there is no other way to correct the document from the
	// page. Fixing it needs the account editor, which still takes a document.
	ParseError string `json:"parse_error,omitempty"`
}

Form is the dashboard's configuration as FIELDS rather than as YAML text, in both directions: ParseForm reads a document into it for rendering, ApplyForm writes it back into one on save.

It exists because the browser used to do this with regular expressions, and that was not a stylistic problem, it was a data-loss bug. The save path replaced the whole `pipeline:` line with a flow-style one, so a document whose pipeline was written as a YAML block sequence

pipeline:
  - format
  - extract

became

pipeline: [format, extract_llm]
  - format
  - extract

which is `config: yaml: line 3: did not find expected key` — the error two accounts hit on every single save, unrecoverable from the UI because the refusal left the stored document in place for the next attempt to mangle again. A `preset:` document lost its whole pipeline the same way, silently, because the regex found no flow-style line to read the existing names out of.

A real YAML library on the server cannot make that class of mistake, and the round trip preserves every key the form does not know about. What it does NOT preserve is comments and key order: a Go map has neither. That is the deliberate trade — the settings page is fields now, so nothing in the document is hand-written prose any more.

Why it is descriptor-driven

The first version hand-wrote one Go struct field, one YAML key and one JavaScript control per knob. It reached 18 keys of about a hundred, one component of fifteen, and it had already drifted in both directions: the browser's default table duplicated the server's, and the strategy list was missing a value the engine accepts (see R8 in docs/how-to/settings-form.md). So the fields are now DECLARED beside the config struct they describe — components.Field — and everything here is a walk over those declarations. Adding a knob to a component adds it to the form, and forgetting to is a test failure.

func ParseForm added in v0.1.1

func ParseForm(doc string) (Form, error)

ParseForm reads a configuration document into form fields.

Best-effort by design: it is what the settings page renders from, and a document it cannot fully understand must still draw a usable form. So it tries the strict loader first (which resolves presets, the whole reason to bother) and falls back to a loose decode of the same shape, recording why (R1).

type ObserveConfig added in v0.1.1

type ObserveConfig struct {
	// MaxQueue bounds the off-path measurement queue (0 = 256). A full queue drops,
	// counted, and never blocks the request path.
	MaxQueue int `yaml:"max_queue"`
	// Workers is the number of drain goroutines (0 = 1).
	Workers int `yaml:"workers"`
}

ObserveConfig is the `observe:` block.

type Upstream added in v0.1.1

type Upstream struct {
	Name    string `yaml:"name"`
	Dialect string `yaml:"dialect"` // anthropic | openai | bob
	BaseURL string `yaml:"base_url"`
	// KeyEnv optionally names an environment variable holding a SERVER-HELD
	// credential for this upstream. Leave it empty — the default — and the caller's
	// own provider key is forwarded instead, so each user's traffic is billed to their
	// own account. Set it only for a gateway deployment where the agent holds a
	// placeholder key (eval containers, local single-tenant).
	//
	// The key itself is never in this file, never in the database, and never in a
	// tenant's configuration — it is read from the environment at request time, so a
	// leaked config or a database dump contains no usable secret.
	KeyEnv string `yaml:"key_env"`
	// Header is the request header the key is injected into. Empty defaults per
	// dialect: x-api-key for anthropic, Authorization: Bearer for openai and bob.
	Header string `yaml:"header"`
}

Upstream is one entry in the server's allow-list of places traffic may be forwarded to. A hosted proxy lets tenants CHOOSE an upstream by name; it must never let them supply a URL, because that turns the service into an unauthenticated request-forwarder for anything its network can reach. Names in, URLs owned by the operator.

func LoadUpstreams added in v0.1.1

func LoadUpstreams(path string) ([]Upstream, error)

LoadUpstreams reads and validates the server's upstream allow-list.

Validation is strict and happens at BOOT, not at first request. key_env is OPTIONAL: an upstream without one forwards the caller's own provider credential, which is the hosted default. When one IS named it must be present in the environment, because a gateway deployment that silently lost its key would forward a placeholder and fail every request in a way nobody can read.

Jump to

Keyboard shortcuts

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