provider: Tencent Cloud's Token Plan is at tokenhub.tencentmaas.com/plan (ysm119)

ysm119 (Discord) showed Tencent's docs: Token Plan's OpenAI base is now
https://tokenhub.tencentmaas.com/plan/v3 and the Anthropic one on
tokenhub.tencentmaas.com is the recommended one, with
api.lkeap.cloud.tencent.com marked as going away.

Tencent's current pages (product/1823/130060 个人版 overview, 130070
Claude Code, 130071 Codex, 130119 quickstart, 136601 CC Switch, all
updated 10-15 to 10-22) give 个人版 the same endpoints as 企业版 China
(130659): chat/responses at https://tokenhub.tencentmaas.com/plan/v3,
messages at https://tokenhub.tencentmaas.com/plan/anthropic, one sk-tp-
key for 通用 and Hy plans.

- The tencent-cloud preset's plan region (and the preset default) are
  at those endpoints, with Responses added (Codex's page uses
  wire_api "responses"). magpie tells regions apart by endpoint, so the
  personal and China enterprise regions, now one address, are one:
  "plan", models the union of both lists. "enterprise" stays an alias
  (regionAliases, RegionID): a key saved on it, an import link with
  region=enterprise and `region=enterprise` on the CLI land on plan.
  Singapore 企业版 (enterprise-intl) is unchanged.
- A Tencent Cloud provider saved at the old lkeap /plan/v3 or
  /plan/anthropic is moved to TokenHub at load (moveEndpoints in
  normalize), and gains the Responses endpoint when it had chat. A
  Responses address the user set stays. A provider of no preset (a
  custom one the user typed lkeap into) keeps its address: that is the
  user's value, and lkeap still answers today.
- An app config still at lkeap (Tencent's OpenClaw page, 130062, still
  gives it) imports as tencent-cloud at the new endpoints.
- Usage: DescribeTokenPlan is 企业版's API (api/1823/132270 lists
  enterprise products only), and Guangzhou's endpoint now serves
  个人版 too, so a Guangzhou provider with no SecretId no longer gets the
  card asking for one (tcSharedRegion); Singapore's still does. The
  editor shows the optional SecretId/SecretKey at the plan region, so a
  personal user sees them too.
- docs/subsystems/providers-accounts.md says all of this.

Run at the pushed head's base f3551387c on mote (rebased onto
d29f02d65, which only touches internal/agent's omp; provider and cli
re-run after the rebase):
- go test -timeout 45m ./...: every package ok except three filed reds
  that touch nothing here: cli TestEveryRouteHasACommandOrIsNamed
  (#4826), gateway TestCodexPoolSaysTheClientsVersion (#4807), gui
  TestMainWindowCorners/macOS_26_SDK on macOS 27 (#3949).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- GUI tencent-cloud, tencent-access-key, i18n-keys (chromium+webkit,
  en/zh): 24 pass, 4 fail, all "a region clicked right after the strip
  scrolled" (#4321/#4399/#4625; app.js is unchanged here).

Broken by hand, each red then green again:
- normalize without moveEndpoints: TestTencentCloudOldPresetsKeepWorking
  and TestTencentPlanMovedFromLkeap fail.
- the import's movedEndpoints lookup: TestTencentPlanMovedFromLkeap.
- the Guangzhou card skip: TestPlanCardWithoutAccessKey.
- RegionID in ParseImport: TestTencentPlanMovedFromLkeap; in the CLI:
  TestTencentOldRegionAtCLI.

Not tried: no real Tencent key here, so no request reached either host
and no real usage read. Tencent's international personal plan (CodeBuddy
page tencentcloud.com/document/product/1300/81035) is at
tokenhub-intl.tencentcloudmaas.com, a host magpie has no region for; not
added. The 即将下线 label in ysm119's screenshot is not on the pages
fetched, and no retirement date was found (FAQ 130076). The site's
import-link builder still offers "Enterprise plan · China", which now
adds the plan through the alias.
This commit is contained in:
yetone
2026-11-02 21:41:56 +08:00
parent d29f02d650
commit c47fc516a4
11 changed files with 234 additions and 61 deletions
+1 -1
View File
@@ -325,7 +325,7 @@ and `TestHistoricalWindowHoldsUsesEachWindowsOwnReading`.
- A routing group may be held to some accounts the same way (`Group.Accounts`, duanckham on X): a request through it uses only those of a provider it names, and with a gateway key only those both allow. Entries are resolved and checked when the group is saved (`cleanGroupAccounts`, `ResolveAccount`), and dropped from a shared or imported group. See [gateway-routing](gateway-routing.md#a-route-group-held-to-chosen-accounts).
- A sub2api key's windows are fixed: each starts at the key's first request after it was empty, aligned to the relay's day, and a window not started yet says `used 0` with no `reset_at`, so it is taken to renew a span from now. They count this key's spend only, not the relay's accounts behind it. `ForgetBalances` (a key or Balance URL changed) has every key's windows read again at its next ask, a read begun before dropped; until then the last reading stands, fresher than the card's, which routing's reads never write. A key changed is another key (`keyID`), with windows of its own.
- A Volcengine Ark provider's access key (`TakesVolcAccessKey`: any of its bases on `ark.<region>.volces.com`) is kept with its keys and never sent to the GUI: `/api/providers` tells the editor its ID and whether a Secret is saved (`accessKey`). A save that leaves the Secret blank keeps it, one that leaves the ID out or sends it blank keeps both (an editor opened before the key was given sends `""`, #1821), and `clearAccessKey` drops both. The ID and Secret go together everywhere the keys go: a copy takes them, also when its form sends the source's ID without the Secret (`AddCopy`), a backup or sync without keys has neither (`withoutKeys`), and a restore, mirror or sync keeps this machine's (`KeepSecrets` in `Restore`, `Mirror`, davsync's `take`) when it came without keys, or with the same key and no access key at all, as a magpie before v0.1.1142 or one the access key was never given on sends it (#1821); another key is another account and brings its own. A copy without keys keeps this machine's secret headers (`SecretHeader`) the same way. A plan endpoint with no provider on it holding the access key is a card that says which to give (`accessKeyCard`, `needsAccessKey`), with a button to the provider's settings, not a card left out. A `providers.json` saved with a UTF-8 BOM is read through it, not taken for a broken file whose `.bak` stands in. The plan read is the endpoint's: `/api/coding` asks `GetCodingPlanUsage`, `/api/plan` asks `GetAFPUsage`, pay-as-you-go (`/api/v3`) has no card; the region is the host's. One card is read for each access key and plan. `GetCodingPlanUsage`'s reply (`QuotaUsage[]` with `Level`, `Percent`, `ResetTimestamp` in seconds) is the one three tools built on it read; `GetAFPUsage`'s buckets are read in each form those tools read (`Used` of `Quota` or `Total`, or `Percent`; `ResetTime` or `ResetTimestamp`), none of them seen from a real account here. A reply none of that reads says so on the card with the reply's head. Changing the access key drops the cached cards (`ForgetPlanQuotas`).
- A Tencent Cloud provider's SecretId and SecretKey are kept, listed and saved the same way, in the same fields (`AccessKeyVendor` tells the editor whose: `accessKey.vendor`, the preset's `accessKeyVendor`). Only the Token Plan 企业版's endpoints are read with them (`TakesTencentAccessKey`: `/plan` on `tokenhub.tencentmaas.com`, region `ap-guangzhou`, or `tokenhub-intl.tencentmaas.com`, `ap-singapore`); the personal plan (`api.lkeap.cloud.tencent.com`) has no usage API and TokenHub's pay as you go no plan, so neither has a card. The preset lists its regions that take one (`accessKeyRegions`, `presetAccessKey`), and the editor shows SecretId and SecretKey at those alone. `DescribeTokenPlanList` gives the account's team plans (a sub-user sees the ones it made); each is asked `DescribeTokenPlan` for its `PackageInfo` and `TokenSummary`, the list's kept for what the reply leaves out. The card's one window is `TotalUsed` of `CycleQuota` (else `TotalQuota`), resetting at `TokenSummary.CycleEndTime`, else counted in months from `StartTime` and never past `ExpireTime`. A plan not `enable` says its status beside the plan's name. Errors come back as 200 with `Response.Error`; an `AuthFailure…` or `UnauthorizedOperation` one says to check the key. Built from the API docs (api/1823/132270 and siblings) and the signing doc's worked example; never seen from a real account here.
- A Tencent Cloud provider's SecretId and SecretKey are kept, listed and saved the same way, in the same fields (`AccessKeyVendor` tells the editor whose: `accessKey.vendor`, the preset's `accessKeyVendor`). Only the Token Plan's endpoints are read with them (`TakesTencentAccessKey`: `/plan` on `tokenhub.tencentmaas.com`, region `ap-guangzhou`, or `tokenhub-intl.tencentmaas.com`, `ap-singapore`). Since 10-22 Tencent serves 个人版 and 企业版 in China at the same `/plan` endpoints with the same `sk-tp-` keys (product/1823/130060, 130659), so they are one region, `plan` (a key saved on `enterprise` is on it, `regionAliases`/`RegionID`); 个人版 has no usage API, so a Guangzhou provider without a SecretId gets no card asking for one (`tcSharedRegion`), while Singapore's does. A Tencent Cloud provider saved at the old personal host `api.lkeap.cloud.tencent.com/plan/...` is moved to TokenHub's at load (`movedEndpoints`, `moveEndpoints` in `normalize`), with Responses added; one of no preset keeps the address its user typed, and an app imported at the old host lands on the plan. TokenHub's pay as you go has no plan and no card. The preset lists its regions that take one (`accessKeyRegions`, `presetAccessKey`), and the editor shows SecretId and SecretKey at those alone. `DescribeTokenPlanList` gives the account's team plans (a sub-user sees the ones it made); each is asked `DescribeTokenPlan` for its `PackageInfo` and `TokenSummary`, the list's kept for what the reply leaves out. The card's one window is `TotalUsed` of `CycleQuota` (else `TotalQuota`), resetting at `TokenSummary.CycleEndTime`, else counted in months from `StartTime` and never past `ExpireTime`. A plan not `enable` says its status beside the plan's name. Errors come back as 200 with `Response.Error`; an `AuthFailure…` or `UnauthorizedOperation` one says to check the key. Built from the API docs (api/1823/132270 and siblings) and the signing doc's worked example; never seen from a real account here.
- Whether a Codex account spends its credits (`CodexNoCredits` in settings, opt-out, by lower-cased email) is the gateway's routing only. It never changes which account Codex is signed in to: `NextLogin` moves off an account at its routing's spent share, 100% at most, credits or not.
- A Vertex AI provider's credentials are read only when a request is signed (`Sign`), so adding, listing and showing one ask Google nothing. With no `credentials` given and no file where Application Default Credentials are looked for, the request fails with `no Google credentials at <file>`, naming `gcloud auth application-default login` and the provider's credentials file as the ways to give it some. A `credentials` file that isn't there fails with the same words, saying to correct it or clear it. When Google refuses a person's sign-in (revoked, or past the organization's session length), the error says how to sign in again for the file used (`signInAgain`): gcloud's Application Default Credentials with `gcloud auth application-default login`, adding `--impersonate-service-account=<account>` when the file impersonates one; a file under gcloud's `legacy_credentials/<account>/` with `gcloud auth login <account>`; any other file by writing it anew or giving the provider another. The new file is read at the next request, with no restart.
- Not read for Vertex AI: the metadata server of Compute Engine, Cloud Run and GKE; workload identity federation (`external_account`, `external_account_authorized_user`, refused by name); credentials whose `universe_domain` isn't `googleapis.com`; Vertex AI's express-mode API keys (Save refuses a key). No quota project is sent: Vertex AI bills the project in the URL.
+2 -1
View File
@@ -1078,7 +1078,8 @@ func applyPairs(p *provider.Provider, pairs []string) error {
for _, r := range pr.Regions {
ids = append(ids, r.ID)
}
i := slices.IndexFunc(pr.Regions, func(r provider.Region) bool { return strings.EqualFold(r.ID, v) })
id := provider.RegionID(p.Preset, v)
i := slices.IndexFunc(pr.Regions, func(r provider.Region) bool { return strings.EqualFold(r.ID, id) })
if i < 0 {
return fmt.Errorf("%s=%s: %s's are %s", k, v, pr.Name, strings.Join(ids, ", "))
}
+15
View File
@@ -81,3 +81,18 @@ func TestRemoteMagpieAddReportsModels(t *testing.T) {
})
}
}
// region=enterprise on Tencent Cloud, from before Token Plan 个人版 and
// 企业版 in China were served at one endpoint (ysm119), is the plan's.
func TestTencentOldRegionAtCLI(t *testing.T) {
p, _ := provider.FromPreset("tencent-cloud")
if err := applyPairs(&p, []string{"region=intl"}); err != nil {
t.Fatal(err)
}
if err := applyPairs(&p, []string{"region=enterprise"}); err != nil {
t.Fatal(err)
}
if p.Chat != "https://tokenhub.tencentmaas.com/plan/v3" || p.Anthropic != "https://tokenhub.tencentmaas.com/plan/anthropic" {
t.Fatalf("region=enterprise: %s %s", p.Chat, p.Anthropic)
}
}
+6 -4
View File
@@ -2,7 +2,9 @@ package gui
// Tencent Cloud's Token Plan 企业版 is read with the account's SecretId and
// SecretKey (#1574): the listing tells the editor the Tencent Cloud preset
// takes one at its two Enterprise regions alone, and whose it is, and a
// takes one at its plan regions alone (China's, which Token Plan 个人版
// shares with 企业版 since Tencent moved it there, ysm119; and 企业版's
// in Singapore), not at pay as you go, and whose it is, and a
// provider of it, at whatever region, its SecretId and whether a
// SecretKey is saved, never the SecretKey. Volcengine Ark's take one at
// all of theirs; another vendor's at none.
@@ -41,7 +43,7 @@ func TestProviderListTellsTencentAccessKey(t *testing.T) {
}
return p
}
team := at("enterprise")
team := at("enterprise-intl")
team.Key, team.AccessKeyID, team.SecretAccessKey = "sk-tp-1", "AKID-1", "SK-1"
if err := provider.Save(team); err != nil {
t.Fatal(err)
@@ -82,7 +84,7 @@ func TestProviderListTellsTencentAccessKey(t *testing.T) {
if a := ps["tencent-cloud"]; a == nil || a.Vendor != "tencent" || a.ID != "AKID-1" || !a.SecretSet {
t.Errorf("enterprise: %+v", a)
}
// at the personal plan it still takes one, for when it is moved
// at China's plan, 个人版's and 企业版's both, it takes one too
if a := ps["tc-personal"]; a == nil || a.Vendor != "tencent" || a.ID != "" || a.SecretSet {
t.Errorf("personal: %+v", a)
}
@@ -91,7 +93,7 @@ func TestProviderListTellsTencentAccessKey(t *testing.T) {
switch pr.ID {
case "tencent-cloud":
seen++
if !pr.AccessKey || pr.AccessKeyVendor != "tencent" || !slices.Equal(pr.AccessKeyRegions, []string{"enterprise", "enterprise-intl"}) {
if !pr.AccessKey || pr.AccessKeyVendor != "tencent" || !slices.Equal(pr.AccessKeyRegions, []string{"plan", "enterprise-intl"}) {
t.Errorf("tencent-cloud preset: %+v", pr)
}
case "volcengine":
+8
View File
@@ -377,6 +377,14 @@ type endpoints struct{ chat, responses, anthropic, gemini string }
// host, like a coding plan), a custom one otherwise.
func imported(name, key string, e endpoints, models []string) (Provider, string) {
e.chat, e.responses, e.anthropic, e.gemini = cleanBase(e.chat), cleanBase(e.responses), cleanBase(e.anthropic), cleanBase(e.gemini)
// an app still set up at an endpoint its vendor has moved since
// (Tencent's OpenClaw page still gives the Token Plan's old host) is
// imported at where it is now
for _, u := range []*string{&e.chat, &e.responses, &e.anthropic} {
if m, ok := movedEndpoints[strings.ToLower(*u)]; ok {
*u = cmp.Or(m.chat, m.responses, m.anthropic)
}
}
for _, u := range []string{e.chat, e.responses, e.anthropic, e.gemini} {
if u == "" {
continue
+1
View File
@@ -67,6 +67,7 @@ func ParseImport(link string) (Provider, error) {
if r := get("region"); r != "" {
found := false
pr := Preset(p.Preset)
r = RegionID(p.Preset, r) // a link made before its region was merged still adds
for _, reg := range pr.Regions {
if reg.ID == r {
// atRegionOf is where a region's endpoints land: chat,
+4 -1
View File
@@ -176,7 +176,10 @@ func TestPlanCardWithoutAccessKey(t *testing.T) {
// pay-as-you-go reads nothing with an access key
{ID: "volc-payg", Name: "Ark API", Chat: "https://ark.cn-beijing.volces.com/api/v3", Key: "ark-k"},
{ID: "volc-off", Name: "Ark off", Chat: "https://ark.cn-beijing.volces.com/api/plan/v3", Key: "ark-k", Off: true},
{ID: "tencent-cloud", Name: "Tencent Cloud", Chat: "https://tokenhub.tencentmaas.com/plan/v3", Key: "sk-tp-1"},
{ID: "tencent-cloud", Name: "Tencent Cloud", Chat: "https://tokenhub-intl.tencentmaas.com/plan/v3", Key: "sk-tp-1"},
// China's /plan is Token Plan 个人版's too, which has no usage to
// read (ysm119): no card asks it for an access key
{ID: "tc-gz", Name: "Tencent China", Chat: "https://tokenhub.tencentmaas.com/plan/v3", Key: "sk-tp-2"},
} {
if err := Save(p); err != nil {
t.Fatal(err)
+84 -19
View File
@@ -3,6 +3,7 @@ package provider
import (
"cmp"
"slices"
"strings"
)
// A preset is a vendor magpie already knows: adding one only asks for the key.
@@ -310,11 +311,19 @@ var presets = []PresetDef{
// pay as you go picked inside it, as Xiaomi MiMo's are), once three
// presets, whose ids still name it, each at its region (presetAliases):
//
// Its Token Plan (TokenHub's subscription): a general and a Hy plan on
// one sk-tp- key, served at their own endpoints under /plan, chat
// completions and Anthropic messages only (its Codex page asks for
// wire_api "chat"). models.dev lists just its Hy models, so the plan's
// are given here, and none of its catalogs names them.
// Its Token Plan (TokenHub's subscription): 个人版, a general and a Hy
// plan on one sk-tp- key, and 企业版 (#1574), a team's monthly plan, its
// 专业套餐 counted in credits and its 轻享套餐 in tokens. Both are served
// at the same endpoints on TokenHub's hosts under /plan: chat
// completions and Responses at /plan/v3, Anthropic messages at
// /plan/anthropic (个人版 product/1823/130060, 130119, its Codex page
// 130071 with wire_api "responses"; 企业版 130659), the key telling the
// plan. China's is one region for both, so its models are the two
// plans' together; 企业版 alone is sold in Singapore too. models.dev
// lists just the plans' Hy models, so they are given here, and none of
// its catalogs names them. 个人版 was at api.lkeap.cloud.tencent.com
// until Tencent moved it (ysm119 on Discord, 11-02): a provider saved
// there is moved (movedEndpoints).
//
// TokenHub pay as you go: an API key of TokenHub's own (not the plan's
// sk-tp-), at tokenhub.tencentmaas.com in Guangzhou and
@@ -324,29 +333,20 @@ var presets = []PresetDef{
// messages at /v1/messages, with its list at /v1/models. It serves Hy
// and other makers' models (DeepSeek, GLM, Kimi, MiniMax, Qwen …):
// Hosts, and models.dev's tencent-tokenhub for their names and prices.
//
// Token Plan 企业版 (#1574): a team's monthly plan, its 专业套餐 counted
// in credits and its 轻享套餐 in tokens, on TokenHub's hosts under /plan
// (chat completions and Responses at /plan/v3, Anthropic messages at
// /plan/anthropic; product/1823/130659 and 131173), a key of the team's.
{ID: "tencent-cloud", Name: "Tencent Cloud", Icon: "tencentcloud-color", Kind: KindVendor, Hosts: true,
Chat: "https://api.lkeap.cloud.tencent.com/plan/v3", Anthropic: "https://api.lkeap.cloud.tencent.com/plan/anthropic",
Chat: "https://tokenhub.tencentmaas.com/plan/v3", Responses: "https://tokenhub.tencentmaas.com/plan/v3", Anthropic: "https://tokenhub.tencentmaas.com/plan/anthropic",
Note: "Token Plan · pay as you go",
Website: "https://cloud.tencent.com/document/product/1823/130060", KeysURL: "https://console.cloud.tencent.com/tokenhub/tokenplan",
KeyPlans: true, Regions: []Region{
{ID: "plan", Name: "Plan · China", Chat: "https://api.lkeap.cloud.tencent.com/plan/v3", Anthropic: "https://api.lkeap.cloud.tencent.com/plan/anthropic",
{ID: "plan", Name: "Plan · China", Chat: "https://tokenhub.tencentmaas.com/plan/v3", Responses: "https://tokenhub.tencentmaas.com/plan/v3", Anthropic: "https://tokenhub.tencentmaas.com/plan/anthropic",
Website: "https://cloud.tencent.com/document/product/1823/130060", KeysURL: "https://console.cloud.tencent.com/tokenhub/tokenplan",
Models: []string{"tc-code-latest", "glm-5.3", "glm-5.3-flash", "glm-5.2", "glm-5.1", "glm-5", "kimi-k3", "kimi-k2.7-code",
"deepseek-v4-pro-202606", "deepseek-v4-flash-202605", "minimax-m3", "minimax-m2.7", "hy4-preview", "hy3"}},
Models: []string{"tc-code-latest", "auto", "glm-5.3", "glm-5.3-flash", "glm-5.2", "glm-5.1", "glm-5", "kimi-k3", "kimi-k2.7-code", "kimi-k2.7-code-highspeed", "kimi-k2.6",
"deepseek-v4-pro-202606", "deepseek-v4-flash-202605", "deepseek-v4.1-flash", "deepseek-v4-pro", "deepseek-v4-pro-0813", "deepseek-v4-flash-0731",
"minimax-m3", "minimax-m2.7", "hy4-preview", "hy3", "mimo-v2.6-pro", "mimo-v2.6-flash"}},
{ID: "cn", Name: "Pay as you go · China", Chat: "https://tokenhub.tencentmaas.com/v1", Responses: "https://tokenhub.tencentmaas.com/v1", Anthropic: "https://tokenhub.tencentmaas.com",
Website: "https://cloud.tencent.com/document/product/1823/130078", KeysURL: "https://console.cloud.tencent.com/tokenhub/apikey", Catalog: "tencent-tokenhub"},
{ID: "intl", Name: "Pay as you go · Global", Chat: "https://tokenhub-intl.tencentmaas.com/v1", Responses: "https://tokenhub-intl.tencentmaas.com/v1", Anthropic: "https://tokenhub-intl.tencentmaas.com",
Website: "https://www.tencentcloud.com/document/product/1300/78939", KeysURL: "https://console.tencentcloud.com/tokenhub/apikey", Catalog: "tencent-tokenhub"},
{ID: "enterprise", Name: "Enterprise plan · China", Chat: "https://tokenhub.tencentmaas.com/plan/v3", Responses: "https://tokenhub.tencentmaas.com/plan/v3", Anthropic: "https://tokenhub.tencentmaas.com/plan/anthropic",
Website: "https://cloud.tencent.com/document/product/1823/130659", KeysURL: "https://console.cloud.tencent.com/tokenhub/tokenplan",
Models: []string{"auto", "hy4-preview", "glm-5.3", "glm-5.3-flash", "glm-5.2", "kimi-k3", "kimi-k2.7-code", "kimi-k2.7-code-highspeed", "kimi-k2.6",
"minimax-m3", "minimax-m2.7", "deepseek-v4.1-flash", "deepseek-v4-pro", "deepseek-v4-pro-0813", "deepseek-v4-flash-0731",
"deepseek-v4-pro-202606", "deepseek-v4-flash-202605", "mimo-v2.6-pro", "mimo-v2.6-flash"}},
{ID: "enterprise-intl", Name: "Enterprise plan · Global", Chat: "https://tokenhub-intl.tencentmaas.com/plan/v3", Responses: "https://tokenhub-intl.tencentmaas.com/plan/v3", Anthropic: "https://tokenhub-intl.tencentmaas.com/plan/anthropic",
Website: "https://cloud.tencent.com/document/product/1823/130659", KeysURL: "https://console.tencentcloud.com/tokenhub/tokenplan",
Models: []string{"auto", "hy4-preview", "glm-5.3", "glm-5.3-flash", "glm-5.2", "kimi-k3", "kimi-k2.7-code", "kimi-k2.7-code-highspeed",
@@ -782,6 +782,71 @@ var presetAliases = map[string]struct{ preset, region string }{
"tencent-tokenhub": {"tencent-cloud", "intl"},
}
// movedEndpoints are base URLs a preset gave before its vendor moved
// them, each the one it is at now: Tencent Cloud's Token Plan 个人版 left
// api.lkeap.cloud.tencent.com for TokenHub's host (ysm119 on Discord,
// 11-02; product/1823/130060), where its 企业版 already was, and it serves
// Responses there too.
var movedEndpoints = map[string]struct{ chat, responses, anthropic string }{
"https://api.lkeap.cloud.tencent.com/plan/v3": {chat: "https://tokenhub.tencentmaas.com/plan/v3", responses: "https://tokenhub.tencentmaas.com/plan/v3"},
"https://api.lkeap.cloud.tencent.com/plan/anthropic": {anthropic: "https://tokenhub.tencentmaas.com/plan/anthropic"},
}
// regionAliases are region ids a preset's keys may name from before its
// regions were made one: Tencent Cloud's 企业版 in China is its plan.
var regionAliases = map[string]map[string]string{
"tencent-cloud": {"enterprise": "plan"},
}
// RegionID is the region a preset's region id names now: an id from
// before regions were made one (a key's plan, an import link, region= on
// the command line) is the region it became.
func RegionID(preset, id string) string {
if a, ok := regionAliases[preset][strings.ToLower(id)]; ok {
return a
}
return id
}
// moveEndpoints puts a preset's provider saved at endpoints its vendor
// has since moved (movedEndpoints) at where they are now, with the APIs
// served beside them there that it has none of. Only an endpoint the
// preset gave is moved: one a provider of no preset was given (the
// user's own, a relay's) is left as it is, and so is the rest of the
// provider. A key's plan named by an old region id is its region since.
func (p *Provider) moveEndpoints() {
if p.Preset == "" || builtinPreset(p.Preset) == nil {
return
}
var to struct{ chat, responses, anthropic string }
for _, u := range []*string{&p.Chat, &p.Responses, &p.Anthropic} {
m, ok := movedEndpoints[strings.ToLower(*u)]
if !ok {
continue
}
*u = cmp.Or(m.chat, m.responses, m.anthropic)
to.chat, to.responses, to.anthropic = cmp.Or(to.chat, m.chat), cmp.Or(to.responses, m.responses), cmp.Or(to.anthropic, m.anthropic)
}
for _, f := range []struct {
have *string
to string
}{{&p.Chat, to.chat}, {&p.Responses, to.responses}, {&p.Anthropic, to.anthropic}} {
if *f.have == "" && f.to != "" {
*f.have = f.to
}
}
if as := regionAliases[p.Preset]; as != nil {
if r, ok := as[p.KeyPlan]; ok {
p.KeyPlan = r
}
for i := range p.Keys {
if r, ok := as[p.Keys[i].Plan]; ok {
p.Keys[i].Plan = r
}
}
}
}
// Preset finds a preset by id, or by an id it carried before
// (presetAliases), or a partner listed now or before (partners.go).
func Preset(id string) *PresetDef {
+3
View File
@@ -1552,6 +1552,9 @@ func normalize(p Provider) Provider {
if a, ok := presetAliases[p.Preset]; ok {
p.Preset = a.preset
}
// a preset's endpoints its vendor has moved since (Tencent Cloud's
// Token Plan 个人版, ysm119) are where they are now
p.moveEndpoints()
// OpenCode Zen serves its free models (-free) signed out, to the key
// OpenCode itself sends then: a Zen provider saved with no key of its
// own asks with that one
+93 -26
View File
@@ -14,16 +14,19 @@ import (
)
const (
tcPlanChat = "https://api.lkeap.cloud.tencent.com/plan/v3"
tcPlanMsgs = "https://api.lkeap.cloud.tencent.com/plan/anthropic"
tcPlanKeys = "https://console.cloud.tencent.com/tokenhub/tokenplan"
tcPlanDocs = "https://cloud.tencent.com/document/product/1823/130060"
tcCNHost = "https://tokenhub.tencentmaas.com"
tcCNKeys = "https://console.cloud.tencent.com/tokenhub/apikey"
tcCNDocs = "https://cloud.tencent.com/document/product/1823/130078"
tcIntlHost = "https://tokenhub-intl.tencentmaas.com"
tcIntlKeys = "https://console.tencentcloud.com/tokenhub/apikey"
tcIntlDocs = "https://www.tencentcloud.com/document/product/1300/78939"
tcPlanChat = "https://tokenhub.tencentmaas.com/plan/v3"
tcPlanMsgs = "https://tokenhub.tencentmaas.com/plan/anthropic"
// where Token Plan 个人版 was before Tencent moved it (ysm119)
tcOldPlanChat = "https://api.lkeap.cloud.tencent.com/plan/v3"
tcOldPlanMsgs = "https://api.lkeap.cloud.tencent.com/plan/anthropic"
tcPlanKeys = "https://console.cloud.tencent.com/tokenhub/tokenplan"
tcPlanDocs = "https://cloud.tencent.com/document/product/1823/130060"
tcCNHost = "https://tokenhub.tencentmaas.com"
tcCNKeys = "https://console.cloud.tencent.com/tokenhub/apikey"
tcCNDocs = "https://cloud.tencent.com/document/product/1823/130078"
tcIntlHost = "https://tokenhub-intl.tencentmaas.com"
tcIntlKeys = "https://console.tencentcloud.com/tokenhub/apikey"
tcIntlDocs = "https://www.tencentcloud.com/document/product/1300/78939"
)
// tcRegions are Tencent Cloud's three, as the three presets they were
@@ -34,7 +37,7 @@ var tcRegions = []struct {
chat, responses, anthropic string
catalog, keys, website string
}{
{"tencent-token-plan", "plan", tcPlanChat, "", tcPlanMsgs, "", tcPlanKeys, tcPlanDocs},
{"tencent-token-plan", "plan", tcPlanChat, tcPlanChat, tcPlanMsgs, "", tcPlanKeys, tcPlanDocs},
{"tencent-tokenhub-cn", "cn", tcCNHost + "/v1", tcCNHost + "/v1", tcCNHost, "tencent-tokenhub", tcCNKeys, tcCNDocs},
{"tencent-tokenhub", "intl", tcIntlHost + "/v1", tcIntlHost + "/v1", tcIntlHost, "tencent-tokenhub", tcIntlKeys, tcIntlDocs},
}
@@ -55,7 +58,7 @@ func TestTencentCloud(t *testing.T) {
t.Fatalf("Tencent Cloud's presets: %+v", tc)
}
pr := &tc[0]
if len(pr.Regions) != 5 {
if len(pr.Regions) != 4 {
t.Fatalf("regions: %+v", pr.Regions)
}
for i, c := range tcRegions {
@@ -83,7 +86,7 @@ func TestTencentCloud(t *testing.T) {
}
// the default is the plan, as the add sheet's Tencent Cloud was
p, _ := FromPreset("tencent-cloud")
if p.Chat != tcPlanChat || p.Anthropic != tcPlanMsgs || p.Responses != "" || p.Catalog != "" || p.KeysURL != tcPlanKeys {
if p.Chat != tcPlanChat || p.Anthropic != tcPlanMsgs || p.Responses != tcPlanChat || p.Catalog != "" || p.KeysURL != tcPlanKeys {
t.Fatalf("default: %+v", p)
}
for _, id := range pr.Regions[0].Models {
@@ -149,17 +152,18 @@ func TestTencentCloud(t *testing.T) {
}
}
// Token Plan 企业版 (#1574) is a region of Tencent Cloud's in China and
// one in Singapore, at TokenHub's hosts under /plan with chat completions,
// Responses and Anthropic messages, its own models before a list: an
// entry imported at its endpoints, a link and a provider moved there in
// the editor each land on it, and TokenHub's pay as you go at the same
// hosts stays where it was.
// Token Plan 企业版 (#1574) is at TokenHub's hosts under /plan with chat
// completions, Responses and Anthropic messages: in China at the plan's
// region, which 个人版 is at too since Tencent moved it there (ysm119), in
// Singapore at a region of its own, each with its own models before a
// list: an entry imported at its endpoints, a link and a provider moved
// there in the editor each land on it, and TokenHub's pay as you go at
// the same hosts stays where it was.
func TestTencentCloudEnterprisePlan(t *testing.T) {
pr := Preset("tencent-cloud")
for _, c := range []struct{ region, host, keys string }{
{"enterprise", tcCNHost, tcPlanKeys},
{"enterprise-intl", tcIntlHost, "https://console.tencentcloud.com/tokenhub/tokenplan"},
for _, c := range []struct{ region, host, keys, docs, first string }{
{"plan", tcCNHost, tcPlanKeys, tcPlanDocs, "tc-code-latest"},
{"enterprise-intl", tcIntlHost, "https://console.tencentcloud.com/tokenhub/tokenplan", "https://cloud.tencent.com/document/product/1823/130659", "auto"},
} {
var r *Region
for i := range pr.Regions {
@@ -168,8 +172,8 @@ func TestTencentCloudEnterprisePlan(t *testing.T) {
}
}
if r == nil || r.Chat != c.host+"/plan/v3" || r.Responses != c.host+"/plan/v3" || r.Anthropic != c.host+"/plan/anthropic" ||
r.Catalog != "" || r.KeysURL != c.keys || r.Website != "https://cloud.tencent.com/document/product/1823/130659" ||
len(r.Models) == 0 || r.Models[0] != "auto" {
r.Catalog != "" || r.KeysURL != c.keys || r.Website != c.docs ||
len(r.Models) == 0 || r.Models[0] != c.first {
t.Fatalf("%s: %+v", c.region, r)
}
for _, id := range r.Models {
@@ -190,7 +194,7 @@ func TestTencentCloudEnterprisePlan(t *testing.T) {
if err != nil || p.Chat != r.Chat || p.Responses != r.Responses || p.Anthropic != r.Anthropic || p.KeysURL != c.keys {
t.Fatalf("link: %v %+v", err, p)
}
if got := p.planModels(nil); len(got) != len(r.Models) || got[0].ID != "auto" {
if got := p.planModels(nil); len(got) != len(r.Models) || got[0].ID != c.first {
t.Fatalf("%s's models: %+v", c.region, got)
}
// pay as you go at the same host moved here takes the plan's key
@@ -221,7 +225,7 @@ func TestTencentCloudOldPresetsKeepWorking(t *testing.T) {
// providers.json as an older magpie wrote it
old := `{"providers":[
{"id":"tencent-token-plan","name":"Tencent Cloud Token Plan","icon":"tencentcloud-color","preset":"tencent-token-plan","key":"sk-tp-plan",
"chat":"` + tcPlanChat + `","anthropic":"` + tcPlanMsgs + `","models":["glm-5.3","hy3"],"website":"` + tcPlanDocs + `","keysUrl":"` + tcPlanKeys + `"},
"chat":"` + tcOldPlanChat + `","anthropic":"` + tcOldPlanMsgs + `","models":["glm-5.3","hy3"],"website":"` + tcPlanDocs + `","keysUrl":"` + tcPlanKeys + `"},
{"id":"tencent-tokenhub-cn","name":"Tencent Cloud TokenHub (China)","icon":"tencentcloud-color","preset":"tencent-tokenhub-cn","key":"sk-cn",
"chat":"` + tcCNHost + `/v1","responses":"` + tcCNHost + `/v1","anthropic":"` + tcCNHost + `","models":["hy3","deepseek-v4-pro"],"catalog":"tencent-tokenhub","website":"` + tcCNDocs + `","keysUrl":"` + tcCNKeys + `"},
{"id":"tencent-tokenhub","name":"Tencent Cloud TokenHub","icon":"tencentcloud-color","preset":"tencent-tokenhub","key":"sk-intl",
@@ -319,3 +323,66 @@ func TestTencentTokenHubList(t *testing.T) {
t.Fatalf("%+v", ms)
}
}
// Tencent moved Token Plan 个人版 from api.lkeap.cloud.tencent.com to
// TokenHub's host (ysm119 on Discord, 11-02; product/1823/130060): a
// Tencent Cloud provider saved at the old endpoints is at the new ones,
// with the Responses API served there beside them, and at the plan's
// region; an endpoint the user gave a provider of no preset, or another
// API's they set, is left as it is. A key on 企业版 in China, a region
// now the plan's, is on the plan. An app still set up at the old host
// (Tencent's OpenClaw page gives it) is imported at the new one.
func TestTencentPlanMovedFromLkeap(t *testing.T) {
pr := Preset("tencent-cloud")
n := normalize(Provider{ID: "tc", Preset: "tencent-cloud", Chat: tcOldPlanChat, Anthropic: tcOldPlanMsgs, Key: "sk-tp-1"})
if n.Chat != tcPlanChat || n.Responses != tcPlanChat || n.Anthropic != tcPlanMsgs {
t.Fatalf("moved: %+v", n)
}
if r := n.regionOf(pr); r == nil || r.ID != "plan" {
t.Fatalf("at %+v", r)
}
// as a hand-edited file may have it
if n := normalize(Provider{ID: "tc", Preset: "tencent-token-plan", Chat: "HTTPS://api.lkeap.cloud.tencent.com/plan/v3/ "}); n.Chat != tcPlanChat || n.Responses != tcPlanChat || n.Anthropic != "" {
t.Fatalf("written another way: %+v", n)
}
// Anthropic's alone: no other API is added
if n := normalize(Provider{ID: "tc", Preset: "tencent-cloud", Anthropic: tcOldPlanMsgs}); n.Anthropic != tcPlanMsgs || n.Chat != "" || n.Responses != "" {
t.Fatalf("messages alone: %+v", n)
}
// a Responses endpoint the user set stays theirs
if n := normalize(Provider{ID: "tc", Preset: "tencent-cloud", Chat: tcOldPlanChat, Responses: "https://relay.example.com/v1"}); n.Chat != tcPlanChat || n.Responses != "https://relay.example.com/v1" {
t.Fatalf("own Responses: %+v", n)
}
// a provider of no preset is asked where the user said
if n := normalize(Provider{ID: "mine", Chat: tcOldPlanChat, Anthropic: tcOldPlanMsgs}); n.Chat != tcOldPlanChat || n.Responses != "" || n.Anthropic != tcOldPlanMsgs {
t.Fatalf("own endpoints: %+v", n)
}
// keys on the China 企业版 region are on the plan's
k := normalize(Provider{ID: "tc", Preset: "tencent-cloud", Chat: tcIntlHost + "/plan/v3", KeyPlan: "enterprise",
Keys: []KeyAccount{{Key: "sk-tp-2", Plan: "enterprise"}, {Key: "sk-tp-3", Plan: "cn"}}})
if k.KeyPlan != "plan" || k.Keys[0].Plan != "plan" || k.Keys[1].Plan != "cn" {
t.Fatalf("key plans: %q %+v", k.KeyPlan, k.Keys)
}
if got := k.atKeyPlan(k.KeyPlan); got.Chat != tcCNHost+"/plan/v3" {
t.Fatalf("a China 企业版 key asked at %s", got.Chat)
}
// another preset's key plan named so is its own
if v := normalize(Provider{ID: "v", Preset: "volcengine", Chat: "https://ark.cn-beijing.volces.com/api/coding/v3", KeyPlan: "enterprise"}); v.KeyPlan != "enterprise" {
t.Fatalf("volcengine: %q", v.KeyPlan)
}
// an import link made when 企业版 China was a region of its own
l, err := ParseImport("magpie://import?preset=tencent-cloud&region=enterprise")
if err != nil || l.Chat != tcPlanChat || l.Anthropic != tcPlanMsgs {
t.Fatalf("link to the old region: %+v %v", l, err)
}
// Tencent's OpenClaw page's baseUrl, imported from the app
for _, e := range []endpoints{{chat: tcOldPlanChat}, {anthropic: tcOldPlanMsgs + "/"}} {
im, _ := imported("TencentCloud_Token_Plan", "sk-tp-x", e, nil)
if im.Preset != "tencent-cloud" || strings.Contains(im.Chat+im.Responses+im.Anthropic, "lkeap") || im.KeysURL != tcPlanKeys {
t.Fatalf("imported from %+v: %+v", e, im)
}
if r := im.regionOf(pr); r == nil || r.ID != "plan" {
t.Fatalf("imported from %+v at %+v", e, r)
}
}
}
+17 -9
View File
@@ -7,10 +7,15 @@ package provider
// 2026-03-22, signed TC3-HMAC-SHA256 with the account's API key, a
// SecretId and SecretKey (AccessKeyID, SecretAccessKey), never with the
// plan's own sk- key. The plan a provider is on is its endpoint's: /plan
// on tokenhub.tencentmaas.com is the enterprise plan in Guangzhou, on
// tokenhub-intl.tencentmaas.com in Singapore. The personal plan
// (api.lkeap.cloud.tencent.com) has no API for its usage, only the
// console, and TokenHub's pay as you go no plan: neither has a card.
// on tokenhub.tencentmaas.com is a Token Plan in Guangzhou, on
// tokenhub-intl.tencentmaas.com 企业版 in Singapore. Guangzhou's is 个人版
// too, at the same endpoints since Tencent moved it there from
// api.lkeap.cloud.tencent.com (ysm119, 11-02), and the key alone tells
// which: 个人版 has no API for its usage, only the console. So a provider
// there is asked for the access key, but given none it has no card
// saying so, which a personal plan would show for nothing; in Singapore,
// where 企业版 alone is sold, it has. TokenHub's pay as you go has no
// plan and no card.
//
// The request is signed as Tencent's signing doc (api/213/30654) says:
// the canonical request with content-type, host and x-tc-action signed,
@@ -41,7 +46,10 @@ const (
tcAPIService = "tokenhub"
tcContentType = "application/json; charset=utf-8"
tcPlanName = "Token Plan Enterprise"
tcKeyHint = "check the SecretId and SecretKey in the provider's editor (Tencent Cloud console → Access management → API keys), and that the key may read TokenHub (CAM)"
// tcSharedRegion is the cloud API region whose /plan endpoints serve
// Token Plan 个人版 as well as 企业版
tcSharedRegion = "ap-guangzhou"
tcKeyHint = "check the SecretId and SecretKey in the provider's editor (Tencent Cloud console → Access management → API keys), and that the key may read TokenHub (CAM)"
)
// TakesTencentAccessKey says p is on Tencent Cloud's Token Plan 企业版 (at
@@ -66,9 +74,9 @@ func AccessKeyVendor(p Provider) string {
}
// tencentPlanRegion is the cloud API region of the enterprise plan p's
// endpoint is on: ap-guangzhou for tokenhub.tencentmaas.com/plan,
// ap-singapore for tokenhub-intl.tencentmaas.com/plan; ok false for
// TokenHub's pay as you go, the personal plan or another vendor.
// endpoint is on: ap-guangzhou for tokenhub.tencentmaas.com/plan (which
// is 个人版's too), ap-singapore for tokenhub-intl.tencentmaas.com/plan;
// ok false for TokenHub's pay as you go or another vendor.
func tencentPlanRegion(p Provider) (string, bool) {
if p.Account != nil {
return "", false
@@ -142,7 +150,7 @@ func tencentPlanQuotas(ctx context.Context) []SubscriptionQuota {
out = append(out, qs...)
}
for _, j := range keyless {
if keyed[j.region] || seen["none "+j.region] || !wantsCard(ctx, j.p.ID, "") {
if keyed[j.region] || seen["none "+j.region] || j.region == tcSharedRegion || !wantsCard(ctx, j.p.ID, "") {
continue
}
seen["none "+j.region] = true