Conversation
Tracks usage-based API credits from Perplexity Pro/Max plans via the /rest/billing/credits endpoint using a browser session cookie. - Three-tier display: recurring credits (monthly), bonus credits (promotional grants), and purchased on-demand credits - Infers plan name (Free/Pro/Max) from recurring credit pool size - Cookie auth: auto browser import from Chrome/Chromium, manual paste, or PERPLEXITY_SESSION_TOKEN / PERPLEXITY_COOKIE env var fallback - Waterfall attribution: recurring → purchased → promotional - Empty credit pools render as depleted bars, not full ones - Login flow opens perplexity.ai/signin with the standard key icon - 10 unit tests covering parsing, waterfall logic, plan inference, empty-pool rendering, and UsageSnapshot conversion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…warning - Cache Perplexity session cookies via CookieHeaderCache (matching Claude/Cursor pattern): try cache before browser import, cache on success, clear + retry on 401/403, preserve cache on transient errors - Fix PerplexityCreditGrant.expiresAtTs to be optional — the API returns null for purchased grants, causing parse failures - Remove deprecated kSecUseAuthenticationUIFail (macOS 14+ only needs LAContext.interactionNotAllowed) - Add debug logging for parse failures (raw response preview) - Add 6 tests for cookie cache behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Perplexity now sends purchased credits as a credit_grant with type="purchased" instead of (or in addition to) the top-level current_period_purchased_cents field. Take the larger of the two sources to avoid double-counting while catching either path. Without this fix, 40k purchased credits were invisible to the waterfall calculation, causing bonus credits to show 100% used when they still had ~42% remaining.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13eecaf076
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@BeelixGit Could you please run this branch at your end and see if all works well in manual testing? |
|
Tested this branch locally:
The Perplexity provider code in this PR is functionally identical to what was in #449. The chunked cookie reassembly and credential-retry logic look solid. Tested on macOS (arm64). Thanks @ratulsarna for the audit pass and rebase! |
Supersedes #449.
Rebased onto current
mainand includes the audit-branch fixes discussed during review.Credit and thanks to @BeelixGit for the original implementation and follow-up work.