Files
plugins/packages/trae
yetone 2caced14ef trae 0.1.6: the usage card says Trae CN's credits in the Credits row, as WorkBuddy's, not as an English balance line under it (yetone/magpie#694, Hu9956 on magpie 0.1.784: 积分显示的样式有点不一样 — WorkBuddy's cards read "积分 1,689.01 / 2,400 积分 · 剩余 70.4%", Trae CN's "积分 剩余 60.7%" with "余额 2307.42 of 3800 credits left" in large type below) — usage gave the share alone on its Credits window and the count as a balance string, "<left> of <limit> credits left", which magpie shows as a separate 余额 row (balanceRow, beside windows) in the plugin's own English and number format, and never flips with 已用/剩余. The window now carries the count as WorkBuddy's does (amount = credits used, limit = the packs' total, unit "credits", magpie#659), so magpie's quotaCount writes "2,307.42 / 3,800 积分 · 剩余 60.7%" (or "1,492.58 / 3,800 积分 · 已用 39.3%"; "credits" in English) in the row itself, and the balance is left out; an unlimited account still says "unlimited" as its balance. No magpie change needed: plugin_usage.go already passes a plugin window's amount, limit and unit to the card. usage.test.mjs now expects the window's amount/limit/unit and no balance (fails on 0.1.5); HOME=$(mktemp -d) bun test (465 pass) and bun scripts/check.mjs trae pass. Checked in magpie's Usage page (webkit, zh and en, API faked with the old and new shapes beside WorkBuddy and WorkBuddy AI cards): the Trae CN card's row reads like WorkBuddy's and the 余额 line is gone. Not tried with a real Trae CN account.
2026-10-04 13:07:10 +08:00
..
trae 0.1.4: the account's fetch sends Trae CN's own pages on api.trae.cn as the account, for magpie's daily check-in (yetone/magpie#694, Hu9956: TRAE cn 也有每天签到送100积分) — the loader's fetch served chat completions only (400 for anything else), so magpie had no way to ask Trae as a signed-in account. A URL on api.trae.cn under /trae/api/ (ownPage) is now sent as it is, with the IDE's headers (Authorization: Cloud-IDE-JWT, x-device-id, x-uid, x-app-id …; the token renewed first when near its end, as a chat is) and the body given ({} when none), and Trae's answer comes back as it is, X-Magpie-Sign-In expired on a 401 or code 1001, renewed or kept otherwise; any other URL that isn't a chat is still refused. magpie asks POST /trae/api/v2/ug/checkin_credits/status, then /claim, both with {} — the endpoints autumnsentiment/Trae2api-cn (whose protocol this plugin follows) and qilimixingkong/trae-checkin both call; an unauthenticated POST to /status answers 200 {code:1001, enable:false, checked_in:false}, and a made-up sibling path 404s. Code 9095 (this device is in today) is left as Trae's answer: nothing sends another device id to get round it. checkin.test.mjs (status and claim sent as the account and answered as they are; 1001 marks the sign-in; a token near its end renewed first; another path refused with nothing sent); bun test (28 pass) and scripts/check.mjs trae pass. Not run with a real Trae CN account: none was signed in to try with. README gains a Daily check-in section.
2026-10-04 03:44:28 +08:00
trae 0.1.6: the usage card says Trae CN's credits in the Credits row, as WorkBuddy's, not as an English balance line under it (yetone/magpie#694, Hu9956 on magpie 0.1.784: 积分显示的样式有点不一样 — WorkBuddy's cards read "积分 1,689.01 / 2,400 积分 · 剩余 70.4%", Trae CN's "积分 剩余 60.7%" with "余额 2307.42 of 3800 credits left" in large type below) — usage gave the share alone on its Credits window and the count as a balance string, "<left> of <limit> credits left", which magpie shows as a separate 余额 row (balanceRow, beside windows) in the plugin's own English and number format, and never flips with 已用/剩余. The window now carries the count as WorkBuddy's does (amount = credits used, limit = the packs' total, unit "credits", magpie#659), so magpie's quotaCount writes "2,307.42 / 3,800 积分 · 剩余 60.7%" (or "1,492.58 / 3,800 积分 · 已用 39.3%"; "credits" in English) in the row itself, and the balance is left out; an unlimited account still says "unlimited" as its balance. No magpie change needed: plugin_usage.go already passes a plugin window's amount, limit and unit to the card. usage.test.mjs now expects the window's amount/limit/unit and no balance (fails on 0.1.5); HOME=$(mktemp -d) bun test (465 pass) and bun scripts/check.mjs trae pass. Checked in magpie's Usage page (webkit, zh and en, API faked with the old and new shapes beside WorkBuddy and WorkBuddy AI cards): the Trae CN card's row reads like WorkBuddy's and the 余额 line is gone. Not tried with a real Trae CN account.
2026-10-04 13:07:10 +08:00
trae 0.1.6: the usage card says Trae CN's credits in the Credits row, as WorkBuddy's, not as an English balance line under it (yetone/magpie#694, Hu9956 on magpie 0.1.784: 积分显示的样式有点不一样 — WorkBuddy's cards read "积分 1,689.01 / 2,400 积分 · 剩余 70.4%", Trae CN's "积分 剩余 60.7%" with "余额 2307.42 of 3800 credits left" in large type below) — usage gave the share alone on its Credits window and the count as a balance string, "<left> of <limit> credits left", which magpie shows as a separate 余额 row (balanceRow, beside windows) in the plugin's own English and number format, and never flips with 已用/剩余. The window now carries the count as WorkBuddy's does (amount = credits used, limit = the packs' total, unit "credits", magpie#659), so magpie's quotaCount writes "2,307.42 / 3,800 积分 · 剩余 60.7%" (or "1,492.58 / 3,800 积分 · 已用 39.3%"; "credits" in English) in the row itself, and the balance is left out; an unlimited account still says "unlimited" as its balance. No magpie change needed: plugin_usage.go already passes a plugin window's amount, limit and unit to the card. usage.test.mjs now expects the window's amount/limit/unit and no balance (fails on 0.1.5); HOME=$(mktemp -d) bun test (465 pass) and bun scripts/check.mjs trae pass. Checked in magpie's Usage page (webkit, zh and en, API faked with the old and new shapes beside WorkBuddy and WorkBuddy AI cards): the Trae CN card's row reads like WorkBuddy's and the 余额 line is gone. Not tried with a real Trae CN account.
2026-10-04 13:07:10 +08:00
trae 0.1.6: the usage card says Trae CN's credits in the Credits row, as WorkBuddy's, not as an English balance line under it (yetone/magpie#694, Hu9956 on magpie 0.1.784: 积分显示的样式有点不一样 — WorkBuddy's cards read "积分 1,689.01 / 2,400 积分 · 剩余 70.4%", Trae CN's "积分 剩余 60.7%" with "余额 2307.42 of 3800 credits left" in large type below) — usage gave the share alone on its Credits window and the count as a balance string, "<left> of <limit> credits left", which magpie shows as a separate 余额 row (balanceRow, beside windows) in the plugin's own English and number format, and never flips with 已用/剩余. The window now carries the count as WorkBuddy's does (amount = credits used, limit = the packs' total, unit "credits", magpie#659), so magpie's quotaCount writes "2,307.42 / 3,800 积分 · 剩余 60.7%" (or "1,492.58 / 3,800 积分 · 已用 39.3%"; "credits" in English) in the row itself, and the balance is left out; an unlimited account still says "unlimited" as its balance. No magpie change needed: plugin_usage.go already passes a plugin window's amount, limit and unit to the card. usage.test.mjs now expects the window's amount/limit/unit and no balance (fails on 0.1.5); HOME=$(mktemp -d) bun test (465 pass) and bun scripts/check.mjs trae pass. Checked in magpie's Usage page (webkit, zh and en, API faked with the old and new shapes beside WorkBuddy and WorkBuddy AI cards): the Trae CN card's row reads like WorkBuddy's and the 余额 line is gone. Not tried with a real Trae CN account.
2026-10-04 13:07:10 +08:00
trae 0.1.6: the usage card says Trae CN's credits in the Credits row, as WorkBuddy's, not as an English balance line under it (yetone/magpie#694, Hu9956 on magpie 0.1.784: 积分显示的样式有点不一样 — WorkBuddy's cards read "积分 1,689.01 / 2,400 积分 · 剩余 70.4%", Trae CN's "积分 剩余 60.7%" with "余额 2307.42 of 3800 credits left" in large type below) — usage gave the share alone on its Credits window and the count as a balance string, "<left> of <limit> credits left", which magpie shows as a separate 余额 row (balanceRow, beside windows) in the plugin's own English and number format, and never flips with 已用/剩余. The window now carries the count as WorkBuddy's does (amount = credits used, limit = the packs' total, unit "credits", magpie#659), so magpie's quotaCount writes "2,307.42 / 3,800 积分 · 剩余 60.7%" (or "1,492.58 / 3,800 积分 · 已用 39.3%"; "credits" in English) in the row itself, and the balance is left out; an unlimited account still says "unlimited" as its balance. No magpie change needed: plugin_usage.go already passes a plugin window's amount, limit and unit to the card. usage.test.mjs now expects the window's amount/limit/unit and no balance (fails on 0.1.5); HOME=$(mktemp -d) bun test (465 pass) and bun scripts/check.mjs trae pass. Checked in magpie's Usage page (webkit, zh and en, API faked with the old and new shapes beside WorkBuddy and WorkBuddy AI cards): the Trae CN card's row reads like WorkBuddy's and the 余额 line is gone. Not tried with a real Trae CN account.
2026-10-04 13:07:10 +08:00

@magpie-community/opencode-trae-auth

Signs in to Trae CN (trae.cn, ByteDance's AI IDE) with your Trae CN account, the way the IDE does, and makes its model requests. The free tier works as well. Provider id: trae-cn.

Experimental. The protocol was worked out from two open-source relays, wangqi233/trae2api and autumnsentiment/Trae2api-cn. The plugin hasn't been run against a real Trae CN account yet. If something fails, open an issue and include the error magpie shows.

Sign-in

One way, Trae CN account (browser). The plugin opens trae.cn's authorization page (www.trae.cn/authorization, the IDE's client ono9krqynydwx5). Sign in there and allow the sign-in. trae.cn then sends the browser back to a callback on http://127.0.0.1:<port>/authorize; it accepts no other kind of callback. The callback carries the account's Cloud-IDE-JWT, refresh token and account. Nothing needs pasting back.

At sign-in the plugin creates the account's device and names it to the authorization page: device_id (19 digits) and machine_id (32 hex). Every request then sends that same device. The relays saw requests dropped when the device was new each time.

Requests

Chat completions (@ai-sdk/openai-compatible) are translated for the IDE agent's POST https://trae-api-cn.mchost.guru/api/agent/v3/llm_utils_chat:

  • Request:

    • The messages go as {role, content: [{type: "text", text}]}.
    • The model goes as config_name and model, and as model_name the __dev model the function's list names for it, when it names one.
    • The function is the one whose model list has the model, the first that names a __dev model for it (in the order chat_v3, the classic IDE's; solo_work_lite, SOLO's Work mode; solo_agent, the TRAE agent's; solo_agent_lite). If Trae answers 4001, 4023 or 1005, the plugin tries the others once and remembers which one worked.
  • Headers: TRAE SOLO CN 0.1.69's (x-ide-version/x-app-version 0.1.69, version code 20260917; Trae offers a model only to clients new enough for it): Authorization: Cloud-IDE-JWT …, X-Cloudide-Token, x-app-id, the device headers and x-uid.

  • Answer: Trae always answers in its own SSE events:

    • output gives response/content and reasoning_content/reasoning.
    • token_usage, done and error mark usage, the end and failures.
    • Queue events are ignored.

    The plugin turns these into an OpenAI stream or a single body.

  • Tools:

    • Trae's chat has no turn for a tool call or its result, so the tools are named twice:
      • natively in tools, with parameters as a JSON string;
      • in a system prompt that asks for each call as a <tool_call>{"name", "arguments"}</tool_call> block.
    • Calls from either source become OpenAI tool_calls.
    • Earlier calls and their results go back in as text.
    • Images aren't sent.

The model list is the account's own, from /api/ide/v1/batch_get_detail_param, every function's list in one ask, as TRAE SOLO CN asks it (/api/ide/v1/get_detail_param, one function at a time, when the batch gives none). The lists are put together: SOLO and the TRAE agent list models chat_v3 doesn't (deepseek-v4.1-flash is the TRAE agent's, solo_agent). Left out are the IDE's helpers (usage other than chat_completion: summary, fast_apply…), configs switched off and the custom-model slots. Context is the list's context_window_tokens.dev (max is Max mode's), output the __dev model's max_tokens. When no list can be read, the plugin uses the models Trae CN's chat_v3 is known to serve: GLM-5.2, GLM-5, Kimi K2.6, Qwen 3.7 Plus, DeepSeek V4 Pro and DeepSeek V4 Flash.

Renewal

The JWT is renewed with the refresh token at api.trae.cn/cloudide/api/v3/trae/oauth/ExchangeToken. Trae issues a new refresh token each time and spends the old one, so only one renewal runs at a time.

magpie renews the JWT ten minutes before it ends (refreshLead) through auth.refresh. Each request also checks it, two minutes before the end, for OpenCode.

The account is marked for a new sign-in in these cases:

  • the refresh token is turned away;
  • a request is answered 401, or with code 1001.

Trae signs other clients out of an account when its token is renewed. The IDE may therefore ask you to sign in again after magpie renews.

Errors

Trae's answer What the agent gets
401 / code 1001 401, and the account is marked for a new sign-in
code 4008 / 1005 (quota, plan) 429
Anything else Trae's message and code, as a 502 or Trae's own status

Usage

magpie's usage card shows the account's credits:

  • Source: api.trae.cn/trae/api/v2/pay/ide_user_ent_usage.
  • What it adds up: each entitlement pack's credits_limit (-1 means unlimited) and what the pack has used.
  • What it shows: one Credits window: the credits used of the packs' total, with the share, which magpie shows as used or left like WorkBuddy's.

Daily check-in

Trae CN gives credits for a daily check-in (每日签到). magpie can press it once a day for each account (Settings, or the switch on the usage card). It asks Trae CN's own pages through this plugin's fetch, which sends them as the account: its Cloud-IDE-JWT (renewed first when near its end) and its device id.

  • Status: POST api.trae.cn/trae/api/v2/ug/checkin_credits/status, body {}: enable, checked_in, credits.
  • Claim: POST api.trae.cn/trae/api/v2/ug/checkin_credits/claim, body {}, only while it is on and today's isn't in.
  • What comes back: Trae's answer as it is. A 401 or code 1001 marks the account for a new sign-in. Code 9095 means this device has checked in today; nothing sends another device id to get round it.

Only api.trae.cn's /trae/api/ pages are sent this way; any other URL that isn't a chat request is still refused (400). Needs 0.1.4 or later.