Skip to content

sonar: raise key-validation max_tokens to Perplexity's minimum (16) - #5

Merged
dorkitude merged 2 commits into
dorkitude:mainfrom
taylorazulai:fix/sonar-validate-max-tokens
Oct 18, 2026
Merged

dorkitude merged 2 commits into
dorkitude:mainfrom
taylorazulai:fix/sonar-validate-max-tokens

Conversation

@taylorazulai

Copy link
Copy Markdown
Contributor

Problem

webctl keys validate fails for Sonar even with a valid Perplexity API key:

Sonar (Perplexity)   ✗ Sonar API returned HTTP 400: max_tokens must be at least 16
error: 1 key(s) failed validation

Perplexity's chat completions API now rejects max_tokens values below 16. Sonar.Validate() sends its minimal probe with MaxTokens: 1, so validation always gets HTTP 400 regardless of key validity.

Real searches are unaffected — Search() sends no max_tokens at all — so only the validation probe is broken.

Fix

Raise the probe from MaxTokens: 1 to MaxTokens: 16, the smallest value the API accepts, keeping validation as cheap as possible. (Omitting the field instead would let Sonar generate an uncapped "hello" completion, costing more than the capped probe.)

Verification

Rebuilt v0.1.7 with this patch on macOS/arm64:

$ webctl keys validate
  Brave Search (recommended: 5,000 free searches/month) ✓ valid
  Sonar (Perplexity)   ✓ valid
  Tavily               ✓ valid
  Keenable             ✓ valid
  Jev (TypeSafe)       ✓ valid

taylorazulai and others added 2 commits October 2, 2026 22:07
Perplexity's chat completions API now rejects max_tokens < 16 with
HTTP 400 ("max_tokens must be at least 16"), so `webctl keys validate`
reports a perfectly valid Sonar key as failed. Raise the validation
probe from 1 token to 16, the smallest value the API accepts, keeping
the probe as cheap as possible. Search() is unaffected: it sends no
max_tokens at all.
@dorkitude
dorkitude merged commit 4f7d3fb into dorkitude:main Oct 18, 2026
1 check passed
@dorkitude

Copy link
Copy Markdown
Owner

Thanks @taylorazulai! Nice catch, and the PR made it easy to review. 🙏

I pushed one small commit that updates TestSonarValidate, which still expected max_tokens of 1. With that, CI is green. Merged, and it will go out in the next webctl release.

@dorkitude

Copy link
Copy Markdown
Owner

Shipped in v0.1.8 🚀 (brew upgrade --cask webctl). Thanks again!

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.

2 participants