Skip to content

Respect custom http headers for outgoing client requests#1166

Merged
joshua-mo-143 merged 5 commits into0xPlaygrounds:mainfrom
simonjanssen:respect-ext-accept-header-streaming
Dec 17, 2025
Merged

Respect custom http headers for outgoing client requests#1166
joshua-mo-143 merged 5 commits into0xPlaygrounds:mainfrom
simonjanssen:respect-ext-accept-header-streaming

Conversation

@simonjanssen
Copy link
Contributor

I am operating in a env where I need to set custom headers for my LLM providers (e.g. user-agent, etc.). Specifically, I need to set a custom Accept header for streaming updates via OpenAI clients.

Setting default headers for my reqwest client had no effect as the ProviderClient treats http client and http headers separately for http request building.

In the ClientBuilder these headers default to an empty map. As far as I can tell there is currently no public setter method to set anything but the default headers.

What I've added/changed:

  • added a demo http_header setter method for ClientBuilder to add additional, custom http headers
  • GenericEventSource::new() reflects custom Accept headers set this way instead of overwriting

Tested the proposed changes with this setup which worked just fine:

let client = openai::CompletionsClient::<reqwest::Client>::builder()
    .base_url(my_base_url)
    .http_headers(my_custom_headers) // added
    .http_client(my_reqwest_client)
    .api_key(my_api_key)
    .build()?;

Copy link
Collaborator

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

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

Needs cargo fmt then lgtm

@simonjanssen
Copy link
Contributor Author

Needs cargo fmt then lgtm

done

Copy link
Collaborator

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Dec 17, 2025
Merged via the queue into 0xPlaygrounds:main with commit 6f7a8cb Dec 17, 2025
5 checks passed
@github-actions github-actions bot mentioned this pull request Dec 17, 2025
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