proxy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 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

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

Types

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