Skip to content

feat(ai-perplexity): add Perplexity Search integration#6204

Open
jliounis wants to merge 1 commit into
Effect-TS:mainfrom
jliounis:feat/perplexity-search
Open

feat(ai-perplexity): add Perplexity Search integration#6204
jliounis wants to merge 1 commit into
Effect-TS:mainfrom
jliounis:feat/perplexity-search

Conversation

@jliounis
Copy link
Copy Markdown

Summary

Adds a new @effect/ai-perplexity package providing Effect bindings for the Perplexity Search API.

What's added

  • PerplexityClient — HTTP client wrapper that handles authentication and error mapping (platform HttpClient errors → @effect/ai AiError).
  • PerplexitySearch — service with a search(options) method that returns a typed SearchResponse (results: { title, url, snippet, date? }[]).
  • Supports the documented Search API request fields: max_results, max_tokens_per_page, search_domain_filter, search_recency_filter, search_after_date_filter, search_before_date_filter.
  • Validates that search_domain_filter does not mix allow- and deny-list entries (the API does not accept that), failing fast with AiError.MalformedInput if it does.
  • API key is read from PERPLEXITY_API_KEY, falling back to PPLX_API_KEY, via Config.redacted. A custom URL can be supplied via PERPLEXITY_API_URL or programmatically.
  • Includes a PerplexityConfig tag and withClientTransform helper, mirroring the pattern used by @effect/ai-anthropic.

Tests

10 unit tests in packages/ai/perplexity/test/PerplexitySearch.test.ts, all using a mocked HttpClient (HttpClient.make) so no network calls are made:

  • request body construction (camelCase → snake_case mapping, optional fields)
  • allowlist / denylist domain filter handling, including the mixed-mode rejection
  • success decoding into SearchResponse
  • non-2xx → AiError.HttpResponseError
  • malformed JSON body → AiError.MalformedOutput
  • header / URL / method assertions on the captured request

Run with:

pnpm --filter @effect/ai-perplexity test
pnpm --filter @effect/ai-perplexity check
pnpm --filter @effect/ai-perplexity build

All three pass locally.

Docs

  • packages/ai/perplexity/README.md documents installation, authentication, basic usage, available options, and the domain-filter caveat.
  • Includes a changeset (@effect/ai-perplexity minor) describing the addition.

References

Adds a new @effect/ai-perplexity package providing Effect bindings for
the Perplexity Search API. Exposes a PerplexitySearch service with a
typed search method (returns {title, url, snippet, date?}) plus support
for max_results, search_domain_filter (allow- or deny-list, validated to
not mix), search_recency_filter, and date-range filters.

Reads the API key from PERPLEXITY_API_KEY (with PPLX_API_KEY as a
fallback) via Config.redacted.

Includes unit tests (10 cases) covering body shape, filter forwarding,
mixed-domain rejection, success decoding, HTTP errors, and malformed
response handling.
@jliounis jliounis requested a review from IMax153 as a code owner April 29, 2026 23:16
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Apr 29, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 29, 2026

🦋 Changeset detected

Latest commit: 5dc0e3a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/ai-perplexity Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jliounis
Copy link
Copy Markdown
Author

Friendly bump — changeset is present, typecheck/lint/build are clean. Happy to address any feedback on the @effect/ai-perplexity package (modeled after @effect/ai-anthropic). Let me know if you'd like changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

1 participant