Skip to content

[HTTPXodus] migrate httpx to httpx2 with dual import - #3931

Open
ProgrammerPlus1998 wants to merge 1 commit into
lm-sys:mainfrom
ProgrammerPlus1998:httpxodus/httpx2-migration
Open

[HTTPXodus] migrate httpx to httpx2 with dual import#3931
ProgrammerPlus1998 wants to merge 1 commit into
lm-sys:mainfrom
ProgrammerPlus1998:httpxodus/httpx2-migration

Conversation

@ProgrammerPlus1998

@ProgrammerPlus1998 ProgrammerPlus1998 commented Sep 3, 2026

Copy link
Copy Markdown

Closes #3929

🏷️ Part of HTTPXodus — a community effort to help major Python projects plan their path off the stalled httpx stable line onto httpx2, the actively maintained fork by Pydantic Services. One coordinated PR per project — no drive-by changes.

What this PR does

Switches FastChat's single httpx call site to httpx2 via a dual import. On Python ≥ 3.10 the runtime binds to httpx2; on 3.8 / 3.9 (which FastChat still supports and which httpx2 cannot run on) it falls back to httpx. requires-python is not changed — this PR does not drop any currently-supported interpreter.

Diff summary

2 files, +6 / −2 (commit 4ea6a03):

  • pyproject.toml — added "httpx2>=2.12.0; python_version >= \"3.10\"" next to the existing "httpx". The python_version marker means httpx2 is only installed on runtimes that can run it; httpx stays in deps for 3.8/3.9.
  • fastchat/serve/openai_api_server.py — top-of-file import httpx replaced with the try: import httpx2 as httpx; except ModuleNotFoundError: import httpx block. This is the only call site in the entire package; non-streaming paths use aiohttp, and controller / model-worker / gradio / monitor / judge code never imports httpx.

Test results

Validated in a fresh venv (Python 3.12.12):

  • pip install -e . — resolves to both httpx-0.28.1 and httpx2-2.12.0 (the marker correctly selects httpx2 on 3.12).
  • srv = importlib.import_module("fastchat.serve.openai_api_server"); srv.httpx.__version__ == "2.12.0" — the try branch wins.
  • Fallback test: uninstalled httpx2, re-imported the module → srv.httpx.__version__ == "0.28.1". The except branch works as expected. This simulates a 3.8/3.9 install where httpx2 is not present.
  • python -W error -c "import fastchat.serve.openai_api_server" — no import-time warnings.
  • black==23.3.0 --check fastchat/serve/openai_api_server.py — clean (the project pins black==23.3.0 in its dev extras; format.sh uses the same version).

The repo's tests/test_image_utils.py fails to collect on stock main (pre-existing — it imports resize_image_and_return_image_in_bytes and image_moderation_filter from fastchat.utils, which are not defined there). Verified by stash + re-test on a clean checkout. Unrelated to this PR. The remaining tests/test_*.py files are all integration tests requiring a live model worker + controller + api server, which can't run in a unit-test context. None reference httpx directly.

Notes for reviewer

  • This is one of the smaller migrations in the HTTPXodus batch: a single internal call site with no public-API surface change. The blast radius is the streaming-completion path between the OpenAI-compatible API server and a model worker.
  • ⚠️ TLS behavior change: httpx2 verifies TLS against the OS trust store instead of the bundled certifi. FastChat deployments that front worker endpoints with TLS (e.g. reverse-proxied multi-node setups) and rely on a custom certifi CA bundle may need SSL_CERT_FILE / SSL_CERT_DIR after the switch. Worth a line in the deployment docs.
  • FastChat's own development has slowed (last release v0.2.36 in 2024-02, last commit on main is a constants.py bump in 2025-06-02; the hosted Chatbot Arena moved to LMArena in 2024-09). The migration itself is tiny and safe; whether to take it is a judgement call about how much ongoing investment this stack is getting. We're flagging it because httpx is unpinned in pyproject.toml, so a breaking httpx 1.0 stable would land in installs without warning.
  • requires-python is unchanged at >=3.8. If maintainers later decide to drop 3.8/3.9, the dual-import can be replaced with a hard import httpx2 in a follow-up PR.

Happy to revise per review — and equally happy to close this PR if the maintainers would rather wait for httpx 1.0 stable. 🙏

Use the actively maintained httpx2 fork (Pydantic Services) when running
on Python 3.10+, falling back to httpx on 3.8/3.9. Single call site
only: fastchat/serve/openai_api_server.py's generate_completion_stream.

Refs: lm-sys#3929
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.

[HTTPXodus] Consider migrating from httpx to httpx2 (the actively maintained fork)

1 participant