feat(oauth): sign in with OpenCode Console for Zen and Go models
Merged
NE
2mo ago+824+824+012345678901234567890123456789-35-35-01234567890123456789
Adds OpenCode Console as a subscription provider, so agent steps can run on OpenCode Zen and OpenCode Go models with one sign-in.
import { opencodeConsole } from 'e2e/oauth/opencode-console';
const agent = { model: opencodeConsole('deepseek-v4.1-flash') }; // OpenCode Zen, workspace credits
const goAgent = { model: opencodeConsole('go/deepseek-v4.1-flash') }; // OpenCode Go subscription
e2e login opencode-consoleruns Console's RFC 8628 device flow (/console/auth/device/code,supports_org_scope). Approving the code binds the login to one workspace; its id is stored and sent asx-org-idto the Console API andx-opencode-org-idto inference. Refresh tokens rotate.- On its first call
opencodeConsole()reads the workspace config (GET /console/api/config, the one OpenCode reads) and picks the model's API from it: chat completions, OpenAI Responses, Anthropic Messages, or Google.@ai-sdk/anthropicand@ai-sdk/googlejoin the optional peers and load lazily, like@ai-sdk/openaifor Copilot. - Every inference call carries one
x-opencode-sessionper model, which Go requires and Console uses to keep a session on one upstream. - Prompt-cache hints match what the runner adds for OpenAI and Anthropic directly, which it cannot do here because the protocol is only known after the first call: Anthropic breakpoints on the system prompt and, in agent steps, the newest message; the runner's system-prompt cache key and
store: falsefor Responses. providerandmodelIdstay fixed (opencode/<id>,opencode.go/<id>) whichever API serves the model, since the runner reads them before and after the first call.OPENCODE_API_KEY(a Console service account key, the variable OpenCode reads) replaces the stored login inopencodeConsole().e2e modelsstill reads the stored login.e2e models opencode-consolelists enabled models tagged Zen or Go, leaving out Zen's free models.e2e initoffers OpenCode Console as a subscription preset.
flowchart LR
A["opencodeConsole(id)"] --> B{first call}
B --> C["GET /console/api/config"]
C -- "npm per model" --> D["chat completions"]
C --> E["Responses: cache key, store false"]
C --> F["Anthropic Messages: cache breakpoints"]
C --> G["Google"]
C -- "unreadable" --> D
D & E & F & G --> H["opencode.ai/inference[/go]/…<br/>x-opencode-session, x-opencode-org-id"]
Verified
Ran it locally: yes
e2e login opencode-consolethrough the built CLI against a real Console workspace with a Go subscription;e2e models opencode-consolelisted 88 models (59 Zen, 29 Go).- Testbed agent suites (
tests-agent/act.e2e.ts,tests-agent/judgments.e2e.ts) through the built CLI with--no-cache --ai-trace, on a temporary config usingopencodeConsole():
| Model | API | Tests | Cached input |
|---|---|---|---|
claude-haiku-4-5 (Zen) | Anthropic Messages | 9/9 | 83% (agent steps 85-96%) |
go/deepseek-v4.1-flash | chat completions | 9/9 | 55% (misses are mostly the canvas step's screenshots) |
Test Files 2 passed (2)
Tests 9 passed (9)
AI 180.8k tokens · 83% cached · 30 model calls · opencode/claude-haiku-4-5
- A forced tool call (what agent steps send) succeeded on
deepseek-v4.1-flash,go/deepseek-v4.1-flash,gpt-6-luna,go/gpt-6-luna,claude-sonnet-5, andgemini-3.1-pro. - Two identical ~4.4k-token calls: Anthropic Messages went from 0 cached tokens on the second call without breakpoints to 4,416 of 4,419 with them; Responses (
gpt-5-nano) read 4,352 of 4,422. OPENCODE_API_KEYwith a real Console service account key, a broken stored login in place: a Zen and a Go call both returned 200, every request carried the key as the bearer and no workspace header.