dsh-model-proxy: Routing outbound proxy based on model name with direct fallback when proxy is unavailable

Introduction

In DeepSeek Harness (DSH), a gateway often hosts multiple models, potentially backed by different upstreams. Under the same host, API key, and request format, some models may function normally in the local region, while others fail due to regional restrictions, rate limiting, or access only available via a corporate proxy—this is unrelated to the “neighboring models.”

Process-level environment variable proxies route by host: HTTP_PROXY cannot distinguish between different models on the same host. Routing the entire gateway through a proxy drags normally functioning models into the proxy as well, while setting no proxy at all results in persistent failures for restricted models. This article introduces the community plugin dsh-model-proxy, which reads the model field from each request body, sending only your specified model names through the proxy while leaving others on their original outbound path.

What is this

dsh-model-proxy (GitHub: windwhiterain/dsh-model-proxy, maintained by windwhiterain) is a bundle plugin for DSH, categorized under model inference. In one sentence: it performs outbound proxy routing by model name within the Harness, and optionally falls back to the direct connection path from before the plugin was loaded when the proxy TCP is unreachable.

The plugin runs with the current dsh process privileges; you should review the repository source code and MIT license before installation. The community directory page is available at SkillHub Plugin Page. It is not officially affiliated with DeepSeek or Hithink RoyalFlush.

Routing Mechanism

DSH, pi-ai, and various provider SDKs send requests via globalThis.fetch, ultimately landing on the global dispatcher slot of undici (Symbol.for('undici.globalDispatcher.1')). This plugin occupies that slot and makes decisions in the following order:

  1. Origin: If the target host is not in origins, or the request has no body, the routing prior to plugin loading is maintained.
  2. Proxy Reachability: When fallbackToDirect is enabled and the proxy host:port refuses TCP connections, candidate requests still follow the aforementioned “previous routing” to avoid dragging down all process calls if the proxy goes down.
  3. Model Name: Read the "model" field from the header JSON of the body; if it matches a pattern in models, the request is sent outbound via proxy.

To parse the model name, the plugin only buffers the first few chunks of the body and yields the chunks already read before parsing, without altering chunk boundaries, backpressure, or streaming response behavior. direct in the config refers to the routing already existing in the process before the plugin was installed; if no proxy was set in the startup environment, unmatched requests behave identically to when the plugin was not installed.

Core Configuration

The bundle’s cordis.patch.yml inserts a line with id: model-proxy; you can also hot-reload edit it in <DSH_HOME>/profiles/<profile>/cordis.patch.yml or override the same ID via the settings layer. Invalid configurations will result in activation failure rather than silently routing incorrectly.

- id: model-proxy
  config:
    enabled: true
    proxy: http://127.0.0.1:10793
    origins:
      - opencode.ai
    models:
      - grok-*
      - gpt-*-luna
    fallbackToDirect: true
    probeTimeoutMs: 300
    probeCacheMs: 2000
    peekBytes: 16384
Field Meaning
enabled If false, the interceptor is not installed, and all requests maintain original routing
proxy Proxy endpoint for matched models, supporting http: / https: and optional credentials
origins Only perform model matching for requests to these hosts
models Model name patterns, * matches any character segment
fallbackToDirect If the proxy is unreachable, matched requests switch to the previous routing
probeTimeoutMs TCP connection timeout for reachability probing
probeCacheMs Cache duration for probe results, probing only once for burst requests
peekBytes Maximum number of body bytes peeked to find the model field

Installation and Activation

Register the dependency and bundle in the target profile’s package.json (Path: <DSH_HOME>/profiles/<profile>/package.json):

{
  "dependencies": {
    "dsh-model-proxy": "github:windwhiterain/dsh-model-proxy"
  },
  "dsh": {
    "profile": {
      "bundles": ["@deepseek-ai/dsh-base", "dsh-model-proxy"]
    }
  }
}

For local development, use forms like link:C:/path/to/dsh-model-proxy. Then install the profile and restart dsh once; the bundle’s cordis.patch.yml will write the default model-proxy configuration.

Do not set HTTP_PROXY / HTTPS_PROXY for the dsh process simultaneously. A proxy in the startup environment causes dsh to install a process-level dispatcher, which this plugin treats as a reserved route for “non-proxied models,” contrary to the goal of “proxying only specific models.” Keep the startup environment direct, and let this plugin handle the traffic that needs proxying separately.

Typical Usage

Partial models need proxying or regional proxies within the same gateway

README example: OpenCode Go provides grok-* and gpt-*-luna on the same gateway. In restricted regions, upstreams return unsupported_country_region_territory, while GLM, Kimi, DeepSeek, etc., work normally with the same key and region. Use the YAML above to send only the two restricted model types through a proxy in a supported region, while keeping others direct; if the proxy is turned off, direct models remain unaffected under fallbackToDirect: true.

When calling this gateway directly, requests must still include the x-opencode-session header (otherwise 400 MissingSessionID), regardless of whether this plugin is enabled.

Single provider via corporate proxy

- id: model-proxy
  config:
    proxy: http://proxy.corp.example:3128
    origins: [api.example.com]
    models: ['*']

Entire gateway via a different exit, while other hosts in the process remain unchanged

Same as the example above, set models to ['*']; routing is still decided per request, and hosts added elsewhere later will not be dragged into this proxy.

Diagnostics and Self-Testing

Decisions are written to the host logger, for example:

dsh-model-proxy: models grok-*, gpt-*-luna on opencode.ai via http://127.0.0.1:10793, direct while it is down
dsh-model-proxy: route=proxy via=http://127.0.0.1:10793 reason=model:grok-4.7
dsh-model-proxy: route=direct via=direct reason=model-other:glm-5.3-flash
dsh-model-proxy: route=direct via=direct reason=proxy-down
dsh-model-proxy: route=direct via=direct reason=origin

When uninstalled, the replaced dispatcher is restored to allow subsequent plugins to occupy the same slot.

The repository provides a probe script (requires readable credentials configured):

node probe/smoke.mjs              # Proxy reachable
node probe/smoke.mjs --proxy-down # Fallback path

Applicability and Notes

Who it is for: Agents or gateway maintainers mixing multiple models on the same DSH gateway where only some require independent outbound proxying; deployments requiring other models to remain available when the proxy goes down.

Process-internal effect: The routing logic only takes effect within the dsh process; curl, git, etc., launched by shell tools still follow the startup environment. This plugin intentionally does not modify the latter.

Model name source: Reads model only from the body; requests where it is written only in headers, or where model appears after peekBytes, will not match and remain direct.

Proxy probe scope: The probe answers “is the port listening” and does not verify upstream availability; if the proxy is connectable but the upstream fails, the request will still fail.

One proxy per config entry: To route different model families to different proxies, multiple model-proxy lines are needed (the README states current implementation constraints here; the truncated section does not elaborate fully).

Dependency versions: The plugin pins undici to ~8.10.0; 8.11.0 may break content-encoding decoding when taking over the global dispatcher under Node 24. Similar to the undici constraints of @deepseek-ai/dsh-http-proxy, lockfile upgrades require caution and re-running probe assertions.

Compatibility: Relies on the global dispatcher slot exposed by Node’s built-in fetch; aside from “Node with fetch,” the README does not assume finer version details.

Conclusion

dsh-model-proxy solves the outbound problem under “same API host, different model reachability”: it selects proxies using model name patterns, optionally falls back when the proxy is unreachable, and avoids the side effects of a one-size-fits-all process-wide HTTP_PROXY. Directory and Source Code:

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

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

Xiaoye