Skip to content

feat: support Tencent TokenHub API key via OpenAI-compatible protocol - #6232

Merged
Calcium-Ion merged 3 commits into
QuantumNous:mainfrom
feitianbubu:pr/45f4da8a0
Jul 25, 2026
Merged

feat: support Tencent TokenHub API key via OpenAI-compatible protocol#6232
Calcium-Ion merged 3 commits into
QuantumNous:mainfrom
feitianbubu:pr/45f4da8a0

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 15, 2026

Copy link
Copy Markdown
Member

📝 变更描述 / 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

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

新建渠道,优化提示:
image
新版渠道,自测通过:
image

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

Summary by CodeRabbit

  • New Features

    • Added support for Tencent services using both native and OpenAI-compatible API formats.
    • Tencent channels now support streaming responses.
    • Added automatic routing based on API key format and sensible default endpoint handling.
  • Tests

    • Added coverage for native Tencent, TokenHub-compatible, default endpoint, and custom endpoint configurations.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Tencent 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.

Changes

Tencent adaptor dispatch

Layer / File(s) Summary
Tencent adaptor selection and wiring
relay/channel/tencent/dispatch.go, relay/channel/tencent/dispatch_test.go, relay/relay_adaptor.go, relay/common/relay_info.go
DispatchAdaptor selects the native or OpenAI-compatible adaptor, applies TokenHub URL defaults, exposes Tencent metadata, is wired into relay adaptor creation, and is tested alongside Tencent stream support.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: calcium-ion

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
Loading

Poem

A rabbit hops through Tencent’s gate,
Keys choose the path and set the state.
Native paws or OpenAI flow,
Streamy ears now proudly show.
Thump, thump—dispatch is on its way!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: Tencent TokenHub API keys are now supported through the OpenAI-compatible path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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/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

📥 Commits

Reviewing files that changed from the base of the PR and between e31cfd5 and 93a7f8b.

📒 Files selected for processing (4)
  • relay/channel/tencent/dispatch.go
  • relay/channel/tencent/dispatch_test.go
  • relay/common/relay_info.go
  • relay/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,

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.

🎯 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/tencent

Repository: 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 || true

Repository: 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.go

Repository: 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

@Calcium-Ion
Calcium-Ion merged commit 08f88d2 into QuantumNous:main Jul 25, 2026
1 check passed
agogo233 pushed a commit to agogo233/new-api that referenced this pull request Jul 27, 2026
…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
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
…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
Jaykebc1 added a commit to wrouter/wrouter that referenced this pull request Jul 30, 2026
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.
IQZZ020501 pushed a commit to IQZZ020501/new-api that referenced this pull request Jul 30, 2026
…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
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
…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
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.

2 participants