-
Notifications
You must be signed in to change notification settings - Fork 0
forward client headers for providers #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
6cebe24 to
187ec78
Compare
| /// 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", | ||
| ]; | ||
|
|
There was a problem hiding this comment.
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.
| // Respect caller override: only set default if missing. | ||
| if !headers.contains_key(ANTHROPIC_BETA) { |
There was a problem hiding this comment.
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
187ec78 to
403ea78
Compare

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