anthropic Python 2.8.0: http_client=httpx.Client(transport=httpx.MockTransport(...)) raises TypeError 'this SDK uses httpx2. Use httpx2.Client instead'
Pass httpx2.Client(transport=httpx2.MockTransport(handler)) as http_client to Anthropic(); with httpx.Client it raised: TypeError: Invalid http_client argument; httpx.Client is from the httpx package, but this SDK uses httpx2. Use httpx2.Client instead. Tested on Python 3.14 via uv run --with anthropic python script.py, anthropic 2.8.0, httpx2 2.16.0, api_key='sk-ant-dummy', no network. The handler returned a tool_use JSON response and msg.stop_reason was 'tool_use'. Script that ran:
import json import httpx2 as httpx import anthropic from anthropic import Anthropic
print("anthropic", anthropic.__version__, "httpx", httpx.__version__) seen = []
def handler(request: httpx.Request) -> httpx.Response: seen.append(json.loads(request.content)) return httpx.Response(200, json={ "id": "msg_1", "type": "message", "role": "assistant", "model": "claude-sonnet-4-5", "content": [{"type": "tool_use", "id": "toolu_1", "name": "get_weather", "input": {"city": "Paris"}}], "stop_reason": "tool_use", "stop_sequence": None, "usage": {"input_tokens": 1, "output_tokens": 1}, })
client = Anthropic(api_key="sk-ant-dummy", http_client=httpx.Client(transport=httpx.MockTransport(handler))) tools = [{"name": "get_weather", "description": "w", "input_schema": {"type": "object", "properties": {"city": {"type": "string"}}}}] msg = client.messages.create(model="claude-sonnet-4-5", max_tokens=100, tools=tools, messages=[{"role": "user", "content": "weather?"}]) print(type(msg).__name__, msg.stop_reason) print(msg.content[0].type, type(msg.content[0]).__name__, type(msg.content[0].input).__name__, msg.content[0].input)
client.messages.create(model="claude-sonnet-4-5", max_tokens=100, tools=tools, messages=[ {"role": "user", "content": "weather?"}, {"role": "assistant", "content": msg.content}, {"role": "user", "content": [{"type": "tool_result", "tool_use_id": msg.content[0].id, "content": "sunny"}]}, ]) print(json.dumps(seen[1]["messages"]))