Preface¶
When using OpenAI-compatible interfaces within DeepSeek Harness (DSH) while sandwiching a reverse proxy like LiteLLM in between, a common requirement is to pass session-related HTTP headers (e.g., x-opencode-session) to the upstream. Experiments show that simply adding request headers on the client side often results in an upstream 500 error after passing through LiteLLM. However, placing the same information into the extra_headers field of the JSON body allows the proxy to forward it, resulting in an upstream 200 response.
DSH’s built-in llm-pi-ai adapter has limited forwarding capabilities for whitelisted fields and cannot inject extra_headers purely via configuration like modifying the body arbitrarily. Consequently, community session plugins that rely on “adding HTTP headers only” are ineffective in this link. dsh-litellm-extra-headers is a host plugin published by maintainer chenyifawan-cell (Category: Networking Tools). On matched providers and upstream hosts, it patches globalThis.fetch to write extra_headers into the JSON body of POST .../chat/completions—this is the injection point specified in the README that remains effective when relaying through LiteLLM.
The following section describes the plugin’s positioning, configuration methods, and usage notes.
What is this¶
- Name:
dsh-litellm-extra-headers(npm package name is the same, current version referenced is0.1.0) - Maintainer: chenyifawan-cell (GitHub:
chenyifawan-cell/dsh-litellm-extra-headers) - License: MIT
- Summary: A host plugin for DSH that merges
extra_headers: { "<header>": "<value>" }into the body of OpenAI-compatible chat/completions requests for configured provider routes and upstream hosts, used to bypass the issue where proxies like LiteLLM discard client HTTP headers.
Community Catalog Page: https://www.skillhub.cn/plugins/chenyifawan-cell/dsh-litellm-extra-headers
Source Code & Docs: https://github.com/chenyifawan-cell/dsh-litellm-extra-headers
Why body-level extra_headers are needed¶
The conclusions verified in the README can be summarized into four points:
- Client HTTP headers are discarded in the LiteLLM hop; the header-only approach results in upstream 500, while switching to
body.extra_headersresults in 200. - DSH’s
llm-pi-aiadapter only whitelists and forwards specific fields inprofileOptions(), and the host side does not exposeoptions.samplingParamscapable of injecting arbitrary body fields. - The existing
dsh-opencode-sessionrelies on adding HTTP headers and defaults toproviders: ['opencode', 'opencode-go'], excluding custom routing keys (such asgwds,go). - pi-ai’s
openai-completionsuses the officialopenaiSDK (documented as v6.40.0) to send requests viaglobalThis.fetch. Therefore, replacingglobalThis.fetchat runtime is currently the available host injection point.
Thus, the documentation advises: Do not rely on adding headers separately elsewhere; when new fields are needed, merge them into the body.
Core Features¶
Dual-layer Whitelist Matching¶
- In the
llm/streamwaterfall: Only whenoptions.providerfalls within the configuredprovidersANDoptions.sessionIdexists, the{ value, provider, model, session }object is placed intoAsyncLocalStorage. - In the
fetchpatch: The body is modified only when the target URL’shostfalls within the configuredhosts.
If neither the routing keys nor the upstream addresses are configured, the plugin remains dormant and logs a warning, avoiding covert field injection into uninformed gateways.
Only modifying chat/completions JSON body¶
Conditions include: method === 'POST', content-type contains application/json, init.body is a string, and the path ends with /chat/completions. If parsing fails, the request is passed through as-is. If extra_headers already exists in the body, it merges them without overwriting existing keys from the caller.
Value Modes¶
The mode determines the source of the value written to extra_headers:
| Mode | Meaning |
|---|---|
session-id (default) |
DSH session id, stable across turns and restarts |
uuid |
A random uuid generated within the process per session |
fixed |
The literal value of the value config item; missing value causes a load-time error |
The default header field name is x-opencode-session, which can be changed via the header setting.
Implementation Constraints (Boundaries from Source)¶
- Zero dependencies (
node:async_hooks/node:crypto/node:fs/promises); Installation and uninstallation usectx.effect(), restoringglobalThis.fetchby reference upon dispose. - If
inputis aRequestobject and the body cannot be read synchronously, it is not modified; currently, pi-ai + openai SDK uses URL + string body, so this path is not triggered. - Only injects
extra_headers; does not perform retries, modify HTTP headers, or modify other body fields.
Installation and Activation¶
The package is published on npm: dsh-litellm-extra-headers@0.1.0. Node requirement is >=20.
# npm (recommended)
dsh plugin --profile web add dsh-litellm-extra-headers
Other installation methods (from README):
# From local directory (recommended for development, link install, changes take effect immediately)
dsh plugin --profile web add ./dsh-litellm-extra-headers
# From packaged artifact
dsh plugin --profile web add ./dsh-litellm-extra-headers-0.1.0.tgz
# From git host (this package is pure JS, no pnpm build script approval needed)
dsh plugin --profile web add github:chenyifawan-cell/dsh-litellm-extra-headers
Once dsh plugin add recognizes the dsh.bundle inside the package, it automatically writes the plugin into the profile’s bundles; the cordis.patch.yml inside the package inserts the corresponding plugin line. After installation, you can verify if this plugin appears in the configuration:
dsh --profile web --dump-config | Select-String litellm-extra-headers
You can also manually write the plugin line into the profile’s cordis.patch.yml (pointing to the package name or index.js path).
Typical Configuration¶
The default providers / hosts inside the package are empty lists (empty = dormant, no injection). You must fill in your routing keys and upstream addresses for it to take effect. Example from README:
- insert:
- id: litellm-extra-headers
name: dsh-litellm-extra-headers
config:
providers: [gwds, go] # Your routing keys
hosts: ["litellm.internal:4000"] # Only inject for these upstreams
header: x-opencode-session
mode: session-id
value: null
debug: false
debugFile: null
Configuration Field Description¶
| Field | Type | Default | Description |
|---|---|---|---|
providers |
string[] |
[] |
Whitelist of options.provider routing keys for llm/stream, must be explicitly listed, case-insensitive |
hosts |
string[] |
[] |
Upstream host[:port] allowed for injection; scheme/path will be normalized, must be explicitly listed |
header |
string |
x-opencode-session |
Key name written to extra_headers |
mode |
session-id | uuid | fixed |
session-id |
Source of the value |
value |
string |
— | Literal value when mode: fixed |
debug |
boolean |
false |
Log ctx.logger.info for every injection decision |
debugFile |
string |
— | Append a JSON line for every injection decision, useful for debugging without console access |
Verification and Troubleshooting¶
The verification order provided by the maintainer in the README:
- Run
npm testin the repository (node --test, 19 unit tests). npm run test:e2e: Local mock upstream +dsh --profile headlesscomparing with and without the plugin line. Assert thatextra_headersappears in the body, values are stable within the same session, the control group lacks the field, anddebugFilecontainsevent: "inject".- Run another round on a machine connected to real LiteLLM, using
debugFileto confirm injection records; compare behaviors betweencurlwith HTTP headers only vs. body withextra_headers.
For daily use, enable debug or debugFile to check provider, model, session, host, path, and reason fields to determine if the whitelist was matched.
Use Cases and Notes¶
Who is it for
- Scenarios where DSH routes to LiteLLM (or similar gateways that only recognize
body.extra_headers) via custom provider routing, the upstream requires session affinity or custom headers, and client HTTP header pass-through cannot be relied upon. - Teams that need fine-grained control over “adding fields only to their own gateways” based on provider + upstream host.
Please be aware before use
- The plugin runs with the current dsh process privileges and patches the global
fetch; review the source code and MIT license before installation to ensure no conflict with existing plugins. - If
providersorhostsare left empty, the plugin deliberately does not work; this is by design, not a malfunction. - Community directories like SkillHub are independent sites with no official affiliation with DeepSeek / High-Flyer; the DSH ecosystem emphasizes “everything is a plugin,” and this package is one such networking tool extension.
Conclusion¶
dsh-litellm-extra-headers solves the combined problem of “LiteLLM relay dropping HTTP headers, and DSH struggling to write to the body directly from configuration”: On explicitly listed providers and upstream hosts, it writes session and other information into extra_headers, allowing the proxy to forward and the upstream to recognize it.
- Catalog Page: https://www.skillhub.cn/plugins/chenyifawan-cell/dsh-litellm-extra-headers
- GitHub: https://github.com/chenyifawan-cell/dsh-litellm-extra-headers