diff --git a/astrbot/core/provider/sources/anthropic_source.py b/astrbot/core/provider/sources/anthropic_source.py index 27cc459622..e9dfbc3d8d 100644 --- a/astrbot/core/provider/sources/anthropic_source.py +++ b/astrbot/core/provider/sources/anthropic_source.py @@ -131,7 +131,11 @@ def _create_http_client(self, provider_config: dict) -> httpx.AsyncClient | None try: from anthropic import _base_client as anthropic_base_client - httpx_module = getattr(anthropic_base_client, "httpx", httpx) + httpx_module = getattr( + anthropic_base_client, + "httpx2", + getattr(anthropic_base_client, "httpx", httpx), + ) except ImportError: pass return create_proxy_client( diff --git a/tests/test_anthropic_kimi_code_provider.py b/tests/test_anthropic_kimi_code_provider.py index 0dc33f58ba..d54894a05f 100644 --- a/tests/test_anthropic_kimi_code_provider.py +++ b/tests/test_anthropic_kimi_code_provider.py @@ -137,7 +137,13 @@ def fake_create_proxy_client( assert captured["provider_label"] == "Anthropic" assert captured["proxy"] == "http://127.0.0.1:7890" assert captured["headers"] == {"X-Trace-Id": "trace-1"} - assert captured["httpx_module"] is anthropic_base_client.httpx + sdk_httpx = getattr( + anthropic_base_client, + "httpx2", + getattr(anthropic_base_client, "httpx", None), + ) + assert sdk_httpx is not None + assert captured["httpx_module"] is sdk_httpx def test_create_http_client_falls_back_to_global_httpx_module(monkeypatch):