Skip to content

feat(websearch): add Perplexity backend (default), keep Exa as alt#25909

Open
jliounis wants to merge 1 commit intoanomalyco:devfrom
jliounis:add-perplexity-websearch
Open

feat(websearch): add Perplexity backend (default), keep Exa as alt#25909
jliounis wants to merge 1 commit intoanomalyco:devfrom
jliounis:add-perplexity-websearch

Conversation

@jliounis
Copy link
Copy Markdown

@jliounis jliounis commented May 5, 2026

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The websearch tool today calls Exa via the hosted MCP endpoint and is the only backend available. This PR adds the Perplexity Search API as a second backend and makes it the default when the user has PERPLEXITY_API_KEY set. Exa stays exactly as it was for users who want it.

Why: Perplexity's /search endpoint returns higher-recall results for technical queries that opencode runs (in my testing on real coding tasks), and gating the existing tool behind a single proprietary backend shouldn't be the only option. Letting users pick keeps Exa first-class for people who already pay for it.

How it works:

  • New mcp-perplexity.ts makes a direct REST call to https://api.perplexity.ai/search (Perplexity has no hosted MCP HTTP endpoint, only stdio, so the MCP-style naming is just for symmetry with mcp-exa.ts). Sends Authorization: Bearer $PERPLEXITY_API_KEY and X-Pplx-Integration: opencode/<version> so usage is attributable on our side.
  • websearch.ts chooses the backend at runtime. Selection precedence:
    1. PERPLEXITY_API_KEY is set and OPENCODE_DISABLE_PERPLEXITY is not set -> Perplexity
    2. OPENCODE_ENABLE_EXA=1 or provider is opencode -> Exa
    3. Otherwise -> tool not registered (existing behavior)
  • flag.ts adds OPENCODE_ENABLE_PERPLEXITY (auto-enabled when the key is present, with OPENCODE_DISABLE_PERPLEXITY=1 as the explicit escape hatch).
  • registry.ts gating: surface the websearch tool when either backend is active, instead of only when Exa is active.
  • providers.mdx adds Perplexity to the LLM provider listing (Agent API is OpenAI-compatible at https://api.perplexity.ai).
  • tools.mdx documents the dual websearch backends and the precedence rules.

Existing Exa users see no behavior change unless they set a Perplexity key, and even then they can opt back into Exa with OPENCODE_DISABLE_PERPLEXITY=1.

This replaces the docs-only PR #24976, which was closed in favor of shipping docs + code together.

How did you verify your code works?

  • bun run typecheck passes for packages/opencode and packages/core.
  • Existing snapshot tests under packages/opencode/test/tool/__snapshots__/parameters.test.ts.snap updated and passing (the livecrawl and type parameter descriptions changed since they're Exa-specific now).
  • Manually exercised mcp-perplexity.call with a real PERPLEXITY_API_KEY against api.perplexity.ai/search and confirmed the response parses, the integration header is sent, and contextMaxCharacters truncation works.
  • Manually verified the Exa path still works when PERPLEXITY_API_KEY is unset (no behavior change).
  • Did NOT add new HTTP-mock unit tests because the existing mcp-exa.ts has no equivalent test pattern in this repo to mirror; happy to add one if a maintainer points to a preferred fixture style.

Screenshots / recordings

N/A (CLI tool, no UI).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

- Add packages/opencode/src/tool/mcp-perplexity.ts calling Perplexity Search REST API
- Update websearch.ts to choose backend at runtime: Perplexity when PERPLEXITY_API_KEY is set, otherwise Exa
- Add OPENCODE_ENABLE_PERPLEXITY flag (auto-enabled when key present, OPENCODE_DISABLE_PERPLEXITY escape hatch)
- Update registry gating so websearch tool surfaces with either backend
- Document Perplexity LLM provider (Agent API + Search API) in providers.mdx
- Update tools.mdx websearch section to describe both backends

Per integration heuristic: wherever a repo integrates Exa, also offer Perplexity Search API.
Builds on the closed docs-only PR anomalyco#24976.

Signed-off-by: James Liounis <james.liounis@perplexity.ai>
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