Skip to content

fix(agent): respect HTTP_PROXY/HTTPS_PROXY when using custom httpx transport#12540

Closed
heykb wants to merge 2 commits into
NousResearch:mainfrom
heykb:fix-http-proxy-with-custom-transport
Closed

fix(agent): respect HTTP_PROXY/HTTPS_PROXY when using custom httpx transport#12540
heykb wants to merge 2 commits into
NousResearch:mainfrom
heykb:fix-http-proxy-with-custom-transport

Conversation

@heykb

@heykb heykb commented Apr 19, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes a bug where HTTP_PROXY/HTTPS_PROXY environment variables were ignored when using the kimi-coding-cn provider (or any provider) behind a proxy.

The root cause was that when creating httpx.Client with a custom HTTPTransport (for TCP keepalive), httpx only reads proxy settings from environment variables when transport=None. Since we were explicitly passing a custom transport, the proxy settings were never applied.

This fix adds _get_proxy_from_env() to explicitly read proxy settings and pass them to httpx.Client, ensuring providers work correctly when behind a proxy.

Related Issue

Fixes connection errors like:

PI call failed (attempt 1/3): APIConnectionError
   🔌 Provider: kimi-coding-cn  Model: kimi-k2.5
   🌐 Endpoint: https://api.moonshot.cn/v1
   📝 Error: Connection error.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • run_agent.py:
    • Added _get_proxy_from_env() function to read proxy from environment variables
    • Modified httpx Client creation to explicitly pass proxy parameter

How to Test

  1. Set proxy environment variable:

    export HTTPS_PROXY=http://your-proxy:8080
  2. Configure kimi-coding-cn provider:

    hermes model  # Select kimi-coding-cn
  3. Run a chat:

    hermes chat -q "Hello"
  4. Before this fix: Connection error. After this fix: Request succeeds.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've tested on my platform: macOS 15.x

Documentation & Housekeeping

Technical Details

The issue is in httpx's Client initialization:

allow_env_proxies = trust_env and transport is None

When a custom transport is provided, allow_env_proxies becomes False, and httpx won't read proxy settings from environment variables. This fix explicitly reads and passes the proxy URL to ensure it's always used when configured.

heykb added 2 commits April 19, 2026 20:00
…ansport

When creating httpx.Client with a custom transport for TCP keepalive,
proxy environment variables (HTTP_PROXY, HTTPS_PROXY) were ignored because
httpx only auto-reads them when transport=None.

Add _get_proxy_from_env() to explicitly read proxy settings and pass them
to httpx.Client, ensuring providers like kimi-coding-cn work correctly
when behind a proxy.

Fixes connection errors when HTTP_PROXY/HTTPS_PROXY are set.
The kimi-k2.5 model requires temperature=1.0, not 0.6. The API returns:
"invalid temperature: only 1 is allowed for this model"

Move kimi-k2.5 from _KIMI_INSTANT_MODELS to _KIMI_THINKING_MODELS so it
gets the correct fixed temperature of 1.0 instead of 0.6.

Update tests and docstring to reflect the correct behavior.
@teknium1

Copy link
Copy Markdown
Contributor

Merged the proxy fix via #12657 — your commit 42b394c3 was cherry-picked with your authorship preserved in git log (now 023208b1 on main). Thanks @heykb for catching this and for the clean _get_proxy_from_env() helper!

I left the kimi-k2.5 temperature contract change out of the salvage — it's a separate behavioral decision that needs its own triage against the Moonshot docs and the kimi-for-coding endpoint. Happy to look at that on its own if you want to open a follow-up PR for just those changes.

The proxy portion fixes a Cloudflare 403 regression for users on proxy setups (WSL2 + Clash, corporate egress) that was introduced by #11277.

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.

2 participants