Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
feat(rust): upstream health check endpoint (phase-1)
chopratejase3b71b949f14
diff --git a/crates/headroom-proxy/src/health.rs b/crates/headroom-proxy/src/health.rsnew file mode 100644index 000000000..8c0524bcf--- /dev/null+++ b/crates/headroom-proxy/src/health.rs@@ -0,0 +1,45 @@+//! Health endpoints. These are intercepted by Rust and never forwarded.++use axum::extract::State;+use axum::http::StatusCode;+use axum::response::{IntoResponse, Response};+use axum::Json;+use serde_json::json;++use crate::proxy::AppState;++/// Own health: 200 if the proxy process is up.+pub async fn healthz() -> impl IntoResponse {+ Json(json!({ "ok": true, "service": "headroom-proxy" }))+}++/// Upstream health: GETs upstream `/healthz`. Returns 200 when reachable ++/// 2xx, 503 otherwise. The endpoint name is reserved by the proxy and is+/// not forwarded; operators must not name a real upstream route this.+pub async fn healthz_upstream(State(state): State<AppState>) -> Response {+ let url = match state.config.upstream.join("healthz") {+ Ok(u) => u,+ Err(e) => {+ return (+ StatusCode::SERVICE_UNAVAILABLE,+ Json(json!({"ok": false, "error": format!("bad upstream url: {e}")})),+ )+ .into_response();+ }+ };+ match state.client.get(url).send().await {+ Ok(resp) if resp.status().is_success() => {+ (StatusCode::OK, Json(json!({"ok": true}))).into_response()+ }+ Ok(resp) => (+ StatusCode::SERVICE_UNAVAILABLE,+ Json(json!({"ok": false, "upstream_status": resp.status().as_u16()})),+ )+ .into_response(),+ Err(e) => (+ StatusCode::SERVICE_UNAVAILABLE,+ Json(json!({"ok": false, "error": e.to_string()})),+ )+ .into_response(),+ }+}