dsh-llm-proxy-router: Provider-Based Proxy Routing for LLM Requests

Preface

When configuring multiple model Providers simultaneously in DeepSeek Harness (DSH), network paths are often inconsistent: Gemini and OpenRouter typically require a proxy for access, while DeepSeek, Kimi, MiniMax, and GLM can often connect directly within China. If HTTPS_PROXY is written into the process environment, the proxy will apply to all outbound HTTPS traffic. Consequently, direct-connect Providers will also be routed through the proxy, increasing latency and potential failure points; conversely, without a proxy configured, overseas Providers become completely unavailable.

The following introduces the community plugin dsh-llm-proxy-router (Maintainer: LostAbaddon, Category: Networking Tools). It changes the decision of “whether to use a proxy” to a per-entry determination based on the target hostname. Rules can be modified in the DSH settings page, and changes take effect immediately upon saving, without requiring a restart.

What is this

dsh-llm-proxy-router is a bundle plugin for DSH: it configures which LLM requests are sent via an HTTP/HTTPS proxy based on the Provider, while keeping others on a direct connection. The proxy address and rules are written to $DSH_HOME/llm-proxy-router/config.json and are not written into the profile’s patch layer, so user configurations generally will not be overwritten during DSH upgrades.

Core Features

Routing Decision Sequence

A single request is judged in the following order; the first match takes precedence:

  1. Global routing switch is off → Direct connection.
  2. No proxy address filled in → Direct connection.
  3. Target is local machine (localhost, 127.0.0.1, ::1, *.local) → Direct connection.
  4. Target host matches a host rule → Use proxy.
  5. Others → Direct connection.

Host rules come from two sources, concatenated in order:

  • Provider Rows: Providers checked with “Use Proxy” come with a set of built-in hostnames (e.g., Gemini corresponds to generativelanguage.googleapis.com, OpenRouter corresponds to openrouter.ai and *.openrouter.ai). Custom hostnames (internal gateways, self-hosted reverse proxies, etc.) can be appended to each row.
  • Additional Host Rules: Independent entries unrelated to Providers, supporting * wildcards, which can be disabled individually.

Hostname matching supports exact match (e.g., api.openai.com), subdomain wildcards (e.g., *.openrouter.ai, does not match the bare domain), and the full wildcard *.

Regardless of the UI settings, the following Providers will never use a proxy: deepseek, deepseek-official, ollama, lmstudio.

Settings Page

Path: Settings → Models group, under “LLM Proxy Routing”.

Area Function
Global Switch When off, all requests immediately revert to direct connection, but configuration is retained
Proxy Address e.g., http://127.0.0.1:7890; if protocol is omitted, it is treated as http://; supports http://user:pass@host:port
Test Proxy Initiates a real CONNECT tunnel handshake to the proxy and reports the result and latency, without relying on third-party detection services
Provider List Check per row whether to use proxy; displays covered hostnames, allows appending custom hostnames
Additional Host Rules Independent hostname entries
Status Line Currently active proxy address and number of rules

Saving writes to disk immediately and takes effect instantly.

Implementation Highlights (For Troubleshooting)

On the Host side, a routing patch is installed on the process’s globalThis.fetch, overriding the outbound path shared by various model adapters within the profile. When a proxy rule is matched, it uses undici’s ProxyAgent to route through a CONNECT tunnel; if not matched, it falls back to the original fetch. The patch is fully restored when the plugin is uninstalled.

The browser side is a self-contained client module that registers the settings page in the settings.section slot and reads/writes configuration via /api/dsh-llm-proxy-router/*. Interfaces exposed by the Host include: GET /state, POST /config, POST /test, POST /reset, POST /selftest, GET /diagnostics.

Installation and Activation

The installation method provided in the official README: the packaged directory itself is an installable bundle. Use plugin_manager to install it (replace <absolute_path_to_package_directory> with the absolute path of the plugin directory on your machine):

plugin_manager install_bundle <absolute_path_to_package_directory>

If DSH reports restart-required after installation, simply restart DSH once. The bundle’s patch only inserts a single Host entry and does not modify other configurations in the profile.

Typical Usage

Configuring via UI

  1. Open Settings → Models → LLM Proxy Routing.
  2. Enter the proxy address (e.g., local Clash at http://127.0.0.1:7890).
  3. Check “Use Proxy” for Providers that require bypassing restrictions (e.g., Gemini, OpenRouter); leave domestic direct-connect Providers unchecked (and built-in exclusions like deepseek will not use the proxy regardless).
  4. If you have a self-hosted reverse proxy or internal gateway, append the hostname in the corresponding Provider row or in “Additional Host Rules”.
  5. Use “Test Proxy” to confirm tunnel availability, then save the configuration.

Configuration File Example

After the first save, the configuration is governed by $DSH_HOME/llm-proxy-router/config.json. Structure example:

{
  "enabled": true,
  "proxyUrl": "http://127.0.0.1:7890",
  "providers": {
    "gemini": { "enabled": true, "extraHosts": [] },
    "openrouter": { "enabled": true, "extraHosts": ["openrouter.internal"] },
    "deepseek": { "enabled": false, "extraHosts": [] }
  },
  "hosts": [
    { "pattern": "*.openrouter.ai", "enabled": true, "note": "" }
  ]
}

Scenarios and Notes

Who is it for: Users mixing multiple domestic and international LLM Providers in DSH, who want “proxy for those that need it, direct for those that don’t,” and do not want to rely on a global HTTPS_PROXY one-size-fits-all approach.

Permissions & Security: The plugin runs with the current DSH process permissions; please review the source code and MIT license before installing. When using the proxy, the tunnel layer does not perform secondary verification of the target certificate (requestTls.rejectUnauthorized: false), facilitating compatibility with private MITM proxies, but also meaning that certificate verification is not performed at this layer.

Known Boundaries (from README):

  • The decision basis is the hostname, not “which Provider initiated the request.” Any request within the same process accessing a host within the rules will go through the proxy, while accessing other hosts will not—this is not the same concept as “isolation by Provider.”
  • Only supports HTTP / HTTPS proxies, does not support SOCKS.
  • By default, it only affects model-related requests passing through the fetch patch path; other traffic like search, web scraping, MCP, etc., connects directly by default unless the accessed host is explicitly written into the rules.

The DSH ecosystem emphasizes “everything is a plugin”; community directories like SkillHub are independent sites and have no official affiliation with DeepSeek / High-Flyer. This plugin currently has 0 stars on GitHub; features and boundaries are subject to the repository README.

Conclusion

Through the steps above, you can maintain a setup in a single DSH configuration that includes both direct connections to domestic models and proxy access to overseas APIs, keeping the rules in an editable and persistent configuration. For details, please refer to the SkillHub Directory Page and the GitHub Repository.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye