Skip to content

Add Perplexity provider#449

Open
BeelixGit wants to merge 1 commit intosteipete:mainfrom
BeelixGit:feature/perplexity-provider
Open

Add Perplexity provider#449
BeelixGit wants to merge 1 commit intosteipete:mainfrom
BeelixGit:feature/perplexity-provider

Conversation

@BeelixGit
Copy link

Worked with Claude Code to add Perplexity Max usage tracking to CodexBar. Seems to work for me but I am sure there are things I missed.

What this adds

  • Tracks recurring (monthly), promotional (bonus), and on-demand purchased credits from Perplexity Pro/Max plans
  • Fetches from /rest/billing/credits using a browser session cookie (auto-imported from Chrome/Chromium on macOS, or set manually via cookie header / PERPLEXITY_SESSION_TOKEN env var)
  • Waterfall attribution: usage is charged against recurring first, then purchased, then promotional — matching how Perplexity actually bills
  • Plan detection (Free / Pro / Max) inferred from the recurring credit pool size
  • All 3 bars always shown; empty pools render as fully depleted rather than full
  • 9 unit tests covering JSON parsing, waterfall attribution, expired grant exclusion, plan name inference, and UsageSnapshot conversion

Test plan

  • Build: bash Scripts/compile_and_run.sh
  • With a valid Perplexity session cookie all 3 bars populate correctly
  • Without credentials provider is hidden / shows login prompt
  • Unit tests: swift test --filter PerplexityUsageFetcherTests
  • Expired promotional grants excluded from the promo bar
  • Plan name (Pro / Max) appears in the account badge

🤖 Generated with Claude Code

@gitguardian
Copy link

gitguardian bot commented Feb 27, 2026

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c932edbee2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +66 to +68
let primaryPercent = recurringTotal > 0
? min(100, max(0, recurringUsed / recurringTotal * 100))
: 0.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark zero recurring credits as fully used

When recurringTotal is 0, this branch sets primaryPercent to 0.0, which renders the recurring bar as full even though there are no recurring credits available. This affects free/expired accounts (or any response without recurring grants) and contradicts the empty-pool handling used for promo/purchased bars, so the UI reports the recurring pool in the opposite state.

Useful? React with 👍 / 👎.

Comment on lines +7 to +10
let raw = environment["PERPLEXITY_SESSION_TOKEN"]
?? environment["perplexity_session_token"]
?? environment["PERPLEXITY_COOKIE"]
return self.cleaned(raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse PERPLEXITY_COOKIE as cookie header

This reader accepts PERPLEXITY_COOKIE but returns it verbatim as a session token; if users provide a full cookie header (which the variable name strongly implies), the fetcher later wraps it again as __Secure-next-auth.session-token=<value>, producing a malformed Cookie header and authentication failures. PERPLEXITY_COOKIE should be normalized through the same token-extraction path used for manual cookie input.

Useful? React with 👍 / 👎.

@BeelixGit BeelixGit force-pushed the feature/perplexity-provider branch 2 times, most recently from 2b10371 to db8342c Compare February 27, 2026 20:07
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>
@BeelixGit BeelixGit force-pushed the feature/perplexity-provider branch from db8342c to fabc673 Compare February 27, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant