Skip to main content

ProxyConfig

Struct ProxyConfig 

Source
pub struct ProxyConfig {
    pub anthropic_upstream: Option<String>,
    pub openai_upstream: Option<String>,
    pub gemini_upstream: Option<String>,
    pub history_mode: Option<String>,
    pub allow_insecure_http_upstream: Option<bool>,
    pub meter_openai_usage: Option<bool>,
    pub cold_prefix_repack: Option<bool>,
    pub role_aggressiveness: RoleAggressiveness,
    pub live_compress: Option<bool>,
    pub live_compress_exclude: Option<Vec<String>>,
    pub ccr_inband: Option<bool>,
    pub effort: Option<String>,
}
Expand description

API proxy upstream overrides. None = use provider default.

Fields§

§anthropic_upstream: Option<String>§openai_upstream: Option<String>§gemini_upstream: Option<String>§history_mode: Option<String>

History-pruning strategy for proxied chat requests. “cache-aware” (default) | “rolling” | “off”. See HistoryMode.

§allow_insecure_http_upstream: Option<bool>

Allow a non-loopback plaintext http:// upstream (trusted local network only). Opt-in; see ProxyConfig::allows_insecure_http_upstream. (#440)

§meter_openai_usage: Option<bool>

Inject stream_options.include_usage = true into streamed OpenAI Chat Completions so the final chunk reports real token usage for the measured spend meter. Default on; set false for a client that mishandles the trailing usage chunk. Anthropic/Gemini/OpenAI-Responses report usage without any request change, so this only affects Chat Completions.

§cold_prefix_repack: Option<bool>

Opt-in “big-gap cold-prefix repack” (#480). When the proxy can confidently predict (from idle time vs the provider cache TTL) that the client-cached prefix has already expired, it overrides the normal “never rewrite the cached prefix” rule for that one resume request and prunes the now-cold prefix too, re-seeding a leaner cache. None/false (the default) keeps the prefix always protected. See ProxyConfig::repacks_cold_prefix.

§role_aggressiveness: RoleAggressiveness

Opt-in per-role prose compression for the proxy’s frozen request region (#710). None for a role (the default) leaves that role untouched — today’s behaviour. See RoleAggressiveness.

§live_compress: Option<bool>

Live tool-result compression on the wire (#481). true (the default) keeps today’s behaviour: the proxy compresses non-protected tool_result content on every request. false turns it off so the proxy can run meter-only — real billed/cache token metering with zero request rewriting (combine with history_mode = "off" and no role_aggressiveness for a fully byte-unchanged body). Env LEAN_CTX_PROXY_LIVE_COMPRESS. See ProxyConfig::live_compresses.

§live_compress_exclude: Option<Vec<String>>

Per-tool exclusion list for live tool-result compression (#481). Tool names are matched case-insensitively as substrings (the same style as crate::proxy::tool_kind::classify_tool_name); a match is treated as protected, exactly like a file read. None (the default) protects Serena’s code-reading tools (find_symbol/find_referencing_symbols/ search_for_pattern return source bodies the model edits, but are mis-bucketed as Search by name). Set an explicit list to narrow it, or [] to disable the exclusion. See ProxyConfig::is_tool_live_compress_excluded.

§ccr_inband: Option<bool>

Opt-in in-band CCR retrieval for a remote proxy with no shared filesystem (#493, follow-up to #482). When enabled, a lossy stub advertises a compact <lc_expand:HASH> marker (instead of a local tee path the remote agent can’t read); when the model echoes that marker back, the proxy splices the verbatim original — recovered from its local tee store — inline on the next request, costing one turn of latency and needing no MCP/FS on the agent host. None/false (the default) keeps the path-handle stub. The splice is a strict no-op on marker-less turns, so it never perturbs the provider cache prefix unless the model explicitly asked to expand. See ProxyConfig::ccr_inband_enabled.

§effort: Option<String>

Cache-safe, cross-provider reasoning-effort control (#834). One of minimal|low|medium|high pins the model’s reasoning depth across every provider; None/"off" (the default) is a strict no-op. The value is a constant — identical on every request — so the provider prompt-cache prefix stays byte-stable (#448/#498) and only the model’s reasoning depth changes. lean-ctx translates it to each provider’s native parameter and only ever fills it (never overrides a client-set value), on models that accept it. Per-turn effort switching is deliberately unsupported — it would invalidate the prompt cache. Env LEAN_CTX_PROXY_EFFORT. See ProxyConfig::resolved_effort.

Implementations§

Source§

impl ProxyConfig

Source

pub fn resolved_history_mode(&self) -> HistoryMode

Resolved history mode: LEAN_CTX_PROXY_HISTORY_MODE env var wins, then [proxy].history_mode in config.toml, then cache-aware. Unknown values fall back to the default so a typo can never silently re-enable the cache-hostile rolling mode.

Source

pub fn meters_openai_usage(&self) -> bool

Whether the proxy injects stream_options.include_usage into streamed OpenAI Chat Completions to meter real spend. [proxy] meter_openai_usage in config.toml, default true.

Source

pub fn repacks_cold_prefix(&self) -> bool

Whether the opt-in cold-prefix repack (#480) is enabled. A wrong “cold” guess re-bills cache reads as writes (~12x), so this is off by default and must be explicitly enabled. LEAN_CTX_PROXY_COLD_PREFIX_REPACK (any value) wins, then [proxy] cold_prefix_repack in config.toml, else false.

Source

pub fn ccr_inband_enabled(&self) -> bool

Whether opt-in in-band CCR retrieval (#493) is enabled. Off by default: the splice mutates provider-visible conversation content for the one turn the model asks to expand, so it must be an explicit opt-in. LEAN_CTX_PROXY_CCR_INBAND (any value) wins, then [proxy] ccr_inband in config.toml, else false.

Source

pub fn resolved_effort(&self) -> Option<Effort>

Resolved cross-provider reasoning effort (#834), or None when the feature is off (the default — a strict no-op that preserves the byte-unchanged meter-only path). Precedence: LEAN_CTX_PROXY_EFFORT env (off disables, a valid level wins, an unparseable/blank value is ignored) > [proxy] effort in config.toml. Any unknown value resolves to None so a typo can never silently enable reasoning steering.

Source

pub fn live_compresses(&self) -> bool

Whether the proxy live-compresses non-protected tool_result content (#481). LEAN_CTX_PROXY_LIVE_COMPRESS (0/false/off/no → off, 1/true/on/yes → on) wins, then [proxy] live_compress in config.toml, else true. An unparseable/blank env value is ignored so a typo can never silently flip the mode.

Source

pub fn live_compress_exclude_patterns(&self) -> Vec<String>

Resolved per-tool live-compress exclusion patterns (#481). None in config falls back to the built-in default (protect Serena); an explicit list — including the empty list — is used verbatim so operators can narrow or fully clear it.

Source

pub fn is_tool_live_compress_excluded(&self, tool_name: &str) -> bool

Whether tool_name is on the live-compress exclusion list (#481) and must therefore reach the model intact, like a protected file read. Matching is case-insensitive substring, mirroring tool_kind::classify_tool_name.

Source

pub fn resolved_role_aggressiveness(&self, role: ProseRole) -> Option<f64>

Resolved prose-compression aggressiveness for role, clamped to [0,1], or None when prose compression is off for that role (the default).

Precedence: the role’s env override (LEAN_CTX_PROXY_SYSTEM_AGGR / LEAN_CTX_PROXY_USER_AGGR) wins, then [proxy.role_aggressiveness] in config.toml. An unparseable or blank env value is ignored so a typo can never silently disable the configured behaviour.

Source

pub fn allows_insecure_http_upstream(&self) -> bool

Whether a non-loopback plaintext http:// upstream is allowed. Opt-in only — a deliberate downgrade for a trusted local-network service such as http://host.docker.internal:2455 in front of codex-lb (#440). LEAN_CTX_ALLOW_INSECURE_HTTP_UPSTREAM (any value) wins, then [proxy] allow_insecure_http_upstream in config.toml, default false.

Source

pub fn resolve_upstream(&self, provider: ProxyProvider) -> String

Effective upstream for a provider (env > config > default). An invalid configured/env value falls back to the provider default (logged) — the safe choice at startup.

Source

pub fn resolve_all(&self) -> Upstreams

Resolve all three upstreams at once (startup snapshot, env-aware).

Source

pub fn resolve_all_disk(&self) -> Upstreams

Resolve all upstreams from config.toml only (ignoring LEAN_CTX_* env) — the values a freshly (re)started managed proxy would serve. Used by status/doctor to detect drift from a running proxy’s live upstream (#449).

Source

pub fn refresh_upstreams(&self, last: &Upstreams) -> Upstreams

Re-resolve upstreams for a running proxy (#449). For any provider whose currently configured/env value fails validation, the last good value is kept instead of rerouting live traffic to the provider default — so a typo in config.toml can never silently redirect in-flight requests.

Trait Implementations§

Source§

impl Clone for ProxyConfig

Source§

fn clone(&self) -> ProxyConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProxyConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProxyConfig

Source§

fn default() -> ProxyConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ProxyConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ProxyConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more