Preface¶
When integrating multiple OpenCode Go subscription keys into DeepSeek Harness (dsh), the common need goes beyond just “making it work”: requests need to be distributed across multiple keys, automatic failover is required when a key encounters rate limiting, quota exhaustion, or credential issues, and visibility into cost and quota status is expected. Manually exporting environment variables and determining whether a key is still usable becomes error-prone in multi-key scenarios.
dsh-go-rotator is a dsh plugin that provides load balancing, automatic rotation, and quota management for OpenCode Go subscription keys with DeepSeek Harness.
What Is This¶
dsh-go-rotator is an OpenCode Go subscription key rotator for dsh. It manages multiple keys in the data/ directory within the plugin directory, with the provider resolving the active key on each request via apiKeyEnv. The project is open-sourced under the MIT License, available at https://github.com/echo-xianyu/dsh-go-rotator.
Core Features¶
Per-Request Routing¶
The provider resolves the active key on each request via apiKeyEnv. Multiple keys can coexist in the state, with the plugin deciding which key to use for the current request, thereby distributing the load.
Automatic Rotation¶
When an LLM stream terminates with a RATE_LIMIT, QUOTA_EXCEEDED, AUTH, or INVALID_CREDENTIAL error, the plugin cools down the current key and switches to another available key.
Cost Accounting¶
Successfully completed streams have their costs estimated based on token usage. Rolling window usage (5-hour/weekly/monthly) is written to the state file, while long-term ledgers (daily/monthly/yearly) are written to the statistics file.
Quota Watchdog¶
The plugin can periodically fetch the actual quota of each key from the dashboard, requiring workspaceId and authCookie. When the quota crosses a threshold, the key is automatically disabled.
Web Settings Interface¶
The plugin provides a dsh web client settings page, along with a standalone HTTP API available at http://localhost:7777 by default, allowing external tools to read and write the same state.
Self-Contained Data¶
All data resides in the data/ directory under the plugin installation directory — no absolute paths are required in the configuration.
Installation and Enablement¶
dsh version 0.1.0-rc.6 or higher is required before installation. The following uses version 0.2.0 as an example.
First, install the plugin. If you already have a local tarball, you can run:
dsh plugin --profile <profile> add ./dsh-go-rotator-0.2.0.tgz
During development, you can also reference the source directory directly:
dsh plugin --profile <profile> add file:/path/to/dsh-go-rotator
After installation, configure the opencode-go provider in $DSH_HOME/settings.yaml. Only the verified provider fields are shown here:
llm-pi-ai:
providers:
opencode-go:
api: openai-completions
baseURL: https://opencode.ai/zen/go/v1
apiKeyEnv: GO_ROTATOR_ACTIVE_KEY
This step allows dsh to access the OpenCode Go openai-completions endpoint through the opencode-go provider, resolving the active key provided by the plugin via GO_ROTATOR_ACTIVE_KEY.
If you want to route the default model to opencode-go, you can set it in $DSH_HOME/cordis.patch.yml:
provider: opencode-go
model: deepseek-v4-flash
Finally, run:
dsh --profile <profile> "hello"
Use Cases and Notes¶
This plugin is suitable for users who use multiple OpenCode Go subscription keys in dsh and require automatic failover and quota visibility.
It is recommended to review the source code and the MIT License before use. The plugin runs with the current dsh process permissions — evaluate the security and compliance of the code yourself before installation.
The plugin stores keys in the state file but never prints them or writes them to logs. The data/ directory is not included in the npm package and is excluded via .gitignore. State file writes use atomic operations (tmp + rename), making them safer in multi-process concurrency scenarios. The first run performs a fresh initialization without legacy path detection or migration logic.
Links¶
- GitHub:
https://github.com/echo-xianyu/dsh-go-rotator