proxy

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 32 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

Overview

Package proxy serves remora's /v1 surface in front of the inference engine.

Index

Constants

View Source
const MaxBodyBytes = 100 << 20

MaxBodyBytes is the largest request body remora accepts; it is the front door's own cap.

Variables

View Source
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

func Allowed(patterns []string, model string) bool

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

func CodexDroppedParams(path string, body []byte) []string

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

func ExtractModel(r *http.Request) (model string, body io.ReadCloser, err error)

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

func RedactEngineLogs(next slog.Handler, redact func(string) string) slog.Handler

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

func Scrub(b []byte) []byte

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

func TranslateModelError(message, target string) string

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

func NewPicker(now func() time.Time, intn func(n int) int) *Picker

NewPicker returns a Picker; nil now and intn mean time.Now and rand.IntN.

func (*Picker) Pick added in v0.3.0

func (p *Picker) Pick(aliasName string) string

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).

func (*Picker) SetChains added in v0.3.0

func (p *Picker) SetChains(chains map[string]alias.Chain)

SetChains replaces every published chain; the reconciler calls it after each committed pass.

func (*Picker) Started added in v0.3.0

func (p *Picker) Started(servedBy string)

Started records a start against the member that served the request (x-remora-served-by), so a fallback counts where it landed. "" is ignored.

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

func New(upstream *url.URL, st *store.Store, log *slog.Logger) *Proxy

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.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves one /v1 request.

type ResponseHook

type ResponseHook func(r *http.Request, reqBody []byte, resp *http.Response)

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.

Jump to

Keyboard shortcuts

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