@juanbenjumea / pi-provider-usage-fetcher
共享 供应商使用 用于Pi扩展、agentq和其他工具的库。
除了这个名字(历史的),这个包涵盖的不仅仅是OpenCode Go:
| 提供者 | 身份验证 | 来源 |
|---|---|---|
| OpenCode去 | API密钥(与chat相同) | GET https://opencode.ai/zen/go/v1/usage |
| 克劳德。 | macOS钥匙链, auth.json,显式apiKey | GET https://api.anthropic.com/api/oauth/usage |
| 食典委 | auth.json, ~/.codex/auth.json,显式apiKey | GET https://chatgpt.com/backend-api/wham/usage |
| ClinePass | CLINE_API_KEY, auth.json,显式apiKey | api.cline.bot/api/v1/* |
| 乌曼 | UMANS_API_KEY, auth.json,显式apiKey | GET https://api.code.umans.ai/v1/usage |
| 副驾驶员 | auth.json (github-copilot),显式apiKey | GET https://api.github.com/copilot_internal/user |
| 双子座 | auth.json, ~/.gemini/oauth_creds.json,显式apiKey | POST https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota |
| 乔任梁编码 | KIMI_API_KEY, auth.json,显式apiKey | GET https://api.kimi.com/coding/v1/usages |
| 合成 | SYNTHETIC_API_KEY, auth.json,显式apiKey | GET https://api.synthetic.new/v2/quotas |
| z.ai / GLM | 区域环境关键; auth.json,显式apiKey | GET {api.z.ai or open.bigmodel.cn}/api/monitor/usage/quota/limit |
| Grok /超级Grok | GROK_OAUTH_TOKEN, GROK_ACCESS_TOKEN, auth.json (grok),或 ~/.grok/auth.json | Grok CLI计费代理(cli-chat-proxy.grok.com/v1/billing?format=credits) |
| 光标 | quota-sessions.json、env、CodexBar、Cursor app DB | cursor.com/api/usage-summary |
| CommandCode | quota-sessions.json, env, CodexBar | api.commandcode.ai/internal/billing/* |
| Openference | 来自调用者的API密钥, OPENFERENCE_API_KEY,或者 auth.json | GET https://openference.com/api/user/me |
当没有配置API密钥时,遗留的OpenCode Go仪表板cookie抓取仍然作为回退。
心意相通的报告 订阅学分,而不是xAI API支出。它的配额适配器遵循CodexBar中观察到的Grok CLI计费路由;这是一个私有的CLI端点,可能会更改。它不使用xAI推理API密钥或xAI管理API花费端点。
安装
npm install @juanbenjumea/pi-provider-usage-fetcher
Monorepo消费者: "@juanbenjumea/pi-provider-usage-fetcher": "file:../opencode-go-usage".
统一调度
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优先)
import { fetchUsageApi } from "@juanbenjumea/pi-provider-usage-fetcher";
const usage = await fetchUsageApi(process.env.OPENCODE_GO_KEY!);
// { rolling, weekly, monthly, error? }
光标/命令代码
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.json 证书。对于Cursor和CommandCode cookie,现有的顺序是 quota-sessions.json →环境→遗产 auth.json cookies→CodexBar手动cookies→(仅限光标)桌面应用令牌。
消费者
@juanbenjumea/pi-dynamic-footer-认购限额@juanbenjumea/pi-multi-opencode-go—故障转移使用轮询- agentq - - - - - -
data/quota.json收集器
包重命名
此包发布为 @juanbenjumea/pi-provider-usage-fetcher. 前者是现有消费者 @juanbenjumea/opencode-go-usage 当采用这个包时,NPM包必须切换它们的依赖和导入;旧的包标识仍然是独立的。