Skip to content

feat: 新增阿里云百炼 Token Plan 渠道类型,修复 responses API 路径问题#5764

Closed
shuaiZend wants to merge 2 commits into
QuantumNous:mainfrom
shuaiZend:main
Closed

feat: 新增阿里云百炼 Token Plan 渠道类型,修复 responses API 路径问题#5764
shuaiZend wants to merge 2 commits into
QuantumNous:mainfrom
shuaiZend:main

Conversation

@shuaiZend

@shuaiZend shuaiZend commented Jun 26, 2026

Copy link
Copy Markdown

问题

使用阿里通义千问渠道类型(ChannelTypeAli)配置 Token Plan API 地址 https://token-plan.cn-beijing.maas.aliyuncs.com 时,调用 responses 接口返回 bad_response_status_code 错误。

根因分析

Ali 适配器在 RelayModeResponses 下构造的请求路径为:

/api/v2/apps/protocols/compatible-mode/v1/responses

该前缀 /api/v2/apps/protocols/ 是 DashScope(dashscope.aliyuncs.com)平台专属路径,Token Plan 平台不支持。

Token Plan 的正确 responses 端点应为:

/compatible-mode/v1/responses

修复方案

  1. 新增 ChannelTypeAliTokenPlan = 59 渠道类型(阿里百炼 Token Plan 与通义千问是不同产品线)
    1. 新增 APITypeAliTokenPlan API 类型
    1. 创建 relay/channel/ali_token_plan/adaptor.go,通过 Go 结构体嵌入继承 ali.Adaptor,仅覆写 GetRequestURL() 方法修复路径
    1. 注册流式支持和前端 UI 选项

变更文件

  • constant/channel.go - 新增渠道类型常量和 base URL
    • constant/api_type.go - 新增 API 类型
    • common/api_type.go - 添加类型映射
    • relay/relay_adaptor.go - 注册适配器工厂
    • relay/channel/ali_token_plan/adaptor.go - 新建适配器(继承 Ali)
    • relay/common/relay_info.go - 注册流式支持

Summary by CodeRabbit

  • New Features
    • Added a new Ali Token Plan channel across the API and UI, including display name, base URL mapping, and selector option.
    • Added a dedicated routing adaptor for this channel, supporting Claude chat-completions as well as responses, embeddings, completions, rerank, and image-related flows.
    • Enabled upstream model list fetching and streaming support for the new channel.
  • Chores
    • Updated ignore rules to exclude the .qoder/ directory.

- 新增 ChannelTypeAliTokenPlan (59) 渠道类型和 APITypeAliTokenPlan
- 创建 ali_token_plan 适配器包,通过嵌入 ali.Adaptor 继承并覆写 GetRequestURL
- 修复 Token Plan 的 responses API 路径(使用 /compatible-mode/v1/responses 替代 DashScope 特有前缀)
- 注册流式支持和前端 UI 选项
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92ce6540-077a-4e77-a986-ee554e7ac14d

📥 Commits

Reviewing files that changed from the base of the PR and between c667d7c and d146729.

📒 Files selected for processing (2)
  • .gitignore
  • relay/channel/ali_token_plan/adaptor.go
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • relay/channel/ali_token_plan/adaptor.go

Walkthrough

Adds a new Ali Token Plan channel and API type, routes it to a dedicated relay adaptor for responses and other modes, and updates streaming support plus web channel options.

Changes

Ali Token Plan channel support

Layer / File(s) Summary
Channel and API type registration
constant/api_type.go, constant/channel.go, common/api_type.go
Adds APITypeAliTokenPlan, ChannelTypeAliTokenPlan, its base URL and display name, and maps the new channel type to the new API type.
Relay adaptor routing
relay/relay_adaptor.go, relay/channel/ali_token_plan/adaptor.go
Wires APITypeAliTokenPlan to a new adaptor that selects Ali-compatible request paths by relay format and mode, returns ali.ModelList, and reports the ali_token_plan channel name.
Stream and UI exposure
relay/common/relay_info.go, web/classic/src/constants/channel.constants.js
Marks the new channel as stream-supported and adds it to the web channel options and model-fetchable channel set.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant GetAdaptor as relay/relay_adaptor.go GetAdaptor
  participant Adaptor as relay/channel/ali_token_plan.Adaptor
  participant Upstream as Ali token plan upstream

  Client->>GetAdaptor: APITypeAliTokenPlan request
  GetAdaptor->>Adaptor: return ali_token_plan.Adaptor
  Client->>Adaptor: GetRequestURL(info)
  Adaptor->>Adaptor: choose /compatible-mode/v1/responses, /embeddings, /completions, /rerank, or /chat/completions
  Adaptor->>Upstream: send request to resolved URL
  Upstream-->>Adaptor: response
  Adaptor-->>Client: relay response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • QuantumNous/new-api#1915: Both PRs extend the same enum-to-adaptor wiring points and GetAdaptor switch mappings for a new API type.

Suggested reviewers

  • seefs001

Poem

I’m a rabbit with token-plan flair,
Hopping routes through the relay air.
Responses now scamper clean and bright,
With orange channel bells in sight.
🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning .gitignore adds a new .qoder/ ignore rule, which is unrelated to the Token Plan channel fix. Move the .qoder/ ignore change to a separate cleanup PR or justify it as part of this issue.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an Aliyun Token Plan channel and fixing its responses API path.
Linked Issues check ✅ Passed The PR adds a dedicated Token Plan channel and routes responses requests to the compatible-mode path required by #5763.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relay/channel/ali_token_plan/adaptor.go`:
- Around line 21-35: The fallback in the request URL resolver is too restrictive
and should delegate unknown relay modes to the embedded Ali adaptor. In the
GetRequestURL logic for the Token Plan adaptor, keep the explicit overrides for
the known compatible-mode cases, but replace the default chat-completions path
with a call to a.Adaptor.GetRequestURL(info) so any Ali-specific RelayMode not
listed here inherits the base behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16d1e522-2178-44bf-87ef-01d5ad3ce7b1

📥 Commits

Reviewing files that changed from the base of the PR and between d10fc76 and c667d7c.

📒 Files selected for processing (7)
  • common/api_type.go
  • constant/api_type.go
  • constant/channel.go
  • relay/channel/ali_token_plan/adaptor.go
  • relay/common/relay_info.go
  • relay/relay_adaptor.go
  • web/classic/src/constants/channel.constants.js

Comment thread relay/channel/ali_token_plan/adaptor.go Outdated
将 GetRequestURL() 的 default 分支从硬编码 chat/completions 路径改为
调用 a.Adaptor.GetRequestURL(info),确保未来 Ali 适配器新增模式时
能正确继承路由行为而非被错误路由。
@seefs001 seefs001 closed this Jun 27, 2026
@seefs001 seefs001 added the invalid This doesn't seem right label Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

newapi缺乏阿里云token plan渠道导致responses不可用, 返回500错误

2 participants