Repository navigation
fix(client): send additional_headers from async_api - #2117
Open
anubhavlal07 wants to merge 1 commit into
Open
anubhavlal07 wants to merge 1 commit into
anubhavlal07 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Langfuse(additional_headers=...)is documented as "Additional headers to include in all API requests", but only the sync client (langfuse.api) and the OTLP exporter receive them.LangfuseResourceManager._init_api_clients()buildsAsyncLangfuseAPIwithoutheaders=, so every request made throughlangfuse.async_api(and helpers built on it, such asaiter_observation_pages) goes out without the configured headers. Behind a proxy or gateway that needs those headers (auth, routing, tenant headers), sync calls work and async calls fail.Minimal repro on current
main:On
mainthis prints[None]. The same call throughlf.apisends the header, because the synchttpx.Clientis created withheaders=additional_headers.Fix: pass
headers=self.additional_headerstoAsyncLangfuseAPI. The async client always builds its ownhttpx.AsyncClient, so the headers have nowhere else to go. Sync behaviour is unchanged, including the documented rule that a customhttpx_clientkeeps its own headers. The same code path runs afterfork(), so re-initialised workers get the headers too.Related, but separate: langfuse/langfuse#12422 is about a custom
httpx_clientnot being applied toasync_api. This PR only coversadditional_headers, which users set without passing a custom client.Type of change
Verification
test_async_api_sends_additional_headerssends a realasync_api.health.health()request through anhttpx.MockTransportand asserts that the custom header is on the wire. It fails onmainand passes with the fix.test_additional_headers_simple.py: 12 passed. ruff and mypy are clean.time.tzsettests, a POSIX path assertion intest_serializer.py::test_path, thetest_prompt_atexitsubprocess tests, and thetest_prompt.pyfixture that needsLANGFUSE_*env vars (tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env vars #1976).Checklist
code_review.md..env.templateif needed. (Not needed: this change makes the code match the existing docstring.)This change was prepared with the help of an AI assistant (Claude), and I reviewed and tested it.


Confidence Score: 5/5
The PR appears safe to merge.Summary
Passes
additional_headerstoAsyncLangfuseAPI, so async requests receive the configured headers.Reviews (1) · Last reviewed commit: "fix(client): send additional_headers fro..." · Reviewed by Greptile