Documentation
¶
Overview ¶
Package proxy serves remora's /v1 surface in front of the inference engine.
Index ¶
- Constants
- Variables
- func Allowed(patterns []string, model string) bool
- func CodexDroppedParams(path string, body []byte) []string
- func ExtractModel(r *http.Request) (model string, body io.ReadCloser, err error)
- func RedactEngineLogs(next slog.Handler, redact func(string) string) slog.Handler
- func Scrub(b []byte) []byte
- func TranslateModelError(message, target string) string
- type Picker
- type Proxy
- type ResponseHook
Constants ¶
const MaxBodyBytes = 100 << 20
MaxBodyBytes is the largest request body remora accepts; it is the front door's own cap.
Variables ¶
var ( // ErrNoModel means the request names no usable model. ErrNoModel = errors.New("proxy: no model in request") // ErrClientFallbacks means the client sent its own fallbacks, which would route past the allowlist. ErrClientFallbacks = errors.New("proxy: fallbacks field is not supported") // ErrBodyTooLarge means the request body is larger than MaxBodyBytes. ErrBodyTooLarge = errors.New("proxy: request body too large") )
Functions ¶
func Allowed ¶
Allowed reports whether model, as the client wrote it (an alias name or "<provider>/<model>"), matches one of a key's allowlist patterns. The pattern "*" matches every name, a pattern ending in "/*" matches any depth below its prefix ("openrouter/*" matches "openrouter/qwen/qwen3-embedding"), and every other pattern follows path.Match. Matching is byte for byte and case-sensitive; a malformed pattern never matches, and no patterns deny everything.
func CodexDroppedParams ¶
CodexDroppedParams returns the top-level keys of a client's body at path that the OAuth engine's Codex translator drops or overrides, sorted and deduplicated. It returns nil when there are none, when path is not a Codex-translated route, or when body is not a JSON object. The rules are checked against the engine on every engine bump (internal/engine/cliproxyapi/contract_test.go).
func ExtractModel ¶
ExtractModel reads the request body (up to MaxBodyBytes), finds the model the client asked for, and returns a reader over exactly the bytes it read. The model comes from a multipart/form-data field named "model" or from the top-level JSON object. A top-level "fallbacks" key is rejected: the engine would honour it and route past the allowlist. The request itself, its headers included, is not changed; on error the returned body is nil.
func RedactEngineLogs ¶ added in v0.7.0
RedactEngineLogs scrubs engine output before the handler encodes it, so keys containing JSON metacharacters are matched as text without changing the log format.
func Scrub ¶
Scrub returns b with engine names replaced by remora's and engine keys redacted, for any text an operator or client reads (the CLI uses it on its error output).
func TranslateModelError ¶ added in v0.7.0
TranslateModelError replaces the front door's model-list denial using a user-facing provider/model target.
Types ¶
type Picker ¶ added in v0.3.0
type Picker struct {
// contains filtered or unexported fields
}
Picker picks the member a spreading alias's request tries first, from the live chains the reconciler publishes and the starts of the last minute. It is safe for concurrent use.
func NewPicker ¶ added in v0.3.0
NewPicker returns a Picker; nil now and intn mean time.Now and rand.IntN.
func (*Picker) Pick ¶ added in v0.3.0
Pick returns the member ref to send as X-Remora-First for aliasName, or "" when it has no published chain. Ties go to the lower index (declared order).
type Proxy ¶
type Proxy struct {
// Ready, when set, reports whether the front door holds the store's state; until it does, /v1 answers 503
// instead of meeting missing or stale providers, rules or keys. serve sets it to the reconciler's Synced.
Ready func() bool
// Picker, when set, picks the first member of a spreading alias's request (X-Remora-First).
Picker *Picker
// Cooler, when set, admits half-open probes. MaxAliasDepth matches the reconciler.
// shortcut: Half-open probes are HTTP only; WebSocket sessions use the precompiled chain. Add per-frame admission if they need to probe.
Cooler *cooling.Cooler
MaxAliasDepth int
// contains filtered or unexported fields
}
Proxy serves remora's /v1 surface: it authenticates the remora key, checks the model against the key's allowlist, swaps in the key's front-door virtual key and streams the front door's answer back unbuffered, rewriting only headers and error envelopes so no engine detail reaches a client.
func New ¶
New returns a Proxy in front of the front door at upstream (its inference routes), reading keys and aliases from st. Mount it at /v1/. The /v1 server must not set a WriteTimeout: streams and transcriptions run long.
func (*Proxy) OnResponse ¶
func (p *Proxy) OnResponse(h ResponseHook)
OnResponse adds a hook that runs on every proxied response, in the order added.
type ResponseHook ¶
ResponseHook sees every proxied response in ModifyResponse, after remora's own x-remora-* headers are set and before the first byte is written, so it may rewrite those headers. r is the client's request; reqBody is the exact body ExtractModel held (nil on the WebSocket route). Plan 03 uses it for served-by names of internal providers; x-remora-dropped-params is set after every hook has run, from the served-by they leave.
func ServedByHook ¶
func ServedByHook(rename func(provider, model string) string) ResponseHook
ServedByHook returns a response hook that rewrites x-remora-served-by, which the proxy sets to "<front-door provider>/<model>", to rename(provider, model). serve passes the OAuth engine's mapping, which turns "remora-oauth/codex/gpt-x" into "codex/gpt-x" so the internal provider never reaches a client. x-remora-dropped-params runs after every hook, so it sees the renamed value.