Add /zen/v1 passthrough for the upstream Zen API - #2
Merged
Conversation
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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为网关新增
/zen/v1/*原样透传:把请求原样转发到上游 OpenCode Zen 的同一路径(https://opencode.ai/zen/v1/*),不做任何改写——不过滤免费模型、不追加-free后缀、不进行协议转换、无reasoning_content兜底。客户端需按上游原生协议调用。改动
edge-functions/v1/[[default]].js:upstreamUrl改为前缀感知——入站路径已带/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的运维要点。验证
oc2api-edgeone.edgeone.dev,Deploymentdpanyt4o7h4d)并经 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)再部署,否则新路径不会触发边端函数。