Repository navigation
fix(cloudflare): preserve embedding response data - #8041
donaldxdonald wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Embedding response handling relay/channel/cloudflare/adaptor.go, controller/channel_test_request_test.go |
The adaptor routes embedding responses through openai.OpenaiHandler. Tests check response JSON, HTTP status, content type, and usage totals, including an estimate when upstream usage is absent. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
#8038— Describes the same Cloudflare embedding response defect, where the chat handler drops embedding data.
Possibly related PRs
- QuantumNous/new-api#8026 — Changes the estimate used when an embedding response has no upstream usage, which is asserted by this PR’s tests.
Suggested reviewers: calcium-ion
Merge Risk: 
Minimal · up to 08636
-
The embedding response test covers the changed routing, and no specific merge-blocking issue has been identified. Normal checks remain appropriate.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
The change satisfies
#8040.relay/channel/cloudflare/adaptor.gonow routesRelayModeEmbeddingstoopenai.OpenaiHandlerinstead of the chat handler. This preserves the upstream embeddings response, includingdata[].embeddingandindex. The added regression test covers single vectors, batches, base64 embeddings, extra fields, forced formatting, upstream usage, and missing-usage fallback.
Full details: Out of Scope Changes check
-
Explanation
The changes remain within
#8040. The pull request changes one Cloudflare response branch and adds focused compatibility tests for that branch. No unrelated protocol, chat, Responses, pricing, database, dependency, or authentication changes are present in the reviewed diff.
-
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the vectors in a row
The Cloudflare response lets embeddings show
Through OpenAI’s handler, payloads pass
With usage checked for each small batch
The bunny hops; the tests all glow
Comment @coderabbitai help to get the list of available commands.
Agent
Codex CLI 0.163.0 / Codex desktop,2026-10-26 UTC。代码与测试由 AI 辅助完成;运行环境未提供完整模型 ID。
Links
Closes #8040。Related: #6201(同类旧修复,已关闭未合并)。
User request
Out of scope — refuse
Matched: no。修复已有官方渠道,未开启透传;不涉及第三方封装或接入咨询。
Open gate — do not open unless all are satisfied
Open: yes。Issue 已记录现象、影响、频率和对照;下文包含实际修复前后测试结果。正文已精简、脱敏。
Kind
Issue facts
官方镜像
calciumion/new-api:v1.0.0-rc.47,VPS / Docker Compose / PostgreSQL。Cloudflare 模型@cf/qwen/qwen3-embedding-0.6b的POST /v1/embeddings返回 200,但缺少data,调用方无法取得向量。用户报告必现,实际有效调用 1/1 复现;同文本的上游原生接口返回 1024 维向量。完整脱敏证据见 #8040。Change
让 embeddings 分支调用已有
openai.OpenaiHandler,不再 fallthrough 到聊天处理器。该 handler 在 embedding 格式下保留响应体,并返回上游 usage 或已有输入估算作为结算 usage。无新抽象、依赖或 DTO。Research
Duplicate / prior art
已搜索 Issues/PRs 的
Cloudflare、Cloudflare embedding。#6201 曾包含类似修复,但未合并;#6265 是不同的聊天 usage 问题。本 PR 仅处理 #8040。Docs and code
POST /v1/embeddings。/ai/v1/embeddingsURL 和model/input字段无需修改。Alternatives considered
复用已有 handler,而不是新增 embeddings handler 或在聊天 handler 内增加专用重编码,避免重复转换和丢字段。
Files
relay/channel/cloudflare/adaptor.gocontroller/channel_test_request_test.goBehavior
data,忽略有效上游 usage。Verification
默认 Go 依赖源 DNS 失败,后续命令临时设置
GOPROXY=https://goproxy.cn,direct,未修改全局或仓库配置。go test ./controller -run '^TestCloudflareEmbeddingResponseCompatibility$' -count=1 -v:四个用例通过,验证响应 JSON 保留及结算 usage。go test -overlay=/tmp/new-api-cloudflare-before-overlay.json ./controller -run '^TestCloudflareEmbeddingResponseCompatibility$' -count=1 -v:overlay 仅将 adaptor 替换为修复前 HEAD 内容;相同四个用例全部失败,出现向量丢失及 usage 被估算值覆盖。make test:根模块只有advancedcustom/TestAdaptorMasksDialedHostsInDialFailure/channel_proxy_host失败(得到unexpected EOF,而非预期包含代理主机的错误);controller 等其他包通过。使用同一修复前 overlay 单独运行该测试也失败,未改动无关代码。relaykit/、tokenkit/运行GOWORK=off go test ./...:均通过。git diff --check、gofmt -l:通过,无格式输出。cf ai run对照见 Cloudflare embeddings 返回 HTTP 200 但缺少向量数据 #8040;无 UI 变更或数据库变更。未验证修复后线上部署、Cloudflare 兼容接口独立直连或其他模型;不声称全量测试通过。Risks
有效上游 usage 现在优先于本地估算,可能纠正该渠道的 token 结算量;价格及配额算法不变。缺失 usage 的回退已有回归覆盖。无认证变更。
Scope check
Summary by CodeRabbit