Upstream now fingerprints the client on every tier. The gateway's request shape
no longer passes, so both the keyless free tier and the keyed lanes come back as
403 {"type":"error","error":{"type":"FreeTierError","message":"OpenCode's
free tier can only be used from within OpenCode..."}}
Reproduced by replaying the gateway's exact request against the live endpoint,
and cross-checked by capturing what the official client (@opencode/cli@2.0.29)
puts on the wire.
Three things are checked, and each one alone is enough to fail the request:
1. Endpoint. Keyless traffic moved off /zen onto https://opencode.ai/inference.
Keyed traffic still uses /zen (or /inference/openai), so the anonymous lane
gets its own `upstream.anonymous` base instead of sharing `upstream.zen`.
2. Header shape. Upstream wants the client's own headers: a
"opencode/<channel>/<version>/cli" User-Agent, x-opencode-session-id, a bare
40-character hex x-opencode-project, and no x-opencode-request. The previous
legacy set — "opencode/1.18.31 (<os> <arch>; <runtime>)" User-Agent, a
"prj_" prefixed project, and the gateway's x-opencode-request — is rejected
on both the keyless and the keyed lanes.
3. Tool definitions. Every tool whose name upstream recognises must carry the
genuine OpenCode definition; a synthesised stub that only reuses the name is
rejected. The gateway now embeds the real definitions captured from the
official client and uses them for the tools it injects, and rewrites any
downstream tool that happens to reuse a recognised name. Unrecognised tool
names still pass through untouched, so downstream function calling keeps
working. `anonymousCoreTools` also drops "bash" in favour of "shell", since
"bash" is a recognised name whose genuine definition the gateway does not
have.
Verified against the live endpoint on both lanes: non-streaming, streaming,
function calling with a downstream tool, /v1/messages and /v1/responses all
return 200. Unit tests cover the request headers, the genuine tool definitions
and the tool rewrite.
Upstream began rejecting anonymous free-tier requests whose
x-opencode-session does not match ses_[0-9a-f]{12}[0-9A-Za-z]{14}
with 403 FreeTierError. Map every downstream identity into that
shape deterministically (preserving native sessions), and bump
the impersonated client version to 1.18.31.
Move the command to cmd/opencode2api and group production code into
configuration, gateway, protocol, model, admin, telemetry and helper packages.
Keep shared state private behind context, metrics and runtime interfaces.
Remove the requested test files and replace test-only CI jobs with vet/build
checks. Update Docker and release build paths, preserve version injection and
make the WebUI an explicit embedded asset package.
Add directory trees and source reading guides to both READMEs. Anchor binary
ignore rules so the command package is tracked.