Skip to content

feat(llm): add OpenCode Go OpenAI-compatible gateway - #1218

Open
mari0rh wants to merge 6 commits into
BitterSecurity:mainfrom
mari0rh:feat/opencode-go-gateway
Open

mari0rh wants to merge 6 commits into
BitterSecurity:mainfrom
mari0rh:feat/opencode-go-gateway

Conversation

@mari0rh

@mari0rh mari0rh commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

Adds OpenCode Go as an OpenAI-compatible gateway, so a deployment that only sets OPENCODE_GO_API_KEY resolves the tier chain to opencode_go/kimi-k3 (HIGH), opencode_go/glm-5.3 (MID) and opencode_go/deepseek-v4.1-flash (LOW), with those routes present in the generated static config and carrying the x-opencode-session header the endpoint rejects requests without. OpenCode Zen is untouched. Go is a separate base URL, credential name and model inventory; a Go key also authenticates the pay-as-you-go base, so the base URL is what makes a request bill the Go plan instead of the credit balance — that is the only behavioural difference the code encodes.

Changes

  • config/litellm_dynamic_config.py: opencode_go entry in OPENAI_COMPAT_GATEWAYS (documented base https://opencode.ai/inference/go/openai/v1, key OPENCODE_GO_API_KEY) plus OPENCODE_GO_SESSION_HEADERS, applied only to that prefix.
  • model-catalog/catalog.json and overlay.json: four opencode_go/* models with their published per-token rates and limits; User-Agent stays in the catalog, x-opencode-session lives in the overlay provider block. The generator's four outputs (config/litellm.yaml, config/litellm_prod_catalog.json, currentProdModels.ts, configuredModelRoutes.ts) are regenerated, not hand-edited; generate.py --check is clean.
  • decepticon_core/types/llm.py: AuthMethod.OPENCODE_GO_API, HIGH/MID/LOW matrix, and the routing-table row in the module docstring.
  • decepticon/llm/factory.py: env detection, default priority next to Zen and before the local endpoints, decepticon-cli auth label.
  • .env.example, docs/setup-guide.md, docs/verification/opencode-go-20261130.md.
  • Tests: dynamic route shape, header scoping, tier matrix, static-route price and header, auth activation.

Intent

  • Issue / ADR this satisfies: vouch request #1212, approved by @PurpleCHOIms. No ADR: this is one more row in two existing tables, not an architectural choice.
  • Anti-goal (one thing this PR could have done but deliberately does not): it does not give the session hint per-conversation granularity. The proxy serves many agents and has no conversation id to forward, so one process-wide constant is sent; adding a async_pre_call_hook to mint per-conversation ids is a separate change with its own middleware surface.

Two decisions worth flagging for review:

  1. Prices are the published per-token rates, not $0 plus pricing_zero_reason. The minimax_plan precedent models a subscription whose plan has no per-token rate card. Go does publish one: GET .../models returns cost.text, and Go's own usage windows are denominated in dollars from those rates. With real model_info prices LiteLLM reports a non-zero x-litellm-response-cost, so DECEPTICON_BUDGET__* caps keep enforcing on these routes. With $0 the routes would report no spend and a configured cap would silently not bind.
  2. HIGH is kimi-k3, MID is glm-5.3. Every other gateway's HIGH is its most expensive frontier route, and kimi-k3 (3.00/15.00 per 1M) sits above glm-5.3 (1.40/4.40). The vouch discussion did not fix the mapping; tiering by published rate keeps it consistent with the rest of the table.

Follow-up required: the onboarding wizard (separate PR)

decepticon onboard offers no OpenCode entry at all — neither plan. That is not cosmetic, and it should not be read as "Go is unsupported":

  • The wizard's provider list is a fixed Go table (clients/launcher/cmd/onboard.go, methodOrder), which predates the OpenAI-compatible gateway family: Zen, Vercel, HF, Venice, NanoGPT, Synthetic, ZenMux, Qianfan, Cloudflare and Cheaper Inference are all absent from it too. The gap is pre-existing, not introduced here.
  • Go and Zen share one key. A Go subscriber therefore has no correct choice in the wizard today: if they point "Custom OpenAI Endpoint" at the Zen base, or set OPENCODE_API_KEY in .env (the documented route for every gateway in this family), the request is served by Zen and billed to the credit balance instead of the monthly Go plan, with no error. Verified on 2026-11-30 with the same credential: zen/v1 → usage.opencode.billing_source = "balance", inference/go → "go".
  • The Python side cannot detect it: both bases accept the same key, so there is no validation the backend could add.

This PR reduces the risk rather than removing it at the point of use: it adds the correct .env route, the tier mapping, the picker entry and an explicit warning in docs/setup-guide.md. Removing the footgun needs a second PR against clients/launcher: one "OpenCode" wizard entry with a plan choice that writes OPENCODE_GO_API_KEY for Go and OPENCODE_API_KEY for Zen. That follow-up is #1219: two adjacent entries (OpenCode Zen / OpenCode Go) so the plan is chosen explicitly, and it depends on this PR (AuthMethod.OPENCODE_GO_API and the route must exist first).

Blast radius

  • Tier-auto — tests, internal refactors, non-policy docs, lockfile-only dep bumps.
  • Tier-delegate — agent prompts, skill bodies, middleware internals, web/CLI features.
  • Tier-supply-chain — CI/workflows, package manifests and lockfiles, install script, compose / Dockerfiles, plugin contracts, .semgrep/**.

No prompt, skill, OPSEC wording, RoE, SafeCommand, EngagementContext, semgrep rule, compose file or dependency changes.

Diff budget

  • My diff fits the budget.
  • Or I am requesting large-diff-approved from @PurpleCHOIms because:

Composition, since the raw insertion count is large: exactly 10 non-test, non-doc files (the limit). Four are generator outputs (config/litellm.yaml, config/litellm_prod_catalog.json, currentProdModels.ts, configuredModelRoutes.ts) that CI's drift check rejects editing by hand. Hand-written code is 30 lines (litellm_dynamic_config.py 17, types/llm.py 10, factory.py 3); the remaining ~350 insertions are four catalog records, two overlay provider blocks and their generated form. One concern: registering one provider.

End-to-end verification

Run on the branch head in WSL2 Ubuntu (same OS family as the CI runner) with Docker Engine 29.9.3, Node 22.23.5, make and Go on PATH, using a live Go key:

  1. make ci-test (the blocking PR lane: uv run --extra mcp pytest -n auto -q -m "not slow") → 6267 passed, 14 skipped in 62.6s; make ci-lint → ruff and format clean, basedpyright 0 errors; make quality-cli → npm audit 0, streaming build, tsc --noEmit, build and vitest all exit 0; make quality-telemetry → 0. make audit-skills-strict → 329 files, 0 violations; make bootstrap-skill-graph + make check-skill-graph → OK (2140 nodes, 5763 edges); go vet ./... + go test ./... → vet 0, all packages ok; pip-audit over 191 pinned requirements → no known vulnerabilities; actionlint 1.7.7 → clean; docker compose config for base/dev/dev+watch → 3/3 valid; model-catalog/generate.py --check → clean and test_catalog.py → 10 passed.
  2. make smoke builds and brings the stack up; with DECEPTICON_SANDBOX_PROVIDER=docker (the default openshell provider needs the openshell compose profile) every service reports healthy.
  3. Against that running stack: GET :4000/v1/models lists opencode_go/{kimi-k3,glm-5.3,deepseek-v4.1-flash,minimax-m3}; POST :4000/v1/chat/completions for opencode_go/kimi-k3 with a read_file tool returned finish_reason: tool_calls, read_file({"path":"/etc/hostname"}), 255 tokens, x-litellm-model-api-base: https://opencode.ai/inference/go/openai/v1 and x-litellm-response-cost: 0.001773; inside the langgraph container a lone OPENCODE_GO_API_KEY resolves HIGH/MID/LOW to the three routes above.
  4. Failure paths: upstream with the key but no x-opencode-session → 400 MissingSessionID; proxy without the key → Missing credentials … with no fallback group. Both are recorded in the verification note.

Not reproduced locally: the hosted multi-arch docker-build / docker-build-arm64 lanes (arm64 emulation) and the live-provider make test-live suite.

Testing

  • make quality passes (Python + CLI + Web) — its four targets were run in WSL2 Ubuntu with Node 22 and each exits 0: ci-lint, ci-test (6267 passed, 14 skipped), quality-cli (audit, streaming build, typecheck, build, vitest) and quality-telemetry.
  • make smoke succeeds (clean local build + OSS-style up + health checks) — images built and every service healthy with DECEPTICON_SANDBOX_PROVIDER=docker; the default openshell provider needs the openshell compose profile.
  • pytest tests/ passes — tests/ is part of the make ci-test selection above (-m "not slow"), which is what CI runs.
  • Every new/changed test was watched to fail without the change and pass with it (test commit precedes the feature commit).
  • Every new/changed code path was executed on my machine (proxies above, plus resolve_chain returning opencode_go/kimi-k3 / glm-5.3 / deepseek-v4.1-flash for a lone Go credential).
  • Manual testing (describe): ruff check (all checks passed), ruff format --check (943 files formatted), basedpyright (0 errors; 0 errors/0 warnings on the three touched runtime files), tsc --noEmit in clients/cli after building clients/shared/streaming (clean), scripts/audit_model_payloads.py (300 routes, 296 concrete chat payloads passed, no provider inference).

Quality Bar self-check

  • No banned pattern from QUALITY_BAR §Banned patterns appears in the diff.
  • No AI-slop signature from QUALITY_BAR §AI-slop signatures survives.
  • Every changed line traces to the stated intent. No drive-by formatting, renaming, or reordering.
  • Every public function I added/changed has explicit type annotations including return type, and every raised exception is a named class.
  • I would merge this PR if a stranger opened it.
  • If I were tired and reviewing this at the end of a long day, I would still merge it.

AI-assisted contribution attestation

Prepared with an AI coding agent and reviewed line by line. No AI co-author trailer is present. Every claim above was produced by running the command on this machine; the items listed as not run were not ticked. The diff adds one provider: no guard rail, isolation limit or OPSEC wording is touched.

Related Issues

Relates to the vouch discussion #1212. No issue is closed by this PR.

Pins the dynamic route shape (base URL, OPENCODE_GO_API_KEY, x-opencode-session),
that no other gateway inherits that header, the HIGH/MID/LOW matrix, the static
route prices and the credential that activates the method. These tests fail on
main today: opencode_go is not a known provider and AuthMethod has no
OPENCODE_GO_API member.
Registers opencode_go on its documented base (opencode.ai/inference/go/openai/v1)
with OPENCODE_GO_API_KEY, sends the mandatory x-opencode-session hint, and maps
HIGH/MID/LOW to kimi-k3, glm-5.3 and deepseek-v4.1-flash. Four catalog records
carry the published per-token rates so budget caps stay enforceable; the four
generator outputs are regenerated rather than edited by hand.
Adds the gateway row to the setup guide and records the observed endpoint
behaviour (missing-session 400, Go vs balance billing, tool calling and
streaming per model) plus the proxy, lint and test runs behind the PR claim.
The previous note described the proxy-only checks and called out an unavailable
Docker engine. The suite was subsequently run in WSL2 Ubuntu, the environment
matching the CI runner: make ci-lint, ci-test (6267 passed), quality-cli,
quality-telemetry, skill audit and graph checks, launcher go vet/test,
pip-audit, actionlint and compose validation, plus the composed stack with a
live tool call through opencode_go/kimi-k3.
The wizard does not offer OpenCode Go yet, and the two plans share a key
format: a Go key pasted into the Zen option is billed to the balance instead of
the Go plan with no error. Record the distinction next to the gateway table.
Links BitterSecurity#1218 under Unreleased and states that the onboarding-wizard entry which
removes the silent balance-billing choice is a separate follow-up PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant