feat(websearch): add Perplexity backend (default), keep Exa as alt#25909
Open
jliounis wants to merge 1 commit intoanomalyco:devfrom
Open
feat(websearch): add Perplexity backend (default), keep Exa as alt#25909jliounis wants to merge 1 commit intoanomalyco:devfrom
jliounis wants to merge 1 commit intoanomalyco:devfrom
Conversation
- 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>
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.
Issue for this PR
Closes #
Type of change
What does this PR do?
The
websearchtool 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 hasPERPLEXITY_API_KEYset. Exa stays exactly as it was for users who want it.Why: Perplexity's
/searchendpoint 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:
mcp-perplexity.tsmakes a direct REST call tohttps://api.perplexity.ai/search(Perplexity has no hosted MCP HTTP endpoint, only stdio, so the MCP-style naming is just for symmetry withmcp-exa.ts). SendsAuthorization: Bearer $PERPLEXITY_API_KEYandX-Pplx-Integration: opencode/<version>so usage is attributable on our side.websearch.tschooses the backend at runtime. Selection precedence:PERPLEXITY_API_KEYis set andOPENCODE_DISABLE_PERPLEXITYis not set -> PerplexityOPENCODE_ENABLE_EXA=1or provider isopencode-> Exaflag.tsaddsOPENCODE_ENABLE_PERPLEXITY(auto-enabled when the key is present, withOPENCODE_DISABLE_PERPLEXITY=1as the explicit escape hatch).registry.tsgating: surface the websearch tool when either backend is active, instead of only when Exa is active.providers.mdxadds Perplexity to the LLM provider listing (Agent API is OpenAI-compatible athttps://api.perplexity.ai).tools.mdxdocuments 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 typecheckpasses forpackages/opencodeandpackages/core.packages/opencode/test/tool/__snapshots__/parameters.test.ts.snapupdated and passing (thelivecrawlandtypeparameter descriptions changed since they're Exa-specific now).mcp-perplexity.callwith a realPERPLEXITY_API_KEYagainstapi.perplexity.ai/searchand confirmed the response parses, the integration header is sent, andcontextMaxCharacterstruncation works.PERPLEXITY_API_KEYis unset (no behavior change).mcp-exa.tshas 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