npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tian.zuo/pi-usage

v0.5.1

Published

Show OpenAI Codex, GitHub Copilot, Z.ai GLM Coding Plan (global and China), DeepSeek, and Xiaomi MiMo balance usage in the pi coding agent.

Readme

@tian.zuo/pi-usage

Release notes: changelog · GitHub releases

Show OpenAI Codex, GitHub Copilot, Z.ai (GLM Coding Plan), Z.ai Coding Plan (China), DeepSeek, and Xiaomi MiMo account usage from inside the pi coding agent, plus a /tokens dashboard of the token and cost history pi records locally.

/usage opens a menu with the current usage for every configured provider, and a compact meter is shown in the footer whenever the active model belongs to a supported provider.

Codex usage uses the openai-codex login — listed as OpenAI Codex (legacy) in /login. The newer Sign in with ChatGPT credential on the openai provider is an api.openai.com token that the ChatGPT usage endpoint does not accept. For models under either openai or openai-codex, the extension queries usage with the legacy Codex credential and displays the same codex footer meter. It assumes both logins use the same account; account identity is not checked. The meter reports legacy Codex quota, not a separately queried quota for the newer OpenAI login.

If you only have the newer OpenAI login, the footer prompts you to use /login → OpenAI Codex (legacy). You can keep your openai model selected after signing in.

OpenAI Codex · Plus
  5h limit:         [████████████████░░░░] 78% left · resets 14:20 on 27 Jul

  Weekly limit:     [████████████░░░░░░░░] 60% left · resets 09:00 on 2 Aug

GitHub Copilot · Business
  Premium credits:  [██████░░░░░░░░░░░░░░] 31% left · 7,787 / 25,000 credits
  Quota resets: 2026-08-01

GLM Coding Plan · Lite
  5h tokens:        [████████████░░░░░░░░] 59% left · resets 16:22

GLM Coding Plan (China) · Pro
  5h tokens:        [████████████████░░░░] 82% left · resets 18:05

DeepSeek
  Balance:          ¥27.00
  Topped up: ¥27.00

Xiaomi MiMo
  Balance:          ¥21.66
  Granted: ¥21.66

/tokens opens an interactive token and cost dashboard with an ASCII/Unicode bar chart, peak breakdown, and scrollable model rankings (up to top 10 models):

────────────────────────────────────────────────────────────────────
 tokens · local pi usage
 14 session files · dedup by entry id

 1d [7d] 30d MTD
 ←/→ or h/l window · ↑/↓ or j/k scroll · 1-4 jump · Tab · Esc close
────────────────────────────────────────────────────────────────────
 Last 7 days (Aug 23 – Aug 29) · per day, tokens
 1.3M tokens · $41.27
 7 requests · in 892K · out 163K · cache 255K
 cost at list prices (subscription plans may cover it)

 peak 415K on Aug 25
       ██
       ██ ██
    ██ ██ ██    ██
    ██ ██ ██ ██ ██
 ██ ██ ██ ██ ██ ██ ██
 ██ ██ ██ ██ ██ ██ ██
 23    25    27    29

 top models by tokens (1–5 of 7 · ↑/↓ scroll)
   1. anthropic/claude-3-7-sonnet  747K  $25.62
   2. openai-codex/gpt-5.6  453K  $14.55
   3. zai/glm-4-plus  110K  $1.10
   4. google/gemini-2.5-pro  85K  $0.75
   5. deepseek/deepseek-chat  40K  $0.20
────────────────────────────────────────────────────────────────────

Commands

  • /usage — open the usage menu. A cancellable loading spinner is shown while the provider endpoints are queried (press Esc to cancel). Pick Refresh to re-query, Close to dismiss. In non-interactive modes it prints a one-line summary instead.
  • /tokens — local token/cost history recorded by pi itself, no provider calls. Shows a bar chart with a 1.2M tokens · $39.82 headline for Today (per hour), Last 7 days, Last 30 days, and Month to date (per day). Navigate with ←/→ (or 1-4), scroll top models with ↑/↓ (or j/k, up to top 10), toggle the chart metric with Tab (tokens ⇄ cost), rescan with r, close with Esc/q/Enter. In non-interactive modes it prints one summary line per window.

Statusline

When the active model provider is OpenAI, Codex, Copilot, Z.ai, Z.ai Coding Plan (China), DeepSeek, or Xiaomi MiMo, the footer shows a compact Azure Blue meter such as codex 60% wk, copilot 31% credits, copilot 49% premium, zai 59% 5h, zai-cn 82% 5h, deepseek ¥27.00, or xiaomi ¥21.66, refreshed at most every five minutes (results are cached to avoid hammering the endpoints).

Credentials

When magpie is installed, usage is read from it first, covering Codex, GitHub Copilot, Z.ai/GLM Coding Plan (global and China), and DeepSeek from the sign-ins magpie discovers itself (Codex's ~/.codex/auth.json, Copilot's credential store, the keys it holds for vendors). While the magpie app runs, its local gateway serves a cached snapshot over HTTP (sub-second); otherwise magpie quota --json is spawned, which takes a few seconds. That keeps /usage correct even when magpie routes pi's models through its local gateway and pi's stored key is only a gateway placeholder. PI_USAGE_MAGPIE_BIN points the extension at a magpie binary outside the usual install locations, PI_USAGE_MAGPIE_GATEWAY at a gateway outside the usual address.

Per provider with no magpie entry, usage falls back to credentials pi saved itself in ~/.pi/agent/auth.json (or $PI_CODING_AGENT_DIR/auth.json when configured), with provider-specific environment variables as a further fallback. /usage only lists providers pi has a login for.

GitHub Copilot Enterprise Cloud

For GitHub Enterprise Cloud with data residency, sign in using Pi's /login → GitHub Copilot and enter your <tenant>.ghe.com login domain. Usage keeps the enterpriseUrl saved alongside that login's GitHub OAuth credential and queries https://api.<tenant>.ghe.com/copilot_internal/user. It uses the stored GitHub OAuth token, not the short-lived Copilot chat token. The normal github.com login continues to use api.github.com.

An invalid or unsupported login domain fails before any request; redirects and fallback requests to another account domain are not followed. Custom GitHub Enterprise Server domains are not supported. The Enterprise API must return quota_snapshots for a remaining allowance to be shown: a working model login alone does not guarantee that your enterprise exposes quota data.

The environment-token and VS Code credential fallbacks are for public GitHub accounts only; use Pi's saved OAuth login for Enterprise. An incomplete saved Enterprise login does not borrow a token from those fallbacks. When VS Code's credential file contains multiple accounts, only github.com entries are eligible for the public fallback.

How /tokens works

pi records every assistant message's usage (input/output/cache tokens, total, and list-price cost) in session files under ~/.pi/agent/sessions/ (or $PI_CODING_AGENT_DIR/sessions). /tokens streams those JSONL files and also counts nested model work on tool results (code-mode classifiers, tools that call models), standalone usage entries such as cache warming, and compaction / branch-summary usage — the same sources pi's session totals use. Entries are deduplicated by id so replayed or resumed copies (repro.jsonl, forks) are counted once. Nested tool usage appears under Tools/summaries. Files whose name-encoded start date is more than 7 days older than the window are skipped; non-standard names are always scanned. Cost is the model's list price recorded at request time — subscription plans (Codex, Copilot, GLM Coding Plan) may cover it, which the panel notes as cost at list prices.

Xiaomi MiMo setup

Xiaomi MiMo's balance is only exposed by the web console API (platform.xiaomimimo.com/api/v1/balance), which authenticates with Xiaomi account session cookies — the sk- model API key you use for /login (and for model calls) cannot query balance. The cookie is only needed for this extension's usage display. First sign in to the Xiaomi model provider with pi's /login; MiMo usage is not loaded for users without a Xiaomi login.

  1. Log in at https://platform.xiaomimimo.com/#/console/balance and open the balance page (the one showing 账户余额 / Account Balance).
  2. Open DevTools (F12, or Cmd+Option+I on macOS) → Network tab.
  3. Refresh the page (Cmd/Ctrl+R) so the balance request is captured.
  4. In the Network tab's filter box type balance — you should see a request named balance (GET …/api/v1/balance). Click it.
  5. In Headers → Request Headers, find the Cookie: line. Right-click the value → Copy value (on older Chrome: select the whole line and copy). The parts that matter are api-platform_serviceToken, api-platform_ph, api-platform_slh, and userId; copying the entire header is fine.
  6. Store it in pi's auth store, <agent-dir>/auth.json (see Credentials above), under the xiaomi-console entry (kept separate from the xiaomi api_key entry so /login never clobbers it):
"xiaomi-console": { "type": "cookie", "key": "api-platform_serviceToken=…; api-platform_ph=…; api-platform_slh=…; userId=…" }

Alternatively export the same string as MIMO_COOKIE (the auth store entry wins when both are set). Supplying the cookie manually is an explicit choice to let /usage query Xiaomi's console balance endpoint with it.

Optional browser sync

After signing in to the Xiaomi model provider with /login, open the MiMo console in a browser and enable the Playwriter extension on that tab. Run /usage-mimo-sync. Pi explains why the console cookie is needed and asks for consent before reading it. It validates the cookie with Xiaomi's balance endpoint and holds it only in memory for this pi process; it never prints or writes the imported cookie to auth.json. The command does not inspect or navigate unrelated tabs. Ordinary /usage and background status updates never read browser cookies.

MiMo is queried only when the Xiaomi model provider is logged in and a console cookie is available. If the session expires, /usage reports a specific 401 re-login instruction; sign in to the console again and run /usage-mimo-sync, or repeat the manual steps above with a fresh cookie.

Install

pi install npm:@tian.zuo/pi-usage

Try it without installing permanently:

pi -e npm:@tian.zuo/pi-usage

License

MIT © Tian Zuo