Skip to content

feat: add Alibaba Cloud Token Plan channel type 新增阿里云百炼 Token Plan 渠道类型#5770

Closed
shuaiZend wants to merge 1 commit into
QuantumNous:mainfrom
shuaiZend:feat/ali-token-plan
Closed

feat: add Alibaba Cloud Token Plan channel type 新增阿里云百炼 Token Plan 渠道类型#5770
shuaiZend wants to merge 1 commit into
QuantumNous:mainfrom
shuaiZend:feat/ali-token-plan

Conversation

@shuaiZend

@shuaiZend shuaiZend commented Jun 27, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

新增专用的阿里云百炼 Token Plan 渠道类型(type=59),解决 Token Plan 用户无法使用 /v1/responses 端点的问题。

背景:

Token Plan 的 API 地址为 token-plan.cn-beijing.maas.aliyuncs.com,使用标准 OpenAI 兼容协议(/compatible-mode/v1/...)。但现有"阿里千问"渠道类型的适配器会将 responses 请求路由到 DashScope 专有路径(/api/v2/apps/protocols/...),并注入 X-DashScope-SSE: enable 等专有头部,导致 Token Plan 返回 500 错误。

实现: 创建 ali_token_plan 适配器包,嵌入 ali.Adaptor 并覆写三个方法:

  • GetRequestURL:路由到 /compatible-mode/v1/{responses,chat/completions,...}
  • SetupRequestHeader:仅保留标准 Authorization: Bearer 头,不注入 DashScope 头部
  • DoRequest:确保 Go 结构体嵌入的方法派发能正确调用子类覆写(Go embedding 不等于 OOP 继承,必须显式覆写 DoRequest 传递外层指针)

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • [ √] ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • [ √] 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • [ √] 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • [ √] 变更理解: 我已理解这些更改的工作原理及可能影响。
  • [ √] 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • [ √] 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • [ √] 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

已部署至生产环境,完整验证所有端点:

image 后台可配置性: image curl验证responses可用: image

Summary by CodeRabbit

  • New Features

    • Added support for a new Ali cloud token-plan channel.
    • Users can now select this channel in the UI, and it shows the new label in channel lists.
    • Model lists can now be fetched for this channel, and streaming is supported where available.
  • Bug Fixes

    • Requests for this channel are now routed correctly with the proper API type and request handling.

Add dedicated channel type for Alibaba Cloud Bailian Token Plan service,
enabling proper /v1/responses endpoint support (required for Codex tools).

Problem:
- Token Plan uses compatible-mode API at token-plan.cn-beijing.maas.aliyuncs.com
- Using the existing 'Ali Qianwen' channel type routes responses requests to
  DashScope-specific paths (/api/v2/apps/protocols/...) which Token Plan doesn't support
- This causes 500 errors on /v1/responses while /v1/chat/completions works

Solution:
- New channel type 59 (ChannelTypeAliTokenPlan) with dedicated adaptor
- Adaptor inherits from ali.Adaptor but overrides:
  - GetRequestURL: routes to /compatible-mode/v1/{responses,chat/completions,...}
  - SetupRequestHeader: removes DashScope-specific headers (X-DashScope-SSE)
  - DoRequest: ensures Go embedding method dispatch calls overridden methods
- Registered in both classic and default frontends with model fetch support
- Default base URL: https://token-plan.cn-beijing.maas.aliyuncs.com

Closes QuantumNous#5763
@coderabbitai

coderabbitai Bot commented Jun 27, 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: 0d17ab33-e878-4ca4-be97-68656f289f9b

📥 Commits

Reviewing files that changed from the base of the PR and between 626dadb and a93db50.

📒 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

Walkthrough

Adds a new Ali Token Plan channel type end-to-end: backend constants, adaptor selection, request routing, stream support, and web channel options. The adaptor maps relay requests to Ali compatible-mode endpoints and sets request headers for the new channel.

Changes

Ali Token Plan channel support

Layer / File(s) Summary
Channel constants and API mapping
constant/api_type.go, constant/channel.go, common/api_type.go
Adds the Ali Token Plan channel and API type constants, base URL, display name, and channel-to-API type mapping.
Relay adaptor selection and stream support
relay/relay_adaptor.go, relay/common/relay_info.go
Adds the Ali Token Plan adaptor import and selection case, and marks the channel as stream-supported.
Ali token-plan request routing
relay/channel/ali_token_plan/adaptor.go
Adds the token-plan adaptor with request URL selection, header setup, request dispatch, model list, and channel name overrides.
Web channel options
web/classic/src/constants/channel.constants.js
Adds the Ali Token Plan option to the channel list and includes it in the set of fetchable channel types.

Sequence Diagram(s)

sequenceDiagram
  participant relay.GetAdaptor
  participant ali_token_plan.Adaptor
  participant channel.DoApiRequest
  participant channel.SetupApiRequestHeader
  participant Ali compatible-mode API
  relay.GetAdaptor->>ali_token_plan.Adaptor: return &ali_token_plan.Adaptor{}
  ali_token_plan.Adaptor->>channel.DoApiRequest: DoRequest(...)
  channel.DoApiRequest->>ali_token_plan.Adaptor: GetRequestURL(info)
  channel.DoApiRequest->>ali_token_plan.Adaptor: SetupRequestHeader(c, req, info)
  ali_token_plan.Adaptor->>channel.SetupApiRequestHeader: baseline headers
  channel.DoApiRequest->>Ali compatible-mode API: send relay request
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • seefs001
  • Calcium-Ion

Poem

🐰 Hop, hop—new channels bloom at dawn,
Token-plan trails where responses run on.
Ears up for headers, tails up for cheer,
Ali routes hum and the web path is clear.
Nibble-nibble—success hopped here.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding the Alibaba Cloud Token Plan channel type.
Linked Issues check ✅ Passed The PR adds a dedicated Token Plan channel, routes requests to compatible-mode endpoints, and preserves responses/chat completions support as requested.
Out of Scope Changes check ✅ Passed All code changes relate to Token Plan channel support across backend and UI; no unrelated scope appears introduced.
✨ 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.

@seefs001 seefs001 closed this Jun 27, 2026
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.

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

2 participants