Go to file
apale7 4264ada4f8 fix: improve ops alias routing
Accept ops-prefixed alias names in the local proxy so OpenCode requests do not fail on model lookup. Add clearer proxy diagnostics and fix alias list target state output to simplify ops troubleshooting.
2026-04-17 09:22:09 +08:00
.opencode 产出prd 2026-04-17 00:20:07 +08:00
.trellis fix: improve ops alias routing 2026-04-17 09:22:09 +08:00
cmd/ops feat: add ops MVP failover proxy 2026-04-17 07:51:42 +08:00
internal fix: improve ops alias routing 2026-04-17 09:22:09 +08:00
.gitignore feat: add ops MVP failover proxy 2026-04-17 07:51:42 +08:00
AGENTS.md use chinese & caveman 2026-04-17 07:53:04 +08:00
go.mod feat: add ops MVP failover proxy 2026-04-17 07:51:42 +08:00
go.sum feat: add ops MVP failover proxy 2026-04-17 07:51:42 +08:00
README_EN.md feat: add ops MVP failover proxy 2026-04-17 07:51:42 +08:00
README.md feat: add ops MVP failover proxy 2026-04-17 07:51:42 +08:00

opencode-provider-switch (ops)

A tiny local proxy for OpenCode that gives you one stable model alias routed to multiple upstream providers with deterministic failover.

  • Expose one custom provider ops to OpenCode.
  • Configure logical aliases (ops/gpt-5.4, etc.).
  • Each alias has an ordered list of upstream provider/model targets.
  • When the primary upstream returns 5xx/429/connect error before any stream bytes are flushed, ops transparently retries the next target.
  • Once a stream has started, the upstream is locked for the rest of that request — no mid-stream splicing.

Protocol: OpenAI Responses (POST /v1/responses) only. Streaming supported.

Install

go build -o ops ./cmd/ops

Quick start

# 1. add upstream providers
ops provider add --id su8   --base-url https://cn2.su8.codes/v1 --api-key sk-...
ops provider add --id codex --base-url https://api-vip.codex-for.me/v1 --api-key sk-...

# 2. create alias and bind targets in priority order
ops alias add --name gpt-5.4
ops alias bind --alias gpt-5.4 --provider su8   --model gpt-5.4
ops alias bind --alias gpt-5.4 --provider codex --model GPT-5.4

# 3. push alias exposure into OpenCode global config
ops opencode sync

# 4. run the proxy
ops serve

Inside OpenCode you can now pick ops/gpt-5.4.

Import providers from an existing OpenCode config

ops provider import-opencode             # reads global OpenCode config
ops provider import-opencode --from ./examples/opencode.jsonc

Only @ai-sdk/openai custom providers with a baseURL and apiKey are imported. Everything else is out of MVP scope.

Doctor (static)

ops doctor

Runs structural checks only — never issues real upstream requests.

CLI reference

  • ops serve — run the proxy
  • ops doctor — validate config
  • ops provider {add,list,remove,import-opencode}
  • ops alias {add,list,bind,unbind,remove}
  • ops opencode sync [--target FILE] [--set-model ALIAS] [--set-small-model ALIAS] [--dry-run]

Global flag: --config PATH (default $XDG_CONFIG_HOME/ops/config.json).

Debug headers

Every proxied response includes:

  • X-OPS-Alias
  • X-OPS-Provider
  • X-OPS-Remote-Model
  • X-OPS-Attempt
  • X-OPS-Failover-Count

Scope

Out of MVP: Anthropic native, multi-protocol routing, dashboard, billing, latency-based routing, /v1/models discovery, full OpenCode config takeover. See .trellis/tasks/archive/2026-04/04-17-04-17-ops-mvp-design-review/prd.md for the authoritative design notes.