ModuleNotFoundError: No module named 'httpx'

That's what three out of three Claude Code runs produced when I asked for a small script on the current OpenAI Python SDK. The code was clean and typed. It just targeted an SDK that no longer exists.

So I set up a controlled comparison. Same task, same model, same prompt, and four ways for the agent to get documentation. Then I ran every generated script against the real OpenAI API.

Everything below is reproducible, and the last section shows you how.

| Setup | Worked on openai 3.60 | Avg time | Avg cost | |---|---|---|---| | No docs | 0 / 3 | 28 s | $0.24 | | Context7 MCP | 3 / 3 | 38 s | $0.37 | | Context7 + "use context7" | 3 / 3 | 43 s | $0.34 | | Web search + fetch | 3 / 3 | 70 s | $0.48 |

openai 3.0 (August 12, 2026) moved the SDK from httpx to HTTPX2, and httpx is no longer a dependency. Anything that builds a custom HTTP client is affected: proxies, granular timeouts, transports, mocks.

Write triage.py. Read tickets.csv (id, text), ask OpenAI to classify each ticket
(billing, bug, feature_request, other) with a one-sentence reason, write triaged.csv.
- openai SDK pinned to >=3.60,<4. Make sure the code is correct for this version.
- Model: gpt-5.4-mini
- All traffic through the corporate proxy in CORP_PROXY
- 5 s connect timeout, 30 s read timeout
- Structured output, no regex parsing
Only write the files. Don't install packages or call the API.

All three no-docs runs reached for the client they remembered:

import httpx

http_client = httpx.Client(
    proxy=proxy,
    timeout=httpx.Timeout(30.0, connect=5.0),
)
return OpenAI(http_client=http_client, max_retries=0)
Traceback (most recent call last):
  File "triage.py", line 6, in <module>
    import httpx
ModuleNotFoundError: No module named 'httpx'

The version was in the prompt. The model didn't know what that version changed.

Context7 exposes two MCP tools. Each Context7 run followed the same pattern:

resolve-library-id  "openai python"                    -> /openai/openai-python
query-docs          "structured outputs with responses.parse"
query-docs          "custom http client with proxy and timeout"
query-docs          "httpx2 migration: does plain httpx.Client still work"

And produced:

import httpx2
from openai import OpenAI, DefaultHttpx2Client

TIMEOUT = httpx2.Timeout(connect=5.0, read=30.0, write=30.0, pool=30.0)

client = OpenAI(
    http_client=DefaultHttpx2Client(proxy=proxy, timeout=TIMEOUT),
    timeout=TIMEOUT,
)

6 of 6 runs passed, including the 3 where the prompt never mentioned Context7. The agent called it on its own.

Web search also got all three right. It needed 4 to 7 searches and full-page fetches per run, against 3 to 5 Context7 calls that return only matching snippets. That's the gap in the table: 70 s and $0.48 per run against 40 s and $0.36 for the Context7 average.

Execution against the real OpenAI API, through a logging proxy:

Cost per run, as reported by Claude Code:

pip install httpx rescues the no-docs code.APITimeoutError at 30.2 s. You need Node 22.13+, Python 3.12, Claude Code, and an OpenAI API key for the final check.

1. One MCP config per setup. Context7's hosted server works without a key (rate-limited):

echo '{"mcpServers":{}}' > mcp-none.json
echo '{"mcpServers":{"context7":{"type":"http","url":"https://mcp.context7.com/mcp"}}}' > mcp-context7.json

2. A clean folder per run. Put tickets.csv and a requirements.txt with openai>=3.60,<4 in base/, and save the task prompt above as PROMPT.md. Keep this outside any repo with a CLAUDE.md, or it leaks into the context.

3. The runner. The tool flags are the experiment:

#!/bin/bash
# usage: ./run.sh <name> <mcp-json> <disallowed-tools> [prompt-suffix]
NAME=$1; MCP=$2; DIS=$3; SUFFIX=$4
mkdir -p runs/$NAME && cp base/* runs/$NAME/ && cd runs/$NAME
claude -p "$(cat ../../PROMPT.md)$SUFFIX" \
  --model claude-sonnet-5-5 \
  --strict-mcp-config --mcp-config ../../$MCP \
  --disable-slash-commands \
  --permission-mode acceptEdits \
  --allowedTools "mcp__context7__resolve-library-id,mcp__context7__query-docs,WebSearch,WebFetch" \
  --disallowedTools $DIS \
  --output-format stream-json --verbose < /dev/null > ../$NAME.jsonl
for r in 1 2 3; do
  ./run.sh nodocs_$r   mcp-none.json     "WebSearch,WebFetch,Bash" &
  ./run.sh context7_$r mcp-context7.json "WebSearch,WebFetch,Bash" &
  ./run.sh phrase_$r   mcp-context7.json "WebSearch,WebFetch,Bash" $'\n\nuse context7' &
  ./run.sh web_$r      mcp-none.json     "Bash" &
done; wait

Two flags matter more than they look:

--allowedTools must list the Context7 tools. Without it, headless mode denies them silently and you're testing "no docs" twice. My first batch was invalid because of this.--disallowedTools wins over 4. Read cost and tool calls from the last result event of each .jsonl:

import json, glob
for f in sorted(glob.glob("runs/*.jsonl")):
    r = [json.loads(l) for l in open(f) if '"type":"result"' in l][-1]
    print(f, r["num_turns"], f'{r["duration_ms"]/1000:.0f}s', f'${r["total_cost_usd"]:.3f}')

5. Verify against the real SDK. Install openai>=3.60,<4 in a fresh venv (that's what removes httpx), then run each triage.py with CORP_PROXY pointing at a small logging proxy. Pass = exit code 0, 6 rows in triaged.csv, and a CONNECT api.openai.com:443 line in the proxy log. If you set OPENAI_API_KEY in your OS as well as in .env, unset the OS one first: most loaders won't override it.

Try Context7 on your own stack. Run the script above against the library that last broke your agent.

Looking for technical content for your company? I can help — LinkedIn · kevinmenesesgonzalez@gmail.com

原文来源:dev.to