Skip to content

model-relay v0.6.0

Latest

Choose a tag to compare

@cablate cablate released this 19 Oct 20:28
· 22 commits to main since this release

Use Remote Control without losing the relay (proxy.enabled with a local CA constrained to api.anthropic.com), point haiku / sonnet / opus aliases at any provider in one command (setup.mjs alias & /provider alias), and spawn provider subagents on the fly (subagent_type: "model-relay:<name>") without .claude/agents/*.md files or restarting your session. The /provider panel also adds live toggles for 429 failover (failover.chain), retries (retry.enabled), and Remote Control (f / t / x).

Upgrading: Pull the latest version or run claude plugin update model-relay@model-relay. Run node tools/setup.mjs migrate --go if you want to clean up legacy config keys.

Added

  • Remote Control with the relay still in the path (HTTPS proxy mode): Claude Code keeps api.anthropic.com as its address, which Remote Control requires, and uses the relay as its HTTPS_PROXY. The relay answers for api.anthropic.com with its own certificate and routes model calls exactly as before (providers, sticky 429 failover, retries); token refresh, Remote Control traffic and WebSocket upgrades pass to Anthropic unchanged, and every other host is a plain byte tunnel. Opt-in: off by default, so the router never acts as an open proxy for anyone who does not use Remote Control. Setting: proxy.enabled.
  • Name-constrained local certificate authority: The CA can only vouch for api.anthropic.com, its private key is discarded after it signs the one leaf certificate, and only processes that carry NODE_EXTRA_CA_CERTS trust it. Without a usable certificate the relay tunnels api.anthropic.com untouched, so Claude Code keeps working.
  • setup.mjs proxy and setup.mjs rc: proxy status|enable|disable|renew (add --go to apply) switches settings.json between API-address mode and proxy mode, keeps a settings.json.relay-backup copy and refuses settings it does not own; rc starts the router when needed and then runs claude remote-control.
  • Failover chain: failover.chain lists the providers that take over, in order. When Claude hits its limit the first one answers, and with retry.failover a provider that keeps failing hands the request to the next one, never back to one it already tried. A provider can override this with providers.<name>.fallback (false for nobody, or its own list).
  • Retry master switch: retry.enabled set to false turns retrying off everywhere and keeps the other retry settings for later.
  • Switches in the /provider panel: three rows turn 429 failover, retry and Remote Control on or off (hotkeys f, t, x). Remote Control asks for confirmation first because it rewrites settings.json; the panel changes the file through the same set and proxy commands of setup.mjs.
  • Config commands in setup.mjs: set changes one switch or list after validating it, providers shows routes, failover and retry per provider, remove deletes a provider from the file and from every failover list, and migrate moves an old file to the current layout. Edits keep a .relay-backup copy, tokens are never printed, and the router reads the result on its next request.
  • First-class model alias management (setup.mjs alias & /provider alias): Inspect or point haiku, sonnet, opus, or subagent (CLAUDE_CODE_SUBAGENT_MODEL) at any provider or back to Claude in one command, keeping ~/.claude/settings.json (ANTHROPIC_DEFAULT_*_MODEL) and ~/.claude/model-relay.json (matchModels) in sync. /provider and the panel now display model aliases separately from 429 failover and support /provider alias|failover|retry|rc directly from the prompt.
  • Dynamic model-relay:<provider> subagent types ($.agent.register & agent.spawn): Because Claude Code's Agent tool validates model against "sonnet"|"opus"|"haiku"|"fable", the plugin dynamically registers model-relay:<name> (such as model-relay:glm and model-relay:gemini) with full parent tools and the provider's model ID, and locks that model in on('agent.spawn')—no static .claude/agents/*.md file or session restart needed.

Changed

  • doctor understands proxy mode: doctor --fix no longer puts ANTHROPIC_BASE_URL back when proxy mode is on, and /__health reports proxy state and connection counts.
  • Cleaner config layout: failover holds enabled, chain and cooldownMs, and providers live only under providers. The old top-level baseUrl, token, model, gemini, failoverEnabled, probeEveryMin and failoverProvider still work and are read as if migrated; migrate --go rewrites the file with the same behaviour.
  • doctor checks the config: it warns about an old layout, failover names that match no provider, and a model name that another provider's matchModels claims first, and its failover line shows the chain and the cooldown.
  • /__health reports the switches: failoverChain and config show what the router is really doing, so the panel never guesses.

Fixed

  • failover.cooldownMs was ignored: the documented setting had no effect because the router read probeEveryMin. failover.cooldownMs now sets how long new sessions stay off Claude, with a one-minute minimum.
  • A half-saved config no longer fails requests: the router keeps the last good config when the file cannot be read for a moment, and the setup.mjs commands write files in one step.
  • Claude model names matched via matchModels are now rewritten on the wire: when a request carrying a claude-* model (such as a hardcoded claude-haiku-4-5-20251001) matches a provider's matchModels, the router now rewrites the body's model field to that provider's target model instead of forwarding the claude-* name unchanged.

繁體中文

支援保留轉發站的手機 Remote Control(proxy.enabled 搭配只限 api.anthropic.com 的本機 CA)、一行指令設定 haiku/sonnet/opus 模型別名分流(setup.mjs alias 與 /provider alias),並動態註冊可直接派工的供應商子代理(subagent_type: "model-relay:<name>"),免建 .claude/agents/*.md 也免重開對話。/provider 互動面板同步新增 429 備援(failover.chain)、失敗重試(retry.enabled)與手機遙控三列開關(熱鍵 f/t/x)。

升級: 拉取最新版本或執行 claude plugin update model-relay@model-relay。若想整理舊版設定鍵,可執行 node tools/setup.mjs migrate --go。

新增

  • 轉發站留在路徑上也能用 Remote Control(HTTPS 代理模式): Claude Code 維持 api.anthropic.com 當位址(Remote Control 的要求),改把轉發站當成它的 HTTPS_PROXY。轉發站以自己的憑證代答 api.anthropic.com,模型請求照舊分流(供應商、429 黏著備援、重試);token 更新、Remote Control 流量與 WebSocket 升級原封不動交給 Anthropic,其他網站則是單純的位元組通道。選用功能:預設關閉,沒用 Remote Control 的人,轉發站不會變成開放代理。設定:proxy.enabled。
  • 限定網域的本機憑證授權單位: 這個 CA 只能為 api.anthropic.com 背書,簽完唯一的那張葉憑證後私鑰立即丟棄,而且只有帶 NODE_EXTRA_CA_CERTS 的程序才會信任它。沒有可用憑證時,轉發站會把 api.anthropic.com 原封不動轉送,Claude Code 照常運作。
  • setup.mjs proxy 與 setup.mjs rc: proxy status|enable|disable|renew(加 --go 才會套用)在 API 位址模式與代理模式之間切換 settings.json,保留 settings.json.relay-backup 備份,且不會碰不屬於轉發站的設定;rc 會在需要時先啟動轉發站,再執行 claude remote-control。
  • 備援名單: failover.chain 依序列出接手的供應商。Claude 額度用完時由第一個回答;開啟 retry.failover 後,持續失敗的供應商會把請求交給下一個,不會回頭找已經試過的。供應商可以用 providers.<name>.fallback 覆寫(false 代表不交給任何人,或自己的清單)。
  • 重試總開關: retry.enabled 設為 false 即全面停止重試,其他重試設定會保留,之後再開即可。
  • /provider 面板上的開關: 三列開關可開關 429 備援、重試與 Remote Control(熱鍵 f、t、x)。Remote Control 會改寫 settings.json,所以先確認再執行;面板是透過 setup.mjs 同一組 set 與 proxy 指令修改檔案。
  • setup.mjs 的設定指令: set 驗證後修改單一開關或清單,providers 逐一列出路由、備援與重試,remove 把供應商從檔案與所有備援名單中移除,migrate 把舊格式檔案整理成目前的格式。每次修改都會留一份 .relay-backup 備份、token 一律不會印出,轉發站在下一個請求就會讀到結果。
  • 一鍵模型別名管理(setup.mjs alias 與 /provider alias): 可在單一指令查看或將 haiku、sonnet、opus 與 subagent(CLAUDE_CODE_SUBAGENT_MODEL)指向指定供應商或還原回 Claude,自動同步更新 ~/.claude/settings.json(ANTHROPIC_DEFAULT_*_MODEL)與 ~/.claude/model-relay.json(matchModels)。/provider 與互動面板現在將「別名分流」與「429 備援」分開揭露,並支援直接在對話框輸入 /provider alias|failover|retry|rc。
  • 動態註冊 model-relay:<provider> 子代理類型($.agent.register 與 agent.spawn): 針對 Claude Code Agent 工具 model 欄位只接受 "sonnet"|"opus"|"haiku"|"fable" 的限制,外掛現在會自動為每個供應商動態註冊具備完整父層工具的 model-relay:<name>(如 model-relay:glm、model-relay:gemini),並在 on('agent.spawn') 鎖定該供應商的模型 ID——無須建立 .claude/agents/*.md 或重開對話。

變更

  • doctor 認得代理模式: 代理模式開啟時,doctor --fix 不會再把 ANTHROPIC_BASE_URL 加回去,/__health 也會回報代理狀態與連線數。
  • 設定檔格式更乾淨: failover 底下放 enabled、chain 與 cooldownMs,供應商只放在 providers。舊的頂層 baseUrl、token、model、gemini、failoverEnabled、probeEveryMin 與 failoverProvider 仍可使用,讀取時等同已整理過;migrate --go 會在行為不變的前提下改寫檔案。
  • doctor 會檢查設定: 提醒舊版格式、備援名單裡不存在的供應商,以及被別的供應商的 matchModels 先攔走的模型名稱,備援那一行也會顯示名單與冷卻時間。
  • /__health 回報開關狀態: failoverChain 與 config 讓面板顯示轉發站實際的狀態,而不是猜測。

修正

  • failover.cooldownMs 沒有作用: 文件寫的設定沒有生效,因為轉發站讀的是 probeEveryMin。現在 failover.cooldownMs 會決定新對話離開 Claude 多久,最小一分鐘。
  • 存到一半的設定檔不再讓請求失敗: 檔案暫時讀不到時,轉發站會沿用上一份正常的設定;setup.mjs 的指令也改成一次寫完整個檔案。
  • 經由 matchModels 攔截的 claude-* 請求會正確改寫模型名稱: 當帶有 claude-*(例如 Claude Code 內部寫死的 claude-haiku-4-5-20251001)的請求符合某個供應商的 matchModels 時,轉發站現在會把送往上游的 model 欄位改寫為該供應商的目標模型,不再原樣送出 claude-*。

Full changelog / 完整差異: v0.5.0...v0.6.0