Skip to content
Nilay Kabariya

Entry No.116·AI··4 min read

No module named 'httpx' after an SDK upgrade: the httpx2 switch

Anthropic, Hugging Face and Google GenAI's Python SDKs now install httpx2, not httpx. Code that relied on httpx breaks and respx stops mocking. Tested.

by Nilay#python#anthropic#gemini#huggingface#testingAI

The error, verbatim

Jump to the fix ↓
ModuleNotFoundError: No module named 'httpx'

The fix that worked

If your code imports httpx itself, depend on it yourself:

pip install httpx
Not it? Every cause, tested ↓

Tested on

SDKs
anthropic 0.125.0 (last 0.x; 1.x and 2.x both use httpx2) and 2.6.0, huggingface_hub 1.33.0 and 2.4.0, google-genai 2.34.0 and 3.0.0
HTTP
httpx 0.28.1, httpx2 2.16.0 (2.16.2 in the November 16 side-by-side check), respx 0.23.1
Python
3.13.18 (GitHub Actions ubuntu-latest); 3.15.2 on Windows 11 for the side-by-side check (re-run November 16)

If import httpx worked yesterday and fails today, check whether you ever installed httpx yourself. In most projects it arrived as a dependency of an AI SDK: the Anthropic, Hugging Face Hub and Google GenAI Python packages all used it. Their current major versions don’t. They depend on httpx2 instead, so upgrading the SDK quietly removes httpx from a fresh environment, and any code of yours that imported it, or any test that mocks it, breaks on the next rebuild.

If your own code uses httpx, add it to your requirements explicitly, so it no longer depends on what an SDK happens to bring:

pip install httpx

Which SDK versions still bring httpx

I installed each SDK on its own, newest release and an older line (for Anthropic the last 0.x release; its 1.x and 2.x lines both already use httpx2), in fresh environments on November 9, 2026, and looked at what came along:

Terminal on GitHub Actions with Python 3.13: anthropic 2.6.0, huggingface_hub 2.4.0 and google-genai 3.0.0 install httpx2 2.16.0 and no httpx, so import httpx fails with ModuleNotFoundError; anthropic 0.125.0, huggingface_hub 1.33.0 and google-genai 2.34.0 install httpx 0.28.1; anthropic imports httpx2; a respx mock on the Anthropic URL is not used and the call fails with APIConnectionError.
Six installs, each SDK alone, and the respx check. Full log.
SDK Installs import httpx
anthropic 0.125.0 httpx 0.28.1 works
anthropic 2.6.0 httpx2 2.16.0 only ModuleNotFoundError
huggingface_hub 1.33.0 httpx 0.28.1 works
huggingface_hub 2.4.0 httpx2 2.16.0 only ModuleNotFoundError
google-genai 2.34.0 httpx 0.28.1 works
google-genai 3.0.0 httpx2 2.16.0 only ModuleNotFoundError

The common pattern behind the error is a helper or test that does import httpx to set a timeout, build a custom client or catch httpx.HTTPError, written when the SDK made httpx available for free. The SDK didn’t break your code; it stopped carrying a package you were using without declaring it. That’s also why the error can appear in only some environments: an older lockfile, or another library that still depends on httpx (respx itself does), keeps it installed and hides the gap until a clean install.

The quieter break: respx stops mocking

respx mocks requests by patching httpx. The new SDKs don’t send requests through httpx any more, so a respx mock is never consulted. I pointed the Anthropic client (2.6.0) at a closed local port and set up a respx route for that exact URL. Instead of the mocked reply, the call failed:

anthropic + respx: NOT mocked -> APIConnectionError Connection error.

On a machine with network access, that same unmocked call would go to the real address in your base URL, so a test suite that never checks the route was called can keep passing while it hits a live API, or start failing with connection errors in CI where outbound traffic is blocked. If your SDK tests rely on respx (or anything else that patches httpx), check that they still intercept anything after the upgrade: a route that’s never called is the giveaway, and respx’s assert_all_called option (on by default in respx.mock(...), off for plain respx.mock) turns that into a test failure instead of a silent pass.

What still works in my experience across these posts is not mocking the HTTP library at all: point the SDK’s base URL (base_url= on the Anthropic client) at a small local HTTP server that returns the reply you want. That doesn’t depend on which HTTP package the SDK uses underneath.

What else changes with httpx2

httpx2 is a separate package, not a version of httpx, so code written against httpx types (httpx.Timeout, httpx.Client, exception classes) doesn’t automatically match what the SDK uses internally. If you pass your own HTTP client or catch HTTP exceptions around SDK calls, check each SDK’s current documentation for what it now accepts; I only tested installs, imports and respx here.

The run

GitHub Actions ubuntu-latest, Python 3.13.18, November 9, 2026. Each SDK version was installed alone into a fresh venv, then the script listed the installed httpx and httpx2 versions and tried import httpx. The respx check installed anthropic, google-genai and respx together and called the Anthropic client against http://127.0.0.1:9 with a respx route for that URL. The side-by-side check (adding httpx back next to anthropic 2.6.0) is not part of that script: I ran it by hand on Windows 11 with Python 3.15.2 on November 16, 2026 in a fresh venv, and it gave the result above. The script and its run are public.

— N.K., end of entry No.116

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.098

    huggingface-cli: command not found (removed in 1.0, not 2.0)

    huggingface-cli stopped working in huggingface_hub 1.0.0, returned as a do-nothing stub in 1.10.1 and is gone in 2.0. All versions tested, plus the hf commands.

    > huggingface-cli: command not found

    AI5 min
  2. No.088

    Responses.create() unexpected keyword argument: new names

    max_tokens, messages, response_format, seed: their names in OpenAI's Responses API, tested. Plus the 'proxies' TypeError from httpx 0.28.

    > TypeError: Responses.create() got an unexpected keyword argument 'max_tokens'

    AI6 min
  3. No.087

    Claude SDK: unexpected keyword argument temperature, betas

    Messages.create() got an unexpected keyword argument after an anthropic upgrade, plus what SDK 2.0 (October 21) breaks next. Python and TypeScript, tested.

    > TypeError: Messages.create() got an unexpected keyword argument 'temperature'

    AI5 min

tip: paste the exact error text