Native opencode sends prompt_cache_key (session-sliced ID), plus
safety_identifier, store, and service_tier. The translator dropped
all four, so proxied turns never rode prompt-cache affinity while
native did. Decode, carry, and re-emit on both Chat and Responses
paths, omit-when-absent. Verified live: same-session turns hit 99%
cached upstream after warm-up.
Upstream now rejects anonymous free-tier requests unless they look
like real agent traffic: stream:true plus the core agent tools
(bash/edit/glob/grep/read), returning 403 FreeTierError otherwise.
Normalize the anonymous-lane wire body (force stream:true, inject
minimal definitions for any missing core tools) and collapse the
SSE stream back into the single JSON document non-streaming
clients asked for. Authenticated tiers are untouched.
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.
Preserve request parameters, tool-call completion reasons and retry session
affinity. Bound upstream header waits, stop expired-context scans and add
opt-in redacted request-body diagnostics.
Isolate Playground diagnostics from production pools, report stream failures
accurately, align readiness with discoverable models and honor Docker listen
configuration.
Split Go and WebUI modules by responsibility, add regression tests and CI,
standardize formatting and rewrite the English and Chinese READMEs.
Refs: #6, #18, #19, #20, #21, #22, #23, #24, #25
- capabilityModel now reads the nested modalities.{input,output} object
the catalog actually serves; the old top-level input/output tags
never matched and left both arrays permanently empty.
- Metadata is stored per tier and /v1/models selects by route.Tier,
so same-named Zen/Go models (glm-5, minimax-m3, ...) advertise the
limits of the tier that will serve them. Anonymous routes resolve
to TierZen, keeping the keyless path on Zen metadata.
- Cache schema 2 -> 3; stale flat caches are refused and fall back
to live refresh.
- Untrack config.json.models.catalog.json and ignore
*.models.catalog.json: it is a runtime snapshot, not source.
- Add models_test.go fixtures: nested modalities, tier-split limits,
tier selection, v3 round-trip, v2 rejection.
- Only treat a retry as success on 2xx; on non-2xx/transport failure
close the retry response and restore the original 400 body, logging
reasoning_reference_retry_failed with the retry status.
- Always close the original network body after caching its bytes, and
hand downstream a fresh in-memory reader (also on read errors).
- Narrow the matcher to explicit 'reasoning item/reference ... not
found/expired' errors; add negative cases (unknown reasoning field,
bad reasoning_effort, unrelated 400s).
- Thread a cumulative attempt offset through doUpstreamTiers and the
anonymous path so retry attempts keep numbering [1 2] per request.
- Add HTTP-level tests via httptest upstream: retry success (with
stripped-payload assertion), retry non-2xx restore, non-matching
passthrough, no-op (nothing to strip), cumulative attempt numbers.
Discovery clients (jcode, Pi, etc.) read context_length/context_window and
supported_reasoning_levels at the TOP LEVEL of each /v1/models entry, not
inside a nested metadata object. Emit both: keep the rich nested metadata
object AND mirror context_window/context_length/max_input/max_output/
reasoning/tool_call/structured_output at the top level so standard OpenAI
model-discovery clients get correct context windows without config.
fetchProtocolCapabilities already parses the full opencode catalog but
discards everything except protocol. Capture limit/reasoning/tool_call/
structured_output/modalities per model and expose them in /v1/models so
auto-discovering clients (e.g. jcode, which defaults every model to 200k
when context_window is absent) get correct context and feature flags.
Purely additive: routing/decision logic untouched, legacy response shape
preserved, cache schema bumped to v2 (old v1 caches load fine).
When Zen returns 400 such as "Referenced reasoning item 'rs_...' was
not found or has expired", replay once without the Responses reasoning
input items and previous_response_id under a fresh upstream session
instead of failing the client request. Other 400s pass through
unchanged. Adds unit tests for the classifier and payload stripping.
The models.dev metadata store used its own plain http.Client, so the
periodic price/deprecation refresh always bypassed the configured proxy
pool and failed on networks where direct access to models.dev is
unreliable or blocked.
Introduce a client provider on the store that resolves candidates at
refresh time: the active runtime's healthy proxy transports first, then
the original direct client as fallback. The provider reads the current
runtime atomically, so WebUI hot reloads automatically pick up new proxy
transports without touching the long-lived store.
Add a top-level "prefer" config field ("zen" or "go", default "go") that
controls which upstream is used when a model is available in both pools,
including during the temporary model-discovery fallback. Previously Zen
was always preferred.