Skip to content

fix(llm): route http_client to the matching sync/async Anthropic client#565

Open
matteomedioli wants to merge 5 commits into
mainfrom
matteo/anthropic-kwargs-bugfix
Open

fix(llm): route http_client to the matching sync/async Anthropic client#565
matteomedioli wants to merge 5 commits into
mainfrom
matteo/anthropic-kwargs-bugfix

Conversation

@matteomedioli

@matteomedioli matteomedioli commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Stack

Merge order: #565#567#566#571 / #572 (last two in either order). Each PR builds on the previous one. Until its base merges, GitHub may show parent commits in the diff — review only the commits unique to this branch.

Description

AnthropicLLM builds two SDK clients — one sync, one async — from the same **kwargs. Most settings are safe to share between them, but http_client is not: the sync client needs an httpx.Client and the async client needs an httpx.AsyncClient. Today whichever one you pass is forwarded to both clients, so one of them always receives the wrong type. In practice there is no way to inject a custom HTTP client into AnthropicLLM at all.

This PR fixes that:

  • http_client now goes only to the client whose type it matches.
  • Passing anything else emits a warning and is ignored (both clients fall back to their defaults) — the same behavior OpenAILLM already has.
  • Every other kwarg is still shared between both clients, unchanged.

No new parameters, no signature changes. If you never pass http_client, nothing changes for you.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change

Complexity

Complexity: Low

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Checklist

  • Documentation has been updated
  • Unit tests have been updated
  • Examples have been updated
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated

…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.
Keep the PR scoped to the http_client routing fix.
@matteomedioli
matteomedioli force-pushed the matteo/anthropic-kwargs-bugfix branch 2 times, most recently from e487f99 to 4300d09 Compare July 17, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant