Skip to content

feat: Perplexity API key override and opt-in model allowlist - #2

Merged
cotdp merged 1 commit into
mainfrom
feat/perplexity-model-settings
Jun 1, 2026
Merged

feat: Perplexity API key override and opt-in model allowlist#2
cotdp merged 1 commit into
mainfrom
feat/perplexity-model-settings

Conversation

@cotdp

@cotdp cotdp commented Jun 1, 2026

Copy link
Copy Markdown
Owner

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.

  • API key override: configurable at runtime via POST /api/config (seeded from PERPLEXITY_API_KEY at startup). Masked everywhere it's surfaced (pplx...7890); the real value is only used internally.
  • 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 (env, comma-separated) or perplexity_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.
  • Reasoning tool: model is configurable via PERPLEXITY_REASONING_MODEL (default sonar-reasoning-pro) and is gated by the allowlist — so perplexity_reason returns a "model not enabled" error until opted in (by design).
  • Service reads the key/enabled-models dynamically and rebuilds the SDK client when the key changes. Adds a config://perplexity resource.

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 — clean
  • mypy src/ — no new errors vs. main baseline
  • End-to-end check: disabled model gated without API call; opt-in enables it; key masked in GET /api/config

Note: .env.example could not be updated (blocked by local security policy). New optional vars to document there: PERPLEXITY_ENABLED_MODELS, PERPLEXITY_REASONING_MODEL.

🤖 Generated with Claude Code

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>
@cotdp
cotdp merged commit 9d3e9ba into main Jun 1, 2026
4 checks passed
@cotdp
cotdp deleted the feat/perplexity-model-settings branch June 1, 2026 14:41
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