在配额、速率限制或身份验证失败后轮换已配置的 LLM API 密钥。
安装
# npm 包(预构建)
dsh plugin --profile web add @m1khal3v/dsh-llm-key-rotation
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:m1khal3v/dsh-llm-key-rotation
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
该插件的 README 只有英文版本。
⚡️ Highlights
- 🔄 Invisible to Agent & User: Request fails with quota/rate limit → plugin hot-swaps the key → request retries and succeeds seamlessly.
- 🎛 Native Web UI: List every key a provider can use and toggle rotation right inside Settings.
- 🧠 Smart Anti-Spin: Cooldown discipline prevents infinite loops if all your keys are exhausted.
- 🧼 Zero Core Patches: Plugs cleanly into the Harness recovery waterfall — safe to install, safe to remove.
🛠 How It Works
┌─────────────────┐ 429 / QUOTA / AUTH ┌──────────────────────┐
│ Model Request │ ───────────────────────────────────► │ llm-key-rotation │
└─────────────────┘ └──────────┬───────────┘
▲ │
│ { kind: 'retry' } │ 1. Pick next key
│ (Adapter re-resolves key) │ 2. Hot-swap env ref
└──────────────────────────────────────────────────────────┘
- You keep working with your currently-active key as usual.
- If a request fails (
QUOTA,RATE_LIMIT, orAUTH), the plugin loads the next key from your configured chain. - The turn retries with the new key, and future requests continue with the working key.
🚀 Quick Start
1. Install the plugin
dsh plugin --profile web add @m1khal3v/dsh-llm-key-rotation
2. Configure via Web UI
Navigate to Settings → Plugins → Key Rotation:
- Toggle on rotation for your target provider.
- Select your trigger codes (default:
QUOTA,AUTH). - Click Add key, paste all the keys you want that provider to rotate through, and hit Save.
(Keys are safely saved to the Harness credential store).
⚙️ Behavior & Good to Know
- Smart Rotation Window (300s): During consecutive failures, the plugin walks forward through your configured keys. If no failures occur for >5 minutes, the chain resets to start from the top again.
- Interplay with
dsh-llm-retry:QUOTAandAUTHrotate immediately.RATE_LIMITis handled bydsh-llm-retryfirst (with backoff). To rotate instantly on 429 errors instead, simply removeRATE_LIMITfrom your provider'sretryableCodes.
- Live Terminal Logs: Watch rotation events in real time right in your
dshterminal:
(Secret values are never logged — only provider names, indices, and error codes).[llm-key-rotation] rotated provider="opencode-go" chain[0]→"OPENCODE_GO_API_KEY" (QUOTA)
🧑💻 Development
pnpm install
pnpm run verify # typecheck + test
pnpm run build
📄 License
链接
同类插件
bowenliang123/dsh-context★ 1903
DSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
Han-1413141/dsh-cost-meter★ 379
会话与当日 API 费用统计、预算图框(已用%)、官方余额、历史看板,支持峰谷计价与官方价格一键同步。
wssfk12138/dsh-damage-pulse★ 248
在 DSH Web 界面追踪 DeepSeek Token 用量、单次与会话费用及账户余额,并显示缓存感知的扣费动画。
zh667/TokenLedger★ 204
侧边栏用量面板:把 Token 归属到实际服务该请求的中转站,站点从已有的 provider 配置中读出,无需额外配置;含今日/本月/累计三窗口、按站点与模型下钻、一年活跃度热力图,以及 New API / Sub2API / DeepSeek 余额。
Ychris12138/dsh-usage-stats★ 170
多供应商用量看板:按供应商/模型统计 Token 与日期下钻,统一展示账户余额,并追踪 OpenCode Go / Z.ai 订阅额度。
PolinniZhong/dsh-personal-center★ 118
DeepSeek Harness 个人中心:跨会话用量统计、按模型成本估算、全局自定义指令、外观全局字号、数据驱动的桌面宠物(位图/矢量皮肤)与会话状态概览,纯本地离线运行。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。