Files
wait2050 4482118b7a fix(alibaba-token-plan): personal requests rejected with Workspace.NotAuthorised (hardcoded switchAgent) (#2533)
* fix(alibaba-token-plan): personal requests rejected with Workspace.NotAuthorised

The Personal/Solo path hardcoded `switchAgent: 1_233_135` in the
`cornerstoneParam` request body. The gateway binds that value to a specific
account's workspace, so for any other account the call is rejected with
`BailianGateway.Workspace.NotAuthorised` even though the outer envelope
claims `code: "200"`. Omitting the field lets the gateway resolve the
session's default workspace.

Also:
- Resolve `sec_token` best-effort for personal requests (the browser always
  sends it; some accounts are rejected without it) and append it to the body
  when available, mirroring the Teams path.
- `throwIfErrorPayload` now reads `errorCode`/`errorMsg` from the nested
  frame that carries `success: false`, so the real gateway error is surfaced
  instead of a misleading "API error: 200". Authorization-family errors map
  to `invalidCredentials` so the UI prompts for re-authentication.

Fixes #2500. Verified live against the mainland Personal/Solo API and covered
by new regression tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: preserve Alibaba personal sessions

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Peter Steinberger <steipete@mac-studio-sf2.local>
2026-08-03 09:14:29 -07:00

3.4 KiB

summary, read_when
summary read_when
Alibaba Token Plan provider notes: Team and Personal/Solo variants, cookie auth, and setup.
Adding or modifying the Alibaba Token Plan provider
Debugging Alibaba Token Plan cookie import or subscription summary fetching
Explaining Alibaba Token Plan setup and limitations to users

Alibaba Token Plan Provider

The Alibaba Token Plan provider tracks Team credits and Personal/Solo rolling-window usage from the Alibaba Cloud console.

Features

  • Token-plan usage display: Shows used, total, and remaining token-plan credits when Bailian returns quota totals.
  • Personal/Solo windows: Shows 5-hour and 7-day usage, reset times, and tier-specific quota totals.
  • Cookie-based auth: Uses browser cookies or a pasted Cookie: header.
  • Expiry awareness: Shows the nearest token-plan expiration date as the reset time when the subscription summary includes it.

Setup

  1. Open Settings -> Providers
  2. Enable Alibaba Token Plan
  3. Choose the matching Gateway region Team or Personal/Solo variant
  4. Leave Cookie source on Auto (recommended)
  1. Open the Token Plan page using Open Token Plan in settings
  2. Copy a Cookie: header from the quota request in your browser's Network tab. For Personal/Solo, use the .../tokenplan/personal/api/v2/usage request so the header is scoped to the quota host.
  3. Paste it into Alibaba Token Plan -> Cookie source -> Manual

How it works

  • Team variants fetch GetSubscriptionSummary from the selected international or mainland console and parse the credit pool without probing Personal endpoints.
  • Personal/Solo variants fetch usage, subscription, and quota-config from the rolling-window API. International uses bailian-singapore-cs.alibabacloud.com; mainland uses bailian-cs.console.aliyun.com.
  • Browser cookies are rebuilt independently for the dashboard and quota hosts. Personal/Solo requests use the quota-host cookie header. The dashboard sec_token is resolved best-effort and appended when available (some accounts get BailianGateway.Workspace.NotAuthorised without it); requests still proceed without it.
  • Config region values are intl and cn for Team, or intl-personal and cn-personal for Personal/Solo.
  • Supports ALIBABA_TOKEN_PLAN_HOST and ALIBABA_TOKEN_PLAN_QUOTA_URL for testing endpoint overrides

Limitations

  • Alibaba Token Plan currently supports the Bailian web-cookie path only
  • API-key auth, token cost summaries, and automatic status polling are not supported
  • Live provider auth is not exercised by the test suite; endpoint changes rely on reporter confirmation after release

Troubleshooting

"No Alibaba Token Plan session cookies found in browsers"

Log in at https://bailian.console.aliyun.com/cn-beijing?tab=plan#/efm/subscription/token-plan in Chrome, then refresh CodexBar.

The pasted header is empty or not a valid Cookie header. Re-copy the request from the Token Plan page after logging in again.

"Alibaba Token Plan login required"

Your Bailian session is stale. Sign out and back in on the Bailian console, then refresh CodexBar.

Empty subscription summary

If Bailian returns TotalCount: 0, CodexBar keeps the provider visible but does not show a quota window because the account has no active token-plan subscription summary to graph.