Open
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".
Collaborator
Author
|
@BeelixGit Could you please run this branch at your end and see if all works well in manual testing? |
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.
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.