feat: support Tencent TokenHub API key via OpenAI-compatible protocol - #6232
Conversation
WalkthroughTencent channel initialization now dispatches between native and OpenAI-compatible adaptors based on API key format, applies TokenHub base URL defaults, exposes Tencent metadata, and enables stream support. ChangesTencent adaptor dispatch
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Relay as relay.GetAdaptor
participant Dispatch as tencent.DispatchAdaptor
participant Info as relaycommon.RelayInfo
participant Native as tencent.Adaptor
participant OpenAI as openai.Adaptor
Relay->>Dispatch: create Tencent adaptor
Dispatch->>Info: inspect ApiKey and ChannelBaseUrl
alt ApiKey contains "|"
Dispatch->>Native: Init(info)
else TokenHub-compatible key
Dispatch->>Info: set TokenHub base URL when needed
Dispatch->>OpenAI: Init(info)
end
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…ocales Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
e31cfd5 to
93a7f8b
Compare
There was a problem hiding this comment.
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/common/relay_info.go`:
- Line 345: Restrict SupportStreamOptions for Tencent so legacy TC3 requests do
not pass stream_options into requestOpenAI2Tencent. Update the capability
configuration around the Tencent entry in SupportStreamOptions to apply only to
TokenHub or the appropriate supported key/format, while preserving stream
options for TokenHub requests.
🪄 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 Plus
Run ID: 046187bd-45cf-4476-9f38-0963146c473e
📒 Files selected for processing (4)
relay/channel/tencent/dispatch.gorelay/channel/tencent/dispatch_test.gorelay/common/relay_info.gorelay/relay_adaptor.go
🚧 Files skipped from review as they are similar to previous changes (2)
- relay/relay_adaptor.go
- relay/channel/tencent/dispatch.go
| constant.ChannelTypeMiniMax: true, | ||
| constant.ChannelTypeSiliconFlow: true, | ||
| constant.ChannelTypeAdvancedCustom: true, | ||
| constant.ChannelTypeTencent: true, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
fd -t f -e go . relay/channel/tencent relay/common |
xargs rg -n -C 3 'StreamOptions|Convert(OpenAI)?Request|DispatchAdaptor|SupportStreamOptions'Repository: QuantumNous/new-api
Length of output: 4897
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== relay/common/relay_info.go relevant sections =="
sed -n '200,250p' relay/common/relay_info.go
sed -n '320,360p' relay/common/relay_info.go
echo
echo "== relay/channel/tencent/dispatch.go =="
cat -n relay/channel/tencent/dispatch.go
echo
echo "== relay/channel/tencent/adaptor.go outline/contents =="
wc -l relay/channel/tencent/adaptor.go
sed -n '1,140p' relay/channel/tencent/adaptor.go
echo
echo "== relay/channel/tencent/dispatch_test.go =="
cat -n relay/channel/tencent/dispatch_test.go
echo
echo "== StreamOptions usages in relay/common =="
rg -n -C 4 'StreamOptions|stream_options|SupportStreamOptions' relay/common relay/channel/tencentRepository: QuantumNous/new-api
Length of output: 17937
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Find stream_options helpers and TC3 conversion =="
rg -n -C 5 'stream_options|StreamOptions|ToTencent|requestOpenAI2Tencent|Tencent.*Request|OpenAI2Tencent|ConvertOpenAIRequest' relay common types dto constant relay/channel/tencent relay/channel/openai
echo
echo "== dto stream option definitions/usages =="
rg -n -C 3 'StreamOptions|stream_options' dto relay relay/common relay/channel || trueRepository: QuantumNous/new-api
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== relay/channel/openai/adaptor.go ConvertOpenAIRequest =="
sed -n '220,260p' relay/channel/openai/adaptor.go
echo
echo "== relay/channel/tencent/relay-tencent.go requestOpenAI2Tencent =="
sed -n '28,80p' relay/channel/tencent/relay-tencent.go
echo
echo "== relay/channel/tencent/dto.go =="
cat -n relay/channel/tencent/dto.go
echo
echo "== relay/compatible_handler.go stream option gating =="
sed -n '40,65p' relay/compatible_handler.goRepository: QuantumNous/new-api
Length of output: 7465
Gate stream options to TokenHub for Tencent.
SupportStreamOptions is assigned before DispatchAdaptor.Init; enabling it for the whole ChannelTypeTencent lets legacy | TC3 keys pass stream_options into requestOpenAI2Tencent, and the TC3 request model has no such field. Remove ChannelTypeTencent from the global stream-supported set, add a per-key/format capability, or strip TC3 requests like the OpenAI adaptor does.
🤖 Prompt for 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.
In `@relay/common/relay_info.go` at line 345, Restrict SupportStreamOptions for
Tencent so legacy TC3 requests do not pass stream_options into
requestOpenAI2Tencent. Update the capability configuration around the Tencent
entry in SupportStreamOptions to apply only to TokenHub or the appropriate
supported key/format, while preserving stream options for TokenHub requests.
Source: Coding guidelines
…QuantumNous#6232) * feat: support tencent tokenhub api key via openai-compatible protocol * fix: use tokenhub base url for tencent api key channels * test: cover tencent key-format dispatch and add TokenHub key prompt locales
…QuantumNous#6232) * feat: support tencent tokenhub api key via openai-compatible protocol * fix: use tokenhub base url for tencent api key channels * test: cover tencent key-format dispatch and add TokenHub key prompt locales
Bring aurora to parity with three rc.22 web/ frontend changes, additively — no aurora customizations altered: - Keys: unlimited-quota API keys now surface used quota. New UnlimitedQuotaBadge (Unlimited badge + popover showing Used: <amount>) replaces the bare label in the key columns and the mobile card list (QuantumNous#6224). - Channels: add Codex (type 57) to the fetch-upstream-models set (QuantumNous#6184); update the type-23 key prompt to mention TokenHub (QuantumNous#6232). Advanced-custom model fetch (QuantumNous#5971, type 58) intentionally NOT wired — aurora's custom advanced-custom editor has no model-list-route concept, so it needs a separate design discussion rather than a forced fit. - Models: fix the model edit drawer resetting the form when system options refetch mid-edit — read modelSettings via a ref and key the load effect on a hasModelSettings boolean instead of the object reference. i18n zh+en (zh-TW regenerated). aurora build + typecheck clean (6 pre-existing, no new). Verified only aurora/ files changed.
…QuantumNous#6232) * feat: support tencent tokenhub api key via openai-compatible protocol * fix: use tokenhub base url for tencent api key channels * test: cover tencent key-format dispatch and add TokenHub key prompt locales
…QuantumNous#6232) * feat: support tencent tokenhub api key via openai-compatible protocol * fix: use tokenhub base url for tencent api key channels * test: cover tencent key-format dispatch and add TokenHub key prompt locales
📝 变更描述 / Description
腾讯云新的 TokenHub 平台发的是单段 sk 密钥,走 OpenAI 兼容协议,和旧混元三段式 AppId|SecretId|SecretKey(TC3 签名)不是一套东西。旧混元平台2026-06-22已开始下线, 2026-09-30 停服,新购只能用 TokenHub 的 api key。
改法: 因为新版兼容oai格式, 因此改法比较简单, key 含
|走原来 TC3逻辑,api key 走 OpenAI 兼容的实现即可, 代码改动较小迁服新闻: https://cloud.tencent.com/announce/detail/2310
新版平台: https://console.cloud.tencent.com/tokenhub/models
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
新建渠道,优化提示:


新版渠道,自测通过:
由于旧版渠道已无法新建,因此无法自测, 通过断点验证了旧的的url 和 tc3段key和签名正常
Summary by CodeRabbit
New Features
Tests