fix(llm): route http_client to the matching sync/async Anthropic client#565
Open
matteomedioli wants to merge 4 commits into
Open
fix(llm): route http_client to the matching sync/async Anthropic client#565matteomedioli wants to merge 4 commits into
matteomedioli wants to merge 4 commits into
Conversation
…ync Anthropic clients Route httpx.Client only to the sync anthropic.Anthropic constructor and httpx.AsyncClient only to the async anthropic.AsyncAnthropic constructor, mirroring BaseOpenAILLM's existing param-splitting pattern, so passing a sync-only or async-only http_client no longer collides across both clients.
… type Mirror BaseOpenAILLM's existing behavior: when http_client is provided but is neither an httpx.Client nor an httpx.AsyncClient instance, emit a warning and construct both clients with the default (no custom) http_client instead of raising.
…tests Add unit tests verifying httpx.Client reaches only the sync Anthropic client, httpx.AsyncClient reaches only the async client, and an invalid http_client type warns and falls back to defaults for both clients. Also note the stale-venv anthropic version gotcha in AGENTS.md.
Documents the AnthropicLLM sync/async http_client kwargs collision bug fixed in tasks 001-002, matching the repo's existing changelog style.
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.
Description
AnthropicLLM.__init__currently passes the exact same**kwargsdict to bothanthropic.Anthropic(**kwargs)(sync) andanthropic.AsyncAnthropic(**kwargs)(async):Most kwargs (
api_key,max_retries,default_headers, ...) are safe to share.http_clientis not: it must be anhttpx.Clientfor the sync client and anhttpx.AsyncClientfor the async client — two incompatible types. Whichever one you pass, the other client receives the wrong type. Today there is effectively no way to inject a custom transport intoAnthropicLLMat all.BaseOpenAILLM(the OpenAI integration) already solves this correctly — it splitshttp_clientinto separate sync/async parameter sets before constructingOpenAI/AsyncOpenAI. This PR bringsAnthropicLLMto the same standard:http_clientis popped fromkwargsand routed only to the client whose type it matches (httpx.Client→ sync,httpx.AsyncClient→ async).http_clientof an unrecognized type emits a warning and is ignored (both clients fall back to their default transport), matchingOpenAILLM's existing behavior rather than crashing or silently misbehaving.This is a pure bugfix — no new parameter, no constructor signature change. Anyone not passing
http_clientsees no behavior difference.Every provider SDK Anthropic ships (
anthropic.Anthropic,anthropic.AnthropicVertex, etc.) already supports a customhttp_clientandbase_url— the coupling to the default endpoint is an artifact of how this class forwards constructor kwargs, not a limitation of the underlying SDK. Fixing the sync/async split is the prerequisite for that to actually work; a natural follow-up (open separately for focused review) extracts aBaseAnthropicLLMbase class mirroringBaseOpenAILLM/AzureOpenAILLM.Type of Change
Complexity
Complexity: Low
How Has This Been Tested?
Checklist
The following requirements should have been met (depending on the changes in the branch):