feat: Perplexity API key override and opt-in model allowlist - #2
Merged
Conversation
Add runtime- and env-configurable settings to control Perplexity usage: - API key is overridable at runtime via POST /api/config (seeded from PERPLEXITY_API_KEY at startup) and is masked everywhere it is surfaced. - Model allowlist (opt-in): only `sonar` is enabled by default; `sonar-pro`, `sonar-reasoning`, `sonar-reasoning-pro`, and `sonar-deep-research` must be enabled explicitly via PERPLEXITY_ENABLED_MODELS or the `perplexity_enabled_models` runtime config. Disabled models are rejected before any billable API call (recorded as 403 in metrics). - Reasoning tool model is configurable via PERPLEXITY_REASONING_MODEL and is gated by the allowlist (sonar-reasoning-pro is disabled by default). - Service reads key/enabled-models dynamically and rebuilds the SDK client when the key changes; adds config://perplexity resource. Updates README, CONFIGURATION.md, API.md and adds tests for gating, masking, validation, and runtime key override. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Adds settings to control Perplexity usage — overriding the API key and toggling which models are enabled, defaulting to
sonar-only with the expensive models opt-in for cost control.POST /api/config(seeded fromPERPLEXITY_API_KEYat startup). Masked everywhere it's surfaced (pplx...7890); the real value is only used internally.sonaris enabled by default.sonar-pro,sonar-reasoning,sonar-reasoning-pro, andsonar-deep-researchmust be enabled explicitly viaPERPLEXITY_ENABLED_MODELS(env, comma-separated) orperplexity_enabled_models(runtime config). A disabled model is rejected before any billable API call and recorded as a 403 in metrics. Unknown model names are rejected with a clear error.PERPLEXITY_REASONING_MODEL(defaultsonar-reasoning-pro) and is gated by the allowlist — soperplexity_reasonreturns a "model not enabled" error until opted in (by design).config://perplexityresource.Test plan
pytest— 142 passing (new tests: model gating, opt-in allowed, reason-blocked-by-default, runtime key override, API-key masking, env parsing, model validation)ruff check+ruff format— cleanmypy src/— no new errors vs.mainbaselineGET /api/config🤖 Generated with Claude Code