Expand description
The LeanCTX model-API proxy, above the Engine library (lean_ctx): an
edit here re-checks this crate and the binary, not the Engine.
LLM reverse proxy — the core of the Gateway pillar.
Intercepts Anthropic, OpenAI, Gemini and ChatGPT traffic, compresses prompts, meters usage, and optionally translates request shapes.
§TLS Requirements
The proxy does NOT terminate TLS. For production/multi-tenant deployments, place behind a TLS-terminating reverse proxy (nginx, caddy, traefik). For mTLS, configure the reverse proxy with client certificates. See: https://github.com/yvgude/lean-ctx/issues/1371
§Org gateway coupling (ADR-023)
The self-hosted org gateway (lean-ctx-enterprise) extends this proxy with admin/usage-store routes. In the OSS build the proxy runs standalone.
Modules§
- auto_
routing - Legacy
model=autowire types, kept for compatibility only. - break_
even - cache_
aligner - Cache-aligner (#940 detect, #974 relocate) — Headroom “cache aligner” port.
- cache_
attribution - Prompt-cache miss attribution (#986, cache-economics telemetry).
- cache_
policy - Net-cost policy for cache-busting rewrites (#986, cache-economics).
- cache_
safety - Cache-preservation telemetry for the proxy’s frozen-region prose rewrites (#710).
- cache_
share - Cache-share guard: per provider+model cost log, rolling cache-read share, alarm below the threshold, and the provider allowlist for open models.
- ccr
- In-band CCR on the proxy wire (#493):
<lc_expand:HASH>markers a model echoed are spliced back into the request body before it leaves. - circuit_
breaker - Public deterministic circuit-breaker reference.
- cold_
prefix - Big-gap cold-prefix repack prediction (#480).
- compress
- compress_
api POST /v1/compress— deterministic messages-in / messages-out compression.- compress_
shared - Provider-neutral classification for content blocks compressed in place.
- compression_
savings - Input-compression savings from the
[proxy] compression_holdout(#1905). - cost
- Per-model proxy savings accounting.
- counterfactual
- Counterfactual savings metering (#701) — provider-authoritative receipts.
- dedup
- Request-local, lossless deduplication of repeated tool output.
- determinism_
guard - Formal, verifiable prompt-cache safety for proxy request rewrites.
- effort
- Cache-safe, cross-provider reasoning-effort control (#834).
- eligibility
- Static eligibility evaluation for the public proxy boundary.
- history_
prune - holdout
- Deterministic output-savings holdout (#895 Track B).
- introspect
- live_
zone - Live-zone-aware request compression preserves provider-cached prefixes.
- output_
savings - Output-token savings reporting (#895 Track B).
- pii
- Person pseudonymization (enterprise#39, GDPR/DSGVO).
- pipeline_
bench - End-to-end, deterministic workloads for the proxy compression pipeline.
- pre_
optimize - prefix_
cache_ stats - Structured prefix-cache statistics for the
/statusendpoint. - prefix_
replay - Append-only delta detection and forwarded-byte replay for provider prefix cache stability.
- prose
- Frozen-region prose compression for the proxy (#710).
- prose_
compress - Markdown-aware normalization and task-relevance filtering.
- prose_
patterns - Deterministic, loss-conscious compression for repetitive prose.
- prose_
ranker - Cache-safe wire prose squeeze (#895).
- rollout
- Public rollout cohort schema and deterministic assignment reference.
- routing
- Explicit model targets — operator-written aliases in the forward path.
- session_
elide - Long-session elision for Anthropic Messages requests.
- sticky_
tools - Sticky CCR tool injection for provider prefix-cache stability.
- tool_
kind - Classifies what produced a
tool_resultso the proxy never lossy-compresses a file/source-code read the model still needs (e.g. mid-refactor). - usage
- Real provider-reported token usage extraction.
- usage_
meter - Measured per-model spend meter.
- usage_
parity - Proxy-to-kernel provider and usage conversion.
- usage_
sink - Process-wide usage event sink (enterprise#17).
- verbosity
- Cache-safe wire verbosity steer (#895 Track B).
Functions§
- register_
shapers - Hand the proxy’s output shaping to the engine’s
ctx_shapetool. The CLI calls this at start-up; the first registration wins.