Skip to content

Conversation

@knjiang
Copy link
Contributor

@knjiang knjiang commented Jan 17, 2026

This PR forwards client headers into lingua with proxy-style filtering and dedupe JSON header setup; filtering similar to proxy.ts -> https://github.com/braintrustdata/braintrust-proxy/blob/main/packages/proxy/src/proxy.ts#L247

@knjiang knjiang marked this pull request as ready for review January 17, 2026 20:18
Copy link
Contributor Author

knjiang commented Jan 17, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@knjiang knjiang force-pushed the 01-17-forward_client_headers branch 6 times, most recently from 6cebe24 to 187ec78 Compare January 18, 2026 04:15
Comment on lines +35 to +54
/// Header prefixes blocked from forwarding to upstream LLM providers.
pub const BLOCKED_HEADER_PREFIXES: &[&str] = &["x-amzn", "x-bt", "sec-"];

/// Exact header names blocked from forwarding to upstream LLM providers
/// from https://github.com/braintrustdata/braintrust-proxy/blob/e992f51734c71e689ea0090f9e0a6759c9a593a4/packages/proxy/src/proxy.ts#L247
pub const BLOCKED_HEADERS: &[&str] = &[
"authorization",
"api-key",
"x-api-key",
"x-auth-token",
"content-length",
"origin",
"priority",
"referer",
"user-agent",
"cache-control",
// Avoid forwarding client Accept-Encoding: upstream may return compressed bytes we
// don't decode (e.g., unsupported encodings), which breaks JSON parsing in the router.
"accept-encoding",
];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main code that is similar to https://github.com/braintrustdata/braintrust-proxy/blob/main/packages/proxy/src/proxy.ts#L247

the only addition is accept-encoding which i was running into issues with since we don't have any feature crates on.

should we turn on gzip? -> https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html it seems to be a feature for reqwest and i think the LLM apis support it.

Comment on lines +98 to +99
// Respect caller override: only set default if missing.
if !headers.contains_key(ANTHROPIC_BETA) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-adding structured outputs since it seems useful esp. for chat completions response_format -> anthropic.

also seems hard coded in their sdk -> https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/resources/beta/messages/messages.py#L1106

@knjiang knjiang force-pushed the 01-17-forward_client_headers branch from 187ec78 to 403ea78 Compare January 18, 2026 04:58
@knjiang knjiang requested a review from ankrgyl January 18, 2026 06:08
@knjiang knjiang changed the title forward client headers forward client headers for providers Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants