Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions langfuse/_client/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_additional_headers_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand Down
Loading