Documentation
¶
Overview ¶
Package proxy serves remora's /v1 surface in front of the inference engine.
Index ¶
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.
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 ¶
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.