feat(client): allow passing async httpx client#1557
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f47f6fbde7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
c7ffa7e to
f47f6fb
Compare
…not-applied-to-clientasync_api-in
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f5b8c8800
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| httpx_client=self.async_httpx_client, | ||
| timeout=timeout, |
There was a problem hiding this comment.
Preserve custom async client timeouts
When a caller provides async_httpx_client, this still forwards timeout to AsyncLangfuseAPI, and AsyncLangfuseAPI prefers that explicit timeout over the client’s own timeout config; since Langfuse.__init__ resolves timeout to a concrete value by default, requests from client.async_api are forced to that value instead of using the custom httpx.AsyncClient settings. This makes custom async clients partially ineffective and can cause unexpected request timeouts (for example, long-running endpoints being cut off at the SDK default).
Useful? React with 👍 / 👎.
Disclaimer: Experimental PR review
Greptile Summary
This PR adds support for passing a custom
async_httpx_client(httpx.AsyncClient) to theLangfuseconstructor, mirroring the existinghttpx_client(sync) parameter. The async client is stored onLangfuseResourceManager, passed toAsyncLangfuseAPI, and preserved throughget_client()— enabling users who need custom transport settings (e.g. proxies, SSL, connection limits) onclient.async_apito supply their own client.Key changes:
langfuse/_client/client.py: Newasync_httpx_clientparameter added to__init__with docstring update.langfuse/_client/resource_manager.py: Parameter threaded into_initialize_instance; internally createshttpx.AsyncClientif not provided; passes it toAsyncLangfuseAPI(previouslyAsyncLangfuseAPIcreated its own internal client).langfuse/_client/get_client.py:async_httpx_client=instance.async_httpx_clientadded to_create_client_from_instancesoget_client()preserves the client across singleton lookups.get_client().The implementation is clean, follows existing patterns, and is well-tested. Changes correctly thread the parameter through all relevant layers with proper end-to-end testing.
Confidence Score: 5/5
async_httpx_clientparameter is correctly threaded through all layers (client → resource manager → async API), preserves the client acrossget_client()calls, and is comprehensively tested. The code quality is high with minimal changes following established patterns. No functional issues or regressions identified.Sequence Diagram
sequenceDiagram participant User participant Langfuse participant ResourceManager as LangfuseResourceManager participant AsyncAPI as AsyncLangfuseAPI User->>Langfuse: Langfuse(async_httpx_client=custom_client) Langfuse->>ResourceManager: LangfuseResourceManager(..., async_httpx_client=custom_client) alt async_httpx_client provided ResourceManager->>ResourceManager: self.async_httpx_client = custom_client else async_httpx_client is None ResourceManager->>ResourceManager: self.async_httpx_client = httpx.AsyncClient(...) end ResourceManager->>AsyncAPI: AsyncLangfuseAPI(..., httpx_client=self.async_httpx_client) AsyncAPI-->>ResourceManager: async_api instance ResourceManager-->>Langfuse: resources ready Langfuse-->>User: client ready (client.async_api uses custom_client) User->>Langfuse: get_client() Langfuse->>ResourceManager: _create_client_from_instance(instance) ResourceManager-->>Langfuse: Langfuse(..., async_httpx_client=instance.async_httpx_client) Langfuse-->>User: client with preserved async_httpx_clientLast reviewed commit: f47f6fb