@juanbenjumea/pi-provider-usage-fetcher

中文文档
0.3.5发布于 2026/11/01MITES Module零依赖构建来源已验证

Multi-provider usage fetchers for coding assistant subscriptions, including OpenCode Go, Claude, Codex, Grok, Cursor, Copilot, Gemini, Kimi, and more.

原始使用文档
文档目录6 节
  1. Install
  2. Unified Dispatch
  3. OpenCode Go (API-first)
  4. Cursor / CommandCode
  5. Consumers
  6. Package rename

@juanbenjumea/pi-provider-usage-fetcher

Shared provider usage library for Pi extensions, agentq, and other tooling.

Despite the name (historical), this package covers more than OpenCode Go:

ProviderAuthSource
OpenCode GoAPI key (same as chat)GET https://opencode.ai/zen/go/v1/usage
ClaudemacOS keychain, auth.json, explicit apiKeyGET https://api.anthropic.com/api/oauth/usage
Codexauth.json, ~/.codex/auth.json, explicit apiKeyGET https://chatgpt.com/backend-api/wham/usage
ClinePassCLINE_API_KEY, auth.json, explicit apiKeyapi.cline.bot/api/v1/*
UmansUMANS_API_KEY, auth.json, explicit apiKeyGET https://api.code.umans.ai/v1/usage
Copilotauth.json (github-copilot), explicit apiKeyGET https://api.github.com/copilot_internal/user
Geminiauth.json, ~/.gemini/oauth_creds.json, explicit apiKeyPOST https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota
Kimi CodingKIMI_API_KEY, auth.json, explicit apiKeyGET https://api.kimi.com/coding/v1/usages
SyntheticSYNTHETIC_API_KEY, auth.json, explicit apiKeyGET https://api.synthetic.new/v2/quotas
z.ai / GLMRegion-specific environment key, auth.json, explicit apiKeyGET {api.z.ai or open.bigmodel.cn}/api/monitor/usage/quota/limit
Grok / SuperGrokGROK_OAUTH_TOKEN, GROK_ACCESS_TOKEN, auth.json (grok), or ~/.grok/auth.jsonGrok CLI billing proxy (cli-chat-proxy.grok.com/v1/billing?format=credits)
Cursorquota-sessions.json, env, CodexBar, Cursor app DBcursor.com/api/usage-summary
CommandCodequota-sessions.json, env, CodexBarapi.commandcode.ai/internal/billing/*
OpenferenceAPI key from caller, OPENFERENCE_API_KEY, or auth.jsonGET https://openference.com/api/user/me

Legacy OpenCode Go dashboard cookie scraping remains as a fallback when no API key is configured.

Grok reports subscription credits, not xAI API spend. Its quota adapter follows the Grok CLI billing route observed in CodexBar; this is a private CLI endpoint and may change. It does not use xAI inference API keys or xAI Management API spend endpoints.

Install

npm install @juanbenjumea/pi-provider-usage-fetcher

Monorepo consumers: "@juanbenjumea/pi-provider-usage-fetcher": "file:../opencode-go-usage".

Unified Dispatch

import { detectProvider, fetchProviderUsage, fetchAllProviderUsage } from "@juanbenjumea/pi-provider-usage-fetcher";

// Automatically detects alias ("anthropic", "github-copilot", "opencode", etc.)
const canonical = detectProvider("anthropic"); // "claude"

// Fetches and normalizes quota snapshot across any supported provider
const snapshot = await fetchProviderUsage("anthropic", { apiKey: "..." });
// { provider: "Claude", windows: [ { label: "5h", usedPercent: 45, resetsIn: "1h30m" }, ... ], fetchedAt }

// Or collect several providers concurrently; unknown providers are omitted.
const snapshots = await fetchAllProviderUsage(["anthropic", "openai-codex", "cursor"]);

OpenCode Go (API-first)

import { fetchUsageApi } from "@juanbenjumea/pi-provider-usage-fetcher";

const usage = await fetchUsageApi(process.env.OPENCODE_GO_KEY!);
// { rolling, weekly, monthly, error? }

Cursor / CommandCode

import { fetchCursorUsage } from "@juanbenjumea/pi-provider-usage-fetcher/cursor.ts";
import { fetchCommandCodeUsage } from "@juanbenjumea/pi-provider-usage-fetcher/commandcode.ts";
import { fetchOpenferenceUsage } from "@juanbenjumea/pi-provider-usage-fetcher/openference.ts";

// Footer labels (Plan / Auto / API)
await fetchCursorUsage();

// agentq labels (total / auto-composer / api-models)
await fetchCursorUsage({ labelStyle: "agentq" });

await fetchCommandCodeUsage();

// Uses the dashboard profile endpoint (openference.com/api/user/me), which the
// inference API key authenticates via Bearer. window = usage.windowQuotaUsed /
// plan.requestsPerWindow, week = usage.weekQuotaUsed / plan.requestsPerWeek.
const openference = await fetchOpenferenceUsage(process.env.OPENFERENCE_API_KEY);

Auth resolution order: provider-specific explicit key → environment variable → auth.json credential. For Cursor and CommandCode cookies, the existing order is quota-sessions.json → env vars → legacy auth.json cookies → CodexBar manual cookies → (Cursor only) desktop app token.

Consumers

  • @juanbenjumea/pi-dynamic-footer — subscription quota bars
  • @juanbenjumea/pi-multi-opencode-go — failover usage polling
  • agentq — data/quota.json collector

Package rename

This package is published as @juanbenjumea/pi-provider-usage-fetcher. Existing consumers of the former @juanbenjumea/opencode-go-usage npm package must switch their dependency and imports when adopting this package; the old package identity remains separate.

版本与发布记录

@juanbenjumea/pi-provider-usage-fetcher 共发布 4 个版本,首次发布于 2026/11/01;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.5latest2026/11/011 天前
0.3.42026/11/012 天前
0.3.32026/11/012 天前
0.0.0-stage2026/11/012 天前

关于 @juanbenjumea/pi-provider-usage-fetcher 的常见问题

@juanbenjumea/pi-provider-usage-fetcher 是什么?

编码助手订阅的多提供者使用获取器,包括OpenCode Go、Claude、Codex、Grok、Cursor、Copilot、Gemini、Kimi等。

如何安装 @juanbenjumea/pi-provider-usage-fetcher?

在项目目录运行 npm install @juanbenjumea/pi-provider-usage-fetcher,或使用 pnpm add / yarn add / bun add。

@juanbenjumea/pi-provider-usage-fetcher 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/juanbenjumea__pi-provider-usage-fetcher 是否存在。

@juanbenjumea/pi-provider-usage-fetcher 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@juanbenjumea/pi-provider-usage-fetcher 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@juanbenjumea/pi-provider-usage-fetcher 可以商用吗?

@juanbenjumea/pi-provider-usage-fetcher 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@juanbenjumea/pi-provider-usage-fetcher 还在维护吗?

最新版本 0.3.5 发布于 2026/11/01(1 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。