/usage: Z.AI coding-plan (API key) shows no real usage limits/balance, only key-status + local spend
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Description
With a Z.AI coding-plan subscription configured via API key (login provider zai, OpenAI-compatible profile ZAI_PROFILE, base https://api.z.ai/api/coding/paas/v4), /usage does not show real usage limits or remaining quota. It only shows a free GET /models key-status probe plus locally tracked spend. The OAuth surface (Claude/OpenAI) shows full usage windows, and other coding agents (e.g. the Z.AI coding plan in other tools) show the actual remaining quota for this plan type.
Repro
- Configure Z.AI coding-plan via API key (
ZHIPU_API_KEYinzai.env). - Use the provider so it has activity.
- Run
/usage. - Z.AI (API key) row shows only key status and local spend — no plan usage/limit/remaining quota.
Expected
The Z.AI row shows the coding-plan usage/remaining quota the same way OAuth surfaces (Claude/OpenAI) do, or as other coding agents report it.
Root cause (from source)
In crates/jcode-base/src/usage/api_keys.rs, enqueue_api_key_usage_tasks only gives real balance fetchers to deepseek and moonshotai:
let has_balance_api = matches!(profile.id, "deepseek" | "moonshotai");
Everything else (including zai) falls into the generic branch in fetch_compatible_profile_report, which only does a free GET {base}/models probe for key validity and appends locally tracked spend. There is no Z.AI coding-plan usage/quota fetcher, so the coding-plan subscription data that the OAuth-style surfaces show is never surfaced for the API-key route.
Suggested area
Add a Z.AI coding-plan usage fetcher (e.g. quota/remaining-tokens endpoint under https://api.z.ai/api/coding/paas/v4) and register zai in has_balance_api / fetch_compatible_profile_report, matching how DeepSeek/Moonshot balance is wired today.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/jcode-base/src/usage/api_keys.rs, reading enqueue_api_key_usage_tasks and fetch_compatible_profile_report alongside the existing DeepSeek and Moonshot balance handling. Investigate the Z.AI coding-plan quota or remaining-tokens endpoint under the configured API base, then wire the fetcher for the zai profile. Done means /usage shows Z.AI coding-plan usage, limits, or remaining quota rather than only key status and local spend.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- ai, api, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100