From 6ec1263e9faf6c3baa83a4bfb0972ca7be267f9c Mon Sep 17 00:00:00 2001 From: Anubhav Date: Mon, 9 Nov 2026 22:36:15 +0530 Subject: [PATCH] fix(client): send additional_headers from async_api --- langfuse/_client/resource_manager.py | 1 + tests/unit/test_additional_headers_simple.py | 25 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/langfuse/_client/resource_manager.py b/langfuse/_client/resource_manager.py index 1c1afa424..360fc7d5d 100644 --- a/langfuse/_client/resource_manager.py +++ b/langfuse/_client/resource_manager.py @@ -366,6 +366,7 @@ def _init_api_clients(self) -> None: x_langfuse_sdk_name="python", x_langfuse_sdk_version=langfuse_version, x_langfuse_public_key=self.public_key, + headers=self.additional_headers, timeout=self.timeout, ) diff --git a/tests/unit/test_additional_headers_simple.py b/tests/unit/test_additional_headers_simple.py index d05475a3c..e22c4c141 100644 --- a/tests/unit/test_additional_headers_simple.py +++ b/tests/unit/test_additional_headers_simple.py @@ -3,6 +3,7 @@ This module tests that additional headers are properly configured in the HTTP clients. """ +import asyncio from typing import Sequence import httpx @@ -56,6 +57,30 @@ def test_httpx_client_has_additional_headers_when_none_provided(self): == "another-value" ) + def test_async_api_sends_additional_headers(self): + langfuse = Langfuse( + public_key="test-public-key", + secret_key="test-secret-key", + host="https://mock-host.com", + additional_headers={"X-Custom-Header": "custom-value"}, + tracing_enabled=False, + ) + captured_requests = [] + + def handler(request: httpx.Request) -> httpx.Response: + captured_requests.append(request) + return httpx.Response(200, json={"status": "OK", "version": "1.0.0"}) + + wrapper = langfuse.async_api._client_wrapper + wrapper.httpx_client.httpx_client = httpx.AsyncClient( + transport=httpx.MockTransport(handler) + ) + + asyncio.run(langfuse.async_api.health.health()) + + assert len(captured_requests) == 1 + assert captured_requests[0].headers["X-Custom-Header"] == "custom-value" + def test_custom_httpx_client_with_additional_headers_ignores_additional_headers( self, ):