Skip to content

feat: 新增阿里云百炼 Token Plan 渠道类型#5777

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

feat: 新增阿里云百炼 Token Plan 渠道类型#5777
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),解决使用"阿里千问"渠道类型时 /v1/responses 返回 500 的问题。

Token Plan 服务使用标准 OpenAI 兼容协议(/compatible-mode/v1/...),但现有 Ali 适配器会将 responses 请求路由到 DashScope 专有路径并注入不兼容的头部。本 PR 新建 ali_token_plan 适配器包,嵌入 ali.Adaptor 并覆写路由和头部逻辑,使 Token Plan 的 /v1/responses 端点正常工作。

🚀 变更类型 / Type of change

  • ✨ 新功能 (New feature)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

已部署至生产环境验证,responses 和 chat/completions 均正常:

测试结果

渠道配置界面:

渠道配置

curl 验证 responses 可用:

curl验证

Summary by CodeRabbit

  • New Features

    • Added support for a new channel option, “阿里云百炼 Token Plan,” across the app.
    • The new channel can now use compatible-mode requests and supports streaming.
    • The UI can display and fetch models for this channel.
  • Bug Fixes

    • Requests to the new channel now use the correct authorization and routing behavior.

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: e6d88058-2bac-496b-8c9b-bfff26f2544b

📥 Commits

Reviewing files that changed from the base of the PR and between 3a506f5 and e037c12.

📒 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 ChannelTypeAliTokenPlan (value 59) channel type with a corresponding APITypeAliTokenPlan constant. Implements a new ali_token_plan relay adaptor that embeds ali.Adaptor and routes requests to Alibaba Cloud Token Plan compatible-mode endpoints with standard Bearer auth. Registers the adaptor in the factory, enables stream support, and adds the channel to the UI.

AliTokenPlan Channel Integration

Layer / File(s) Summary
Channel and API type constants
constant/channel.go, constant/api_type.go, common/api_type.go
Adds ChannelTypeAliTokenPlan=59 with base URL and display name, adds APITypeAliTokenPlan iota constant, and maps the channel type to the API type in ChannelType2APIType.
ali_token_plan relay adaptor
relay/channel/ali_token_plan/adaptor.go
Implements Adaptor embedding ali.Adaptor with overridden GetRequestURL routing to /compatible-mode/v1/... endpoints, SetupRequestHeader using Bearer auth instead of DashScope headers, and DoRequest passing the outer adaptor to channel.DoApiRequest.
Adaptor factory and stream support wiring
relay/relay_adaptor.go, relay/common/relay_info.go
Adds constant.APITypeAliTokenPlan case in GetAdaptor returning &ali_token_plan.Adaptor{}, and marks ChannelTypeAliTokenPlan as supporting stream options.
UI channel registration
web/classic/src/constants/channel.constants.js
Adds CHANNEL_OPTIONS entry for value 59 with orange color and Chinese display name, and includes 59 in MODEL_FETCHABLE_CHANNEL_TYPES.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • QuantumNous/new-api#2190: Extends the same relay/relay_adaptor.go GetAdaptor switch to add a new channel/API type adaptor registration.
  • QuantumNous/new-api#2909: Modifies the same streamSupportedChannels map in relay/common/relay_info.go to add channel types supporting stream options.

Suggested reviewers

  • seefs001
  • Calcium-Ion

🐰 A new channel hops into the mix,
Token Plan with compatible-mode tricks,
Bearer auth replaces DashScope's flair,
Fifty-nine's the number, routing with care,
The rabbit cheers — the responses are there! 🎉

🚥 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 标题准确概括了新增阿里云百炼 Token Plan 渠道类型这一主要变更。
Linked Issues check ✅ Passed 新增专用 Token Plan 渠道、兼容模式适配器和请求头处理,覆盖了 #5763 要求的 responses 可用修复。
Out of Scope Changes check ✅ Passed 未见明显与 Token Plan 渠道支持无关的改动,前后端注册与适配器修改均属范围内。
✨ 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 28, 2026
@seefs001

Copy link
Copy Markdown
Collaborator

原issue已回复过,不会考虑支持

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