feat: merge upstream PRs (models + dynamic CSRF) + out-of-limit rate-limit handling - #1
Conversation
- Fix tokenless env-var check: use optional_env() trim semantics instead of env::var().is_ok() so empty/whitespace-only values are treated as unset (previously rejected as "cannot be used without auth"). - Remove unused DEEP_RESEARCH_MODEL_PREFERENCE constant; inline "pplx_alpha" at its single use site in SearchMode::DeepResearch. - Add SearchMode::Study and SearchMode::DocumentReview, wired through client.rs copilot-mode match. - Add perplexity_study and perplexity_document_review MCP tools following the perplexity_computer pattern. - Update server instructions to document the new tools. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hardcoded 'pplx_asi_opus_thinking' in SearchMode::Computer's default_preference() with ComputerModel::Claude46OpusThinking.api_preference() .as_str() to ensure the preference stays synchronized with the model enum definition. This follows the same pattern as Auto/Pro/Reasoning modes and prevents divergence if the default model is ever updated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Perplexity removed the next-auth.csrf-token browser cookie, making PERPLEXITY_CSRF_TOKEN impossible to extract. The CSRF token is now fetched automatically from GET /api/auth/csrf during client initialization, so users only need PERPLEXITY_SESSION_TOKEN. Closes mishamyrt#12 Bahtya
- Return error when both cookies() and http_client() are provided, preventing inconsistent auth state (CodeRabbit review) - Use singular "authenticated" in README for consistency Bahtya
…models-csrf-ratelimit # Conflicts: # crates/perplexity-web-api-mcp/src/main.rs
- Add /rest/rate-limit/all endpoint client (rate_limit.rs): RateLimits, SourceLimit, QuotaStatus; parse remaining_pro/research/labs/agentic_research + sources.source_to_limit (shape verified vs live API 2026-07). - Pre-flight quota check in search_stream(): authenticated metered modes now return Error::RateLimited instead of Perplexity's silent empty answer when a plan quota is exhausted. Transient probe failures fall through (non-blocking). - New Error variants: RateLimitRequiresAuth, RateLimitFetch, RateLimited. - New MCP tool perplexity_usage: report remaining quotas + per-source limits. - Client::rate_limits() + Client::check_quota_for_mode() public API. - 3 unit tests for parsing/mode-mapping.
| ### Claude Code | ||
|
|
There was a problem hiding this comment.
🟡 New environment variable for computer model selection is undocumented, so users cannot discover or configure it
A new PERPLEXITY_COMPUTER_MODEL environment variable is accepted and used (optional_model_env::<ComputerModel>("PERPLEXITY_COMPUTER_MODEL") at crates/perplexity-web-api-mcp/src/main.rs:135) but is never mentioned in the README's Environment Variables section, so users have no way to discover or configure it.
Impact: Users cannot customize the model for the new perplexity_computer tool without reading source code.
Missing documentation in README Environment Variables section
The code at crates/perplexity-web-api-mcp/src/main.rs:118-119 validates the env var in tokenless mode, and at crates/perplexity-web-api-mcp/src/main.rs:135 reads it for authenticated mode. The README at README.md:60-78 lists all other env vars (PERPLEXITY_SESSION_TOKEN, PERPLEXITY_ASK_MODEL, PERPLEXITY_REASON_MODEL, PERPLEXITY_INCOGNITO) but omits PERPLEXITY_COMPUTER_MODEL.
This violates the AGENTS.md rule: "Update docs/examples when API behavior changes."
(Refers to lines 69-78)
Prompt for agents
The README's Environment Variables section (README.md around lines 60-78) needs a new entry for PERPLEXITY_COMPUTER_MODEL, similar to the existing PERPLEXITY_ASK_MODEL and PERPLEXITY_REASON_MODEL entries. It should document that it's optional, requires a token, is used for the perplexity_computer tool, and list the valid values from the ComputerModel enum in crates/perplexity-web-api/src/models.rs (asi, asi-beta, claude-4.6-sonnet-thinking, claude-4.6-sonnet, claude-4.6-opus-thinking, claude-4.6-opus, gpt-5.4, kimi, qwen), with claude-4.6-opus-thinking as the default.
Was this helpful? React with 👍 or 👎 to provide feedback.
| - `gpt-5.4` | ||
| - `claude-4.6-sonnet` | ||
| - `nemotron-3-super` | ||
| - `PERPLEXITY_REASON_MODEL` (optional, requires tokens): Model for `perplexity_reason`. | ||
| - `PERPLEXITY_REASON_MODEL` (optional, requires token): Model for `perplexity_reason`. | ||
| Valid values: | ||
| - `gemini-3.1-pro` (default) | ||
| - `gpt-5.4-thinking` |
There was a problem hiding this comment.
🟡 Documented model choices for ask and reason are incomplete, so users cannot select newly added models
The list of valid model values in the README is stale — only 6 of 13 ask models and 3 of 8 reason models are shown (README.md:65-76), so users cannot select the newly added options like claude-4.6-opus or gemini-3.0-flash-high.
Impact: Users who want to use newly supported models have no way to discover the valid configuration values.
Mismatch between README and code model enums
The README at lines 65-68 lists PERPLEXITY_ASK_MODEL values: turbo, pro-auto, sonar, gpt-5.4, claude-4.6-sonnet, nemotron-3-super. But crates/perplexity-web-api/src/models.rs:92-134 defines SearchModel with 13 variants including pro-upgraded, claude-4.6-opus, gemini-3.0-flash, gemini-3.0-pro, gpt-5-pro, gpt-5.3-codex, gpt-5.4-mini.
Similarly, lines 73-76 list PERPLEXITY_REASON_MODEL values: gemini-3.1-pro, gpt-5.4-thinking, claude-4.6-sonnet-thinking. But crates/perplexity-web-api/src/models.rs:137-162 defines ReasonModel with 8 variants including claude-4.6-opus-thinking, gemini-3.0-flash-high, gpt-5-thinking, gpt-5.1-thinking, gpt-5.2-thinking.
This violates the AGENTS.md rule: "Update docs/examples when API behavior changes."
(Refers to lines 65-76)
Prompt for agents
Update the README Environment Variables section (around lines 65-76) to list all valid model values. For PERPLEXITY_ASK_MODEL, add the missing models from the SearchModel enum in crates/perplexity-web-api/src/models.rs: pro-upgraded, claude-4.6-opus, gemini-3.0-flash, gemini-3.0-pro, gpt-5-pro, gpt-5.3-codex, gpt-5.4-mini. For PERPLEXITY_REASON_MODEL, add: claude-4.6-opus-thinking, gemini-3.0-flash-high, gpt-5-thinking, gpt-5.1-thinking, gpt-5.2-thinking. Keep the existing entries and their default annotations.
Was this helpful? React with 👍 or 👎 to provide feedback.
… Research timeout CI: - Add .github/workflows/build-release.yml: one-click (workflow_dispatch) or tag-driven release. Builds x86_64/aarch64 linux+macos and x86_64 windows, packages tar.gz/zip + sha256, attaches to a GitHub Release. Uses built-in GITHUB_TOKEN, no external secrets. - Remove upstream cargo-dist release.yml (npm publish needs NPM_TOKEN + wrong pkg name on fork) and docker.yml (needs DOCKERHUB secrets, pushes upstream img). - Point Cargo.toml repo/homepage/docs URLs at the fork. Models (35 typed, was 30): - SearchModel +gpt-5.2, gpt-5.2-pro, grok-4.1 - ReasonModel +grok-4.1-reasoning, kimi-k2.5-thinking - raw: escape hatch: ModelPreference::from_raw + optional_model_pref_env parses 'raw:<preference>' so brand-new Perplexity models work with NO recompile (e.g. PERPLEXITY_REASON_MODEL=raw:glm5_thinking). Unknown names now error with a hint pointing at raw:. Server stores Option<ModelPreference> directly. Deep Research timeout: - SearchMode::is_long_running() (DeepResearch/Computer/DocumentReview). - ClientBuilder.long_timeout (default 600s) used for those modes' SSE send; fast modes keep 30s. Env knobs PERPLEXITY_TIMEOUT_SECS / PERPLEXITY_LONG_TIMEOUT_SECS. Fixes premature Deep Research cutoffs. Docs: README env-var section rewritten (full rosters, raw:, timeouts, no CSRF).
Fork integration branch. Merges two upstream community PRs and adds rate-limit ("out of limit") handling on top.
Merged upstream PRs
next-auth.csrf-tokencookie; CSRF is now fetched dynamically from/api/auth/csrf. OnlyPERPLEXITY_SESSION_TOKENis required now.main.rsresolved: kept feat: add Perplexity models, connectors, and Computer mode mishamyrt/perplexity-web-api-mcp#11's 3-tuple model config (ask/reason/computer) with fix: fetch CSRF token dynamically from /api/auth/csrf mishamyrt/perplexity-web-api-mcp#14's single-token error message.New in this branch — rate-limit / out-of-limit handling
rate_limit.rs: client forGET /rest/rate-limit/all(RateLimits,SourceLimit,QuotaStatus). Parsesremaining_pro(weekly),remaining_research,remaining_labs,remaining_agentic_research, andsources.source_to_limit(shape verified vs live API, 2026-07).Client::search_stream(): authenticated metered modes now returnError::RateLimited { feature, remaining }instead of Perplexity's silent empty answer when a plan quota is exhausted. Transient probe failures fall through (non-blocking).RateLimitRequiresAuth,RateLimitFetch,RateLimited.perplexity_usage: reports remaining quotas + per-source limits.Client::rate_limits(),Client::check_quota_for_mode().Model roster after merge
Verification
cargo fmt --all✓cargo clippy --workspace --all-targets --all-features -- -D warnings✓ (clean)cargo test --workspace✓ (11 lib incl. 3 new rate_limit tests, 4 bin, doctests)perplexity_search/ask/reason/research/computer/study/document_review/usage)