The token and cache proxies’ central flow: a /v1/chat/completions response comes back from upstream, and compress_chat_completion classifies each message.content, applies an EMA-tuned per-type threshold (scaled by the x-headroom-budget header), BLAKE3-hashes over-threshold content, stores it, and replaces the text with a self-describing preview plus a <<<CCR:hash|type|size>>> marker.
tool_calls[].function.arguments is a sibling field the loop never visits, so it always passes through untouched.
The HTTP proxy path is a separate pipeline from the Hermes FFI hook path: it classifies via proxy_detect_content_type and builds previews via proxy_build_preview, and never calls the staged transform pipeline (transforms::detect, stage2::compress_stage2, struct_extract::extract_code_structure) - those run only on the Hermes hook path (see 04-hook-ffi.md ).
The two pipelines share the BLAKE3 compute_key and the marker wire format, but nothing else.
Response compression sequence smart_marker / cache_marker CcrStore / inline_ccr LRU threshold_for + EMA proxy_detect_content_type compress_chat_completion upstream LLM API response_cache (LRU, 1MB cap) proxy_handler OpenAI/Anthropic client smart_marker / cache_marker CcrStore / inline_ccr LRU threshold_for + EMA proxy_detect_content_type compress_chat_completion upstream LLM API response_cache (LRU, 1MB cap) proxy_handler OpenAI/Anthropic client alt [exists] leave content untouched alt [content.len() > threshold (COMPRESS)] [content.len() > inline_ccr_threshold (INLINE only)] [below all thresholds] loop [each choice.message.content (string)] tool_calls[].function.arguments never visited (the loop reads message.content only) alt [Some(compressed)] [None] alt [is_chat_completion && state.ccr.is_some()] [not chat / no CCR] alt [content-type is text/event-stream] [non-streaming] alt [cache HIT] [miss] POST /v1/chat/completions {messages,tools,...} 1 requests_total++ · is_chat_completion = path==/v1/chat/completions 2 cache_key_from_body(body, api_key) (skips if stream:true) 3 cached bytes 4 200 X-Aphrodite-Cache: HIT (early return) 5 forward (stream_client if body stream:true, else client) · ≤3 conn retries 6 response (headers + body) 7 passthrough stream (NO compression - see 06-sse-streaming) 8 accumulate_body (cap 64MB) 9 compress_chat_completion(state, body, x-headroom-budget) 10 base_threshold = compress_threshold() (mode dispatch) 11 budget_mult = clamp(0.50 + hdr/100*0.50, 0.50..1.0) 12 proxy_detect_content_type(content) 13 ct (tool_output|code_rust|error|diff|json|text|...) 14 threshold = threshold_for(ct).max(base) * budget_mult 15 hash = compute_key(bytes) - BLAKE3, 40 hex 16 ccr_get(hash)? (dedup) 17 hit → ccr_hits++ 18 ccr_put(hash, content) → ccr_created++ 19 Cache→cache_marker / Token→smart_marker 20 "preview\n[ct: meta]\n<<<CCR:hash|ct|size>>>" 21 update_compression_ratio(orig,marker) → EMA 22 replace content with marker · did_compress=true 23 inline_ccr.put(hash, content) (no marker swap) 24 Some(response) if did_compress else None 25 write (success + ≤1MB) 26 200 X-Aphrodite-Compressed: true, X-Aphrodite-Fill-Pct 27 raw body passthrough, X-Aphrodite-Cache: MISS 28 raw passthrough 29 RESPONSE COMPRESSION SEQUENCE Per-type threshold (EMA auto-tune → fixed multiplier) update_compression_ratio yes no 20 0 else error code_* diff/git/text tool_output/json threshold_for(ct) ct in linter/build_output/log? return base (no tune, no mult) ratio = compression_ratio_ema/100 ratio tune = 2.0 (compressing well → raise bar) tune = 0.5 (weak → lower bar) tune = 1.0 base' = base*tune fixed per-type multiplier base'*8 base' * code_multiplier (default 3.0) base'*2 base' ratio = orig/comp * 100 new = 0.2*ratio + 0.8*old (α=0.2) fill_pct = clamp(100 - ema/20, 1..99)*100 PER-TYPE THRESHOLD (EMA AUTO-TUNE → FIXED MULTIPLIER) Call sites Concern Module proxy_handler request/response orchestrationcrates/aphrodite/src/proxy.rscompress_chat_completioncrates/aphrodite/src/proxy.rsproxy_detect_content_type (classify)crates/aphrodite/src/proxy.rsproxy_build_preview / proxy_format_ccr_outputcrates/aphrodite/src/proxy.rsthreshold_for / update_compression_ratio / compute_fill_pctcrates/aphrodite/src/proxy.rscompute_key (BLAKE3, 40-hex)vendor/headroom/crates/headroom-core/src/ccr/mod.rssmart_marker / cache_markercrates/aphrodite/src/proxy.rstool_calls pass-through rationale + test crates/aphrodite/src/proxy.rs