Skip to content

Add /zen/v1 passthrough for the upstream Zen API - #2

Merged
6Kmfi6HP merged 1 commit into
mainfrom
feat/zen-v1-passthrough
Aug 20, 2026
Merged

Add /zen/v1 passthrough for the upstream Zen API#2
6Kmfi6HP merged 1 commit into
mainfrom
feat/zen-v1-passthrough

Conversation

@6Kmfi6HP

Copy link
Copy Markdown
Owner

概述

为网关新增 /zen/v1/* 原样透传:把请求原样转发到上游 OpenCode Zen 的同一路径(https://opencode.ai/zen/v1/*),不做任何改写——不过滤免费模型、不追加 -free 后缀、不进行协议转换、无 reasoning_content 兜底。客户端需按上游原生协议调用。

改动

  • edge-functions/v1/[[default]].jsupstreamUrl 改为前缀感知——入站路径已带 /zen 时不再二次前置(原会把 /zen/v1/x 拼成 /zen/zen/x);/v1/* 路由行为不变。
  • edge-functions/zen/v1/[[default]].js(新增):EdgeOne 文件路由注册 /zen/v1/*,委托给主处理器,请求落入通用透传分支(body 原样、状态码/头/SSE 原样返回)。
  • test/v1-proxy.test.js:新增 8 个用例——前缀边界、URL 去重、chat/messages/models 端到端原样透传、SSE 流透传、非 -free 不加后缀、非 2xx 状态透传。
  • README.md:路由表新增 /zen/v1/* 行、透传语义与上游鉴权说明、部署时刷新 routes.json 的运维要点。

验证

  • 单元/集成测试 55/55 通过。
  • 已部署到生产(oc2api-edgeone.edgeone.dev,Deployment dpanyt4o7h4d)并经 SOCKS5 代理实测:
    • /v1/models(过滤 7 个)与 /zen/v1/models(原始 63 个,含付费模型)行为正确;
    • /v1/chat/completions(含 SSE 流)、/v1/messages(Claude)、/v1/responses 三个转换入口均返回 200 与正确格式;
    • /zen/v1/chat/completions 原样透传(响应含 cost 等未清理字段,证明未改写)。
  • 上游对 Bearer public 在鉴权层拒绝付费模型(401 AuthError),透传无法消耗付费额度。

部署注意

新增/变更 edge-functions/ 路由后,需先 npx edgeone makers generate-routes(该命令在 routes.json 已存在时跳过生成,需先删除 .edgeone/routes.json)再部署,否则新路径不会触发边端函数。

Expose the raw OpenCode Zen API surface under /zen/v1/*, relayed verbatim
to https://opencode.ai/zen/v1/*: no free-model filtering, no -free suffix
mapping, and no protocol conversion (no reasoning backfill either).

- upstreamUrl is now prefix-aware so an already-/zen path is not prefixed
  twice; /v1/* routing is unchanged
- new edge-functions/zen/v1/[[default]].js registers the route and
  delegates to the main handler
- 8 new tests cover prefix detection, URL mapping, and end-to-end verbatim
  relay for chat/messages/models incl. SSE and non-2xx passthrough
- README documents the route and the deploy step to refresh routes.json
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@6Kmfi6HP
6Kmfi6HP merged commit 631eb13 into main Aug 20, 2026
1 check passed
@6Kmfi6HP
6Kmfi6HP deleted the feat/zen-v1-passthrough branch August 20, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant