Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

feat(server): forward x-litellm-response-cost upstream header (#806)

Deepak Jain (DJ)8258e29cd627
diff --git a/crates/switchyard-server/src/lib.rs b/crates/switchyard-server/src/lib.rs
index 58ebc0d97..4faf09821 100644
--- a/crates/switchyard-server/src/lib.rs
+++ b/crates/switchyard-server/src/lib.rs
@@ -72,6 +72,7 @@ const FORWARDED_UPSTREAM_HEADERS: &[&str] = &[
"request-id",
"traceparent",
"tracestate",
+ "x-litellm-response-cost",
"x-request-id",
];
const FORWARDED_UPSTREAM_HEADER_PREFIXES: &[&str] =
@@ -1987,4 +1988,20 @@ mod tests {
Some("invalid request")
);
}
+
+ // LiteLLM's cost header passes through to the client; auth headers do not.
+ #[test]
+ fn upstream_header_forwarding_covers_litellm_cost() {
+ for name in [
+ "baggage",
+ "x-litellm-response-cost",
+ "x-ratelimit-remaining",
+ "x-upstream-retry",
+ ] {
+ let header: HeaderName = name.parse().expect("header name");
+ assert!(should_forward_upstream_header(&header), "{name}");
+ }
+ let secret: HeaderName = "authorization".parse().expect("header name");
+ assert!(!should_forward_upstream_header(&secret));
+ }
}