Replace the single-file frontend (app.js, styles.css) with a multi-file
ES module structure served from go:embed, and reorganize the 13 pages
into 8 tabbed pages under 4 navigation groups: runtime (overview,
diagnostics), integrations (access guide, API keys), models (quotas,
rotation), and system (configuration, account).
The redesign adopts a monochrome light/dark design system driven by
prefers-color-scheme, replaces prompt()/confirm() flows with in-page
dialogs, and keeps every management API call and deep link (old hashes
alias to the new pages).
Behavior changes: the log SSE connection now spans the whole console
session and buffers while the stream tab is hidden; quota polling runs
only while its tab is active; the first-run checklist appears on the
overview page and hides once ready.
Also fixes a crash on the rotation page: the persisted state serializes
empty orders and maps as JSON null, which is now normalized before
rendering, with the same defensive handling in the quota and API key
pages.
CI now syntax-checks the ES modules via node --input-type=module, and
the README structure notes are updated.
When every attempt died on the proxy route itself, the gateway answered
with a generic 502 "all upstream attempts failed", pointing operators at
the upstream instead of their proxies.
Attempt errors that fail before a connection to the upstream exists
(proxy dial, CONNECT/SOCKS handshake, tunnelled TLS) are now tagged as
proxy failures on real proxies; direct transports are left untouched.
The anonymous lane also reports a proxy failure when no proxy is healthy.
When the final error is such a failure, the inference and System One
handlers return 503 with type "proxy_error". Any upstream HTTP response
is still forwarded as before, so genuine upstream errors are not
mislabelled.
Translate the whole management console and let the operator pick a language
without replacing the shipped copy.
- webui/i18n.js holds the dictionaries only; the Simplified Chinese text stays
in index.html and app.js and is the fallback for every untranslated string,
so a new locale never rewrites the original.
- Static text uses data-i18n / data-i18n-attr hooks, JavaScript text goes
through t(); a locale switch re-renders both without a reload, and the
choice persists in localStorage under opencode2api.ui.lang.
- The switcher is a flag button in the toolbar and on the login card that
opens a menu of every supported locale. Flags are inline SVG, because
Unicode flag emoji renders as plain letters on Windows.
- Ships 简体中文 (original), English and Tiếng Việt.
- README.vi.md translates the full README; all three READMEs cross-link and
document how to add a locale.
Usage was only broken down by model and tier, so a gateway shared by
several callers could not tell how much each server key consumed.
authenticate now records the fingerprint of the key that matched, and the
monitor keeps requests and tokens per key in usage.server_keys for both
the lifetime and the last hour; the entries sum to the aggregate totals.
/api/api-keys attaches each key's usage and the WebUI shows it in the key
list. Playground traffic borrows the first enabled key, so it is counted
under "playground" instead. Like the rest of the monitor, the figures
survive hot reloads and reset on restart.
Closes#58.
Discovery clients only saw reasoning: true, so harnesses such as OpenClaw
offered just off and max. Reasoning models now list the levels the gateway
forwards in reasoning_efforts and compat.supportedReasoningEfforts, capped
at the probed ceiling for auto, and report a forced or probed level as
default_reasoning_effort. Models with published pricing carry a cost
object, including cache read and write prices now decoded from models.dev.
Closes#65.
With Zen or Go keys configured, every paid model was exposed and routable.
models.free_only rejects models that are not free in both routing entry
points, so /v1/models, inference, rotation aliases and diagnostics agree.
Free models keep their key fallback. The WebUI gains a toggle so saving
the form no longer resets the field, and the docs note that free models
never require a Zen key.
Closes#66.
Carry the canonical ses_ ID into RequestMeta, the request_routed line, the
recent-request ring, and per-session usage maps in the lifetime and hourly
snapshots, including rotation requests. The lifetime map keeps the 500
most recently seen sessions.
Co-authored-by: sk-dev-ai <githubkrishsk@gmail.com>
A quota response with a multi-hour Retry-After cooled anonymous exits for
hours, so after a network change gave them a fresh allowance traffic kept
falling through to key lanes until restart. Cap Retry-After on the
anonymous lane at the 8x backoff ceiling, and clear anonymous cooldowns
when their proxy recovers. Key lanes keep honoring Retry-After in full.
Co-authored-by: CheerC <cheerc@gmail.com>
attempt_timeout_seconds only reached the transport's
ResponseHeaderTimeout, which starts after the request body is written, so
an exit wedged in dial or request write could consume the whole request
budget. When the option is set, each attempt now also carries a context
deadline covering dial, write, headers and, when enabled, the first SSE
event; a committed stream is never cut. Legs record the phase an attempt
died in. A timeout after the upstream already answered is slow generation,
not a broken proxy, so it does not evict the exit.
Co-authored-by: mcheiyue <2267610721@qq.com>
Zen's Responses endpoint rejects max_output_tokens below 16, and clients
such as Claude Code send tiny budgets for background tasks. The 400 was
retried across every anonymous exit before reaching the client. Raise
budgets in (0, 16) to 16 on both the bridged and the same-protocol
Responses paths; nil and larger budgets pass through unchanged.
Co-authored-by: ahoo <ahoo@hroze.org>
A downstream disconnect during the upstream attempt loop is not an
upstream failure, but it was answered with 502 upstream_error on both the
message endpoints and System One. Check wire.ClientCanceled before the
generic 502 and answer 499 client_canceled instead; an exhausted request
budget keeps its 504. Cancels log at debug before the request_failed
warning, so disconnects no longer read as upstream outages.
Co-authored-by: sk-dev-ai <githubkrishsk@gmail.com>
Copy decoded JSON maps and slices directly instead of marshalling and
re-parsing on every call. Both callers pass encoding/json trees, so the
result is unchanged; the doc comment now states that contract.
Co-authored-by: sk-dev-ai <githubkrishsk@gmail.com>
Remove package.json, package-lock.json, .prettierrc.json and
.prettierignore. CI no longer installs npm dependencies or runs the
Prettier check; the WebUI syntax check now calls `node --check
webui/app.js` directly. Docs and .gitignore are updated to match.
`npm run format:check` rejects the embedded tool definitions because the file
was generated with single-space indentation, which fails the "Formatting and
WebUI syntax" job on main.
Reformatted with the repo's Prettier config; no content change. Verified locally
with the exact commands the workflow runs: `gofmt -l .`, `npm run
format:check`, `npm run check:web`, `sh -n docker-entrypoint.sh`, `go vet ./...`
and `go build -trimpath ./cmd/opencode2api`.
OpenCode's 2026-10-14 gate rejects the gateway on every lane again
(403 FreeTierError) while the official CLI keeps working. Probing
byte-identical CLI v2.0.29 replays against the live endpoint isolated
the deltas this changeset fixes on top of #83:
- identity: derive the session from the new x-opencode-session-id
signal too, and stop forwarding the legacy x-opencode-request header
and canonical prj_* project ids upstream — both are instant 403s.
- upstream: the x-opencode-project header keeps one conversation pinned
to one upstream project but is now hashed into the bare 40-hex shape
the client sends (a prj_* value 403s).
- refresh: when the configured anonymous upstream has no models route
(404), fall back to the legacy Zen console listing so the anonymous
catalog still populates.
The endpoint move, genuine tool definitions, and UA shape came in with
#83; the definitions embedded there were re-verified byte-for-byte
against a fresh CLI v2.0.29 capture, including the smallest passing
toolset (shell + read) and per-tool definition checks.
Validation: live end-to-end against opencode.ai — anonymous lane serves
streaming and plain JSON chat completions on big-pickle and
step-5-preview-free, tool calls pass through, all nine exposed free
models probe available, go vet/build/gofmt clean.
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.
The old form marshaled and re-parsed on every call, which is both
slower and lossy: every number decoded as float64 regardless of what
the caller held. The typed clone preserves map, slice, scalar, and
json.Number values, returns nil for nil, and deep-copies nested maps
and slices so callers cannot alias the input.
Every anonymous-lane session draws from one shared upstream IP bucket,
but nothing showed which conversation was draining it. Carry the
canonical ses_ ID into RequestMeta and the request_routed line, the
recent-request ring, and per-model/per-tier style usageSessions maps in
both lifetime and hourly snapshots.
The lifetime sessions map is capped at 500 entries (smallest-first
eviction): session IDs are high-cardinality and an unbounded map grows
forever. Buckets and snapshots are short-lived and stay uncapped.
A downstream disconnect during the upstream attempt loop is not an
upstream failure, but the gateway answered it with 502 upstream_error on
both the message endpoints and System One. Clients that retry on 502
then retried a request nobody cancelled, and telemetry counted a client
behavior as a server failure.
Check wire.ClientCanceled before the generic 502: set meta.Outcome so
the request line reads client_canceled, and answer 499 with a
client_canceled envelope. DeadlineExceeded keeps its 504.