pi-telegram-notifier 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,6 +40,7 @@ The **quota/credit** field supports these Pi provider IDs (using the credential
40
40
  | Pi provider ID | Mode | Required credential | What is shown |
41
41
  | --- | --- | --- | --- |
42
42
  | `openai-codex` | Subscription | ChatGPT OAuth | Remaining 5h / 7d usage-window percentages; [official Codex client endpoint](https://github.com/openai/codex/blob/main/codex-rs/backend-client/src/client/rate_limit_resets.rs). |
43
+ | `openai` | Subscription (Codex fallback) | ChatGPT OAuth **and** a separate `openai-codex` OAuth login | Codex account windows, explicitly labeled `(Codex login)`, not the new login's app-specific limit. The new ChatGPT token cannot read this endpoint. Log both providers into the same account; without the Codex login, `Quota unavailable`. API keys are not supported. |
43
44
  | `anthropic` | Subscription | Claude OAuth | Remaining 5h / 7d usage-window percentages; [private OAuth endpoint](https://github.com/openclaw/openclaw/blob/main/src/infra/provider-usage.fetch.claude.ts). |
44
45
  | `claude-bridge` ([pi-claude-bridge](https://www.npmjs.com/package/pi-claude-bridge)) | Subscription | Pi's Claude OAuth (`/login` → Anthropic) | Same 5h / 7d windows as `anthropic`: the bridge has no credential of its own, so the matching `anthropic` model's OAuth login is used. Log Pi and Claude Code into the **same** Anthropic account, otherwise Pi's account quota is shown. Without the login, `Quota unavailable`. |
45
46
  | `xai` | Subscription | Grok OAuth | Remaining weekly shared Grok credits percentage, **not** prepaid API credit; [official Grok client endpoint](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-shell/src/extensions/billing.rs). |
package/docs/providers.md CHANGED
@@ -6,6 +6,7 @@ Inventory of the 41 built-in provider IDs in the installed Pi model catalog (`@e
6
6
  | --- | --- | --- |
7
7
  | `openrouter` | Account credit = `total_credits - total_usage` (USD), **only if Pi's credential is an OpenRouter management key**; normal inference keys receive HTTP 403 and show unavailable. | [Get remaining credits](https://openrouter.ai/docs/api/api-reference/credits/get-remaining-credits), `GET https://openrouter.ai/api/v1/credits` |
8
8
  | `openai-codex` | Remaining subscription quota for the primary and secondary usage windows (typically 5h / 7d), from `100 - used_percent`; Pi's OAuth token and ChatGPT account ID are required. This backend route is used by the official Codex client but is **not a stable public API**. | [Official Codex client usage request](https://github.com/openai/codex/blob/main/codex-rs/backend-client/src/client/rate_limit_resets.rs), [response fields](https://github.com/openai/codex/blob/main/codex-rs/codex-backend-openapi-models/src/models/rate_limit_status_details.rs), `GET https://chatgpt.com/backend-api/wham/usage` |
9
+ | `openai` | With ChatGPT OAuth, reads the matching model's separate `openai-codex` OAuth login through Pi's registry and labels the result `(Codex login)`. Pi's new direct ChatGPT token cannot read WHAM usage and does not expose the legacy account ID. Account equality cannot be verified: sign both providers into the same account. Missing Codex login, API keys and proxy endpoints show unavailable. | Same official Codex endpoint as above; [Pi ChatGPT OAuth implementation](https://github.com/earendil-works/pi/blob/main/packages/ai/src/auth/oauth/openai-chatgpt.ts). |
9
10
  | `deepseek` | Available balance per currency (CNY and/or USD); no currency conversion. | [Get User Balance](https://api-docs.deepseek.com/api/get-user-balance), `GET https://api.deepseek.com/user/balance` |
10
11
  | `moonshotai` | Available balance, USD. | [Balance](https://platform.moonshot.ai/docs/api/balance), `GET https://api.moonshot.ai/v1/users/me/balance` |
11
12
  | `moonshotai-cn` | Available balance, CNY. | [Balance](https://platform.moonshot.cn/docs/api/balance), `GET https://api.moonshot.cn/v1/users/me/balance` |
@@ -15,9 +16,11 @@ Inventory of the 41 built-in provider IDs in the installed Pi model catalog (`@e
15
16
  | `claude-bridge` (extension provider from [pi-claude-bridge](https://github.com/elidickinson/pi-claude-bridge)) | Same Claude subscription windows as `anthropic`. The bridge registers a placeholder key and runs Claude Code with its own login, so the quota is read with Pi's `anthropic` OAuth credential for the same model ID; without that login it shows unavailable. Claude Code's own credential store is deliberately not read, so the quota belongs to Pi's Anthropic account: it matches the bridge turn only when Pi and Claude Code are logged into the same account (the usage response does not identify the account). | Same endpoint as `anthropic` |
16
17
  | `xai` | Remaining **weekly Grok subscription** credits with Pi OAuth only. The per-product percentages are not the shared pool; xAI API prepaid credit is a different quantity requiring a management key. | [Official Grok billing client](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-shell/src/extensions/billing.rs), `GET https://cli-chat-proxy.grok.com/v1/billing?format=credits` (private endpoint); [API management billing](https://docs.x.ai/developers/rest-api-reference/management/billing) |
17
18
  | `amazon-bedrock`, `azure-openai-responses`, `cloudflare-ai-gateway`, `cloudflare-workers-ai`, `google-vertex`, `radius`, `vercel-ai-gateway` | Cloud/gateway billing belongs to separate accounts/credentials; no verified remaining plan balance endpoint with Pi's inference credential. | Provider-specific cloud billing tools, not Pi model API keys. |
18
- | `openai`, `github-copilot` | Subscription balance not exposed through a verified quota endpoint accessible with Pi's resolved inference credential. Admin usage/spending APIs are **not** plan remainder. | [OpenAI organization costs](https://platform.openai.com/docs/api-reference/organization/costs) |
19
+ | `github-copilot` | Subscription balance not exposed through a verified quota endpoint accessible with Pi's resolved inference credential. Admin usage/spending APIs are **not** plan remainder. | [OpenAI organization costs](https://platform.openai.com/docs/api-reference/organization/costs) |
19
20
  | `fireworks`, `together` | Documented billing usage / quotas are past spend or request limits, not an available credit balance verified for inference keys. | [Fireworks billing summary](https://docs.fireworks.ai/api-reference/get-billing-summary), [Together billing usage](https://docs.together.ai/reference/billing-usage) |
20
21
  | `ant-ling`, `baseten`, `cerebras`, `google`, `groq`, `huggingface`, `kimi-coding`, `meta`, `minimax`, `minimax-cn`, `mistral` | No verified official endpoint returning remaining allowance with Pi's inference credential. | Check provider billing documentation before adding integrations. |
21
22
  | `nvidia`, `opencode`, `opencode-go`, `qwen-token-plan`, `qwen-token-plan-cn`, `qwen-token-plan-individual`, `xiaomi`, `xiaomi-token-plan-ams`, `xiaomi-token-plan-cn`, `xiaomi-token-plan-sgp` | No verified official endpoint returning remaining allowance with Pi's inference credential; management/billing credentials, if available, are distinct. | Check provider billing documentation before adding integrations. |
22
23
 
24
+ The new `openai` ChatGPT login has no verified numerical quota endpoint. OpenAI documents [public Responses API inference](https://developers.openai.com/siwc/token-sharing-open-source/models-and-inference) and [usage-limit errors](https://developers.openai.com/siwc/token-sharing-open-source/errors-and-recovery), directing users to ChatGPT settings → Usage. App-specific limits can apply even when the account has remaining quota, so the Codex fallback does **not** measure the new login's app allowance. Live checks returned 401 for WHAM and `/v1/usage`, and 404 for `/v1/usage/limits`, `/v1/rate_limits`, and `/api/codex/usage` on `api.openai.com`. Other projects report the same limitation: [pi-minimal-footer PR #50](https://github.com/ogulcancelik/pi-extensions/pull/50), [the-last-harness #707](https://github.com/diegopetrucci/the-last-harness/issues/707). No browser cookies or Codex CLI credential files are read by this extension.
25
+
23
26
  An HTTP 401/403, invalid response or missing credential always yields `Quota unavailable` without suppressing the notification. OpenRouter's `/api/v1/key` reports a **per-key** limit, not remaining account credit: deliberately not used. This inventory is for the Pi catalog present at implementation time; new providers require fresh verification.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-telegram-notifier",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Telegram notifications for final Pi agent responses and provider balances",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/quota.ts CHANGED
@@ -23,6 +23,20 @@ function remainingPercent(used: unknown): number | undefined {
23
23
  export async function getQuota(model: Model | undefined, modelRegistry: Pick<ModelRegistry, 'find' | 'getApiKeyAndHeaders' | 'isUsingOAuth'> | undefined, fetchImpl: typeof fetch = fetch): Promise<string> {
24
24
  // pi-claude-bridge has no credential of its own; it draws on the same Claude subscription as Pi's Anthropic OAuth login.
25
25
  if (model?.provider === 'claude-bridge') model = modelRegistry?.find('anthropic', model.id);
26
+ if (model?.provider === 'openai') {
27
+ try {
28
+ if (new URL(model.baseUrl).origin !== 'https://api.openai.com' || !modelRegistry?.isUsingOAuth(model)) return UNAVAILABLE;
29
+ const auth = await modelRegistry.getApiKeyAndHeaders(model);
30
+ if (!auth.ok || !auth.apiKey || (auth.baseUrl && new URL(auth.baseUrl).origin !== 'https://api.openai.com')) return UNAVAILABLE;
31
+ // shortcut: reports legacy Codex quota, replace when SIWC exposes a supported quota endpoint.
32
+ const codex = modelRegistry.find('openai-codex', model.id);
33
+ if (!codex || codex.provider !== 'openai-codex' || !modelRegistry.isUsingOAuth(codex)) return UNAVAILABLE;
34
+ const quota = await getQuota(codex, modelRegistry, fetchImpl);
35
+ return quota === UNAVAILABLE ? quota : `${quota} (Codex login)`;
36
+ } catch {
37
+ return UNAVAILABLE;
38
+ }
39
+ }
26
40
  const provider = model && providers[model.provider];
27
41
  if (!model || !provider) return UNAVAILABLE;
28
42
  try {