OpenAI-compatible reverse proxy for the free models on OpenCode Zen, with a self-updating model catalog
pip install zen-free-proxy Copy PIP instructions
An OpenAI-compatible reverse proxy in front of the free models on OpenCode Zen.
# install, then run uv tool install zen-free-proxy zen-free-proxy # or with pip, if you don't use uv pip install zen-free-proxy zen-free-proxy Or run it without installing:
uvx zen-free-proxy Working on a checkout instead? uv sync, then uv run zen-free-proxy.
Everything is an environment variable, or a .env file (the prefix is ZEN_PROXY_, except ZEN_API_KEY). .env is read from the working directory the server starts in:
# .env ZEN_API_KEY=sk-... ZEN_PROXY_PORT=8787 ZEN_PROXY_ALLOWED_CLIENT_KEYS=team-a-secret,team-b-secret Quick start zen-free-proxy It listens on http://0.0.0.0:8787 by default.
curl http://localhost:8787/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer literally-anything" \ -d '{"model":"space-bunny-free","messages":[{"role":"user","content":"hello"}]}' From the OpenAI SDK:
from openai import OpenAI client = OpenAI(base_url="http://localhost:8787/v1", api_key="whatever") print([m.id for m in client.models.list().data]) reply = client.chat.completions.create( model="space-bunny-free", messages=[{"role": "user", "content": "hello"}], ) print(reply.choices[0].message.content) IMPORTANT: what the free tier actually allows Measured in 2026-10: every free model needs a key. Anonymous traffic (Bearer public) gets 403 FreeTierError from all of them, space-bunny-free included.
GET /v1/models is the exception — it answers anonymously, so the catalog keeps itself up to date either way.
# in .env (copy .env.example) ZEN_API_KEY=sk-... Get a key at https://opencode.ai/auth. Once set, upstream requests carry Authorization: Bearer and the client's own key is never forwarded.
Without a key, a request for a free model comes back as a free_tier_restricted error that names the fix (set ZEN_API_KEY) instead of a bare 403.
Zen answers some free-tier rejections with Error from provider (Console): OpenCode's free tier can only be used from within OpenCode. Disassembling opencode.exe (a bun build) shows the app sends exactly four Zen-specific headers — that is the complete set of x-opencode-*:
x-opencode-client: cli x-opencode-session: ses_… x-opencode-request: req_… User-Agent: opencode/ The proxy replays them verbatim by default (disable with ZEN_PROXY_ZEN_CLIENT_HEADERS=0). Within the range actually tested, adding them does not remove the 403: user agent only, +client, +session +request, +project, and all of cli / desktop / web were tried and every combination returned the same 403. On the other hand, a malformed key gives 401 Invalid API key and no key gives 401 Missing API key on paid models. So Zen is checking the API key, not the headers, and setting ZEN_API_KEY is the fix. The headers are kept as insurance in case Zen tightens the check further.
Provider prefixes are accepted and stripped, so opencode/space-bunny-free works.
Not one model id appears in this repository. At startup, and every ZEN_PROXY_CATALOG_TTL seconds after that, the proxy reads:
GET https://opencode.ai/zen/v1/models — what Zen is currently serving. A model Zen drops disappears from /v1/models on its own, and a model Zen adds appears on its own. This list is the only authority on whether a model may be used at all.
The opencode entry on models.dev (https://models.dev/api.json) — the catalog the official OpenCode client reads, which answers all three remaining questions:
Free is therefore a price, not a name. big-pickle is free despite looking paid, and a model with -free in its name that costs hundreds of dollars a million tokens is correctly refused — no name table involved.
The snapshot opencode commits to its own repository (mirror) — packages/core/src/models-dev/snapshot.txt, refreshed daily by .github/workflows/models-snapshot.yml. Used when models.dev itself is unreachable (ZEN_PROXY_MODELS_DEV_MIRROR_URL). It is the same file: measured on its own, it yields all 14 free models with their window sizes.
If both sources are unreachable the previous catalog keeps being served, and the proxy retries on its own schedule (every 15 minutes) rather than on your inference requests. Only models no source has heard of fall back to name-based detection (-free and friends).
Zen serves different free models on different upstream endpoints, and the catalog says which is which:
A wrong route is not a dead end. When Zen answers Model X is not supported for format openai, the proxy tries the other OpenAI-compatible route once and records the route that worked. It also does that when Zen fails with a 5xx, but only when the route was a name-based guess — a 5xx on a route a source named is a real failure and is reported as one.
So when Zen moves a model, a source lags behind, or a name guess turns out wrong, the cost is that one request goes out twice. No patch required.
Context windows come from the same models.dev fetch as above. There is no table to go stale, so a newly launched free model arrives with its window already filled in.
Clients spell this differently, so every size is published under all the names in use:
pi-web-ui's "Enrich params" pulls from external catalogs (OpenRouter, then models.dev), and Zen's free models are in neither. What actually works is /v1/models, because pi-web-ui's server/model-admin.ts (parseOpenAiModel) reads those fields from the response. Note that pi-web-ui prefers manual values and only enriches blanks, so delete a row you filled in with 200K before fetching it again.
The default is completely open: the client's Authorization header is neither read nor validated, and is never forwarded upstream. You do not have to hand anyone a key.
export ZEN_PROXY_ALLOWED_CLIENT_KEYS="team-a-secret,team-b-secret" Only requests carrying one of those keys are then accepted.
⚠️ The default bind is 0.0.0.0 with no authentication. If this is reachable from a LAN or the internet, set ZEN_PROXY_HOST=127.0.0.1 or configure ZEN_PROXY_ALLOWED_CLIENT_KEYS.
uv run pytest -q # 119 tests uv run ruff check . uv run ruff format . The tests mock the upstream with httpx.MockTransport and never touch the network.
src/zen_free_proxy/ config.py environment variables -> Settings catalog.py the free-model catalog and the window types (ModelMeta / CatalogSource) models_dev.py reads free-ness, routes and window sizes out of models.dev upstream.py HTTP client for Zen (retries, catalog refresh, client headers) sse.py SSE framing bridge.py Chat Completions Responses API conversion app.py the FastAPI routes Releasing Publishing to PyPI goes through Trusted Publishing, so there is no API token stored anywhere. Push a v* tag and CI uploads the release:
uv version --bump patch # 0.1.0 -> 0.1.1 in pyproject.toml git commit -am "release 0.1.1" && git push git tag v0.1.1 && git push --tags Only the very first release needed a one-time publisher registration on PyPI, at https://pypi.org/manage/project/zen-free-proxy/settings/publishing.
opencode zen proxy openai llm free-models models-dev
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.




