feat(capacity): show OpenAI usage from pi's OpenAI login - #254
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ai-devkit capacitynow showspi · OpenAIrows — besidepi · z.ai— whenever the user has logged in to OpenAI via pi, with zero manual setup and no platform API key. Previously the default report warnedopenai capacity unavailable: OpenAI API key not foundbecause the provider only understoodOPENAI_API_KEY/ a piopenaiplatform-key credential, and could never see pi's OAuth login (theopenai-codexentry in~/.pi/agent/auth.json).Live report on a machine with only the pi OpenAI login (redacted):
Design rationale (full docs in
docs/ai/*/2026-09-27-feature-openai-pi-login-capacity.md)OPENAI_API_KEYenv → piopenai{type:"api_key"}→ piopenai-codexOAuth → sanitized not-found error (message now mentions the pi login path). Platform-key users keep a byte-identical report; OAuth only fills the no-setup gap.GET https://chatgpt.com/backend-api/wham/usagewithAuthorization: Bearer+ChatGPT-Account-Id. Verified live with the real pi token (HTTP 200; window/credits shape confirmed) during design; tests use fixtures only.expires, or JWTexpfallback; seconds vs ms handled by magnitude) are never refreshed and never fetched: they render authenticated-but-stale (available: "unknown"), matching codex.ts policy.pi · OpenAIandcodex · OpenAIrows may coexist — the harness column exists for exactly this.capacity/wham.ts, now that a second real caller exists.codex.tsdelegates and keeps itsparseUsage/toRateWindowexports;codex.test.tspasses unchanged.Validation
vitest run src/__tests__/capacity/(agent-manager) → 70 tests passed (16 pre-existing platform tests untouched and green;codex.test.ts/zai.test.tsuntouched).openai.tsandwham.tsat 100% lines; remaining uncovered branches are only the never-network default-injection arms (?? globalThis.fetch,?? 5000) — same as codex.ts/zai.ts.npm run lintexit 0 ·npm testexit 0 ·npm run test:e2eexit 0 (42 tests). Husky pre-commit green on every commit.capacity openai --jsonon this machine; scripted check confirms noaccess/refresh/accountIdvalues in output.Risks & follow-ups
creditsRemainingrenders null when the account'scredits.balanceis non-numeric (tolerated by parser).rate_limit_reached_typecould driveavailable: "no"for API responses.feature/…per worktree brief convention instead of the repo'sfeature-…lint expectation (documented deviation;lint --featuredocs checks pass).🤖 Generated with Claude Code