feat(websearch): add Perplexity backend #25909
Open
jliounis wants to merge 2 commits into
Open
Conversation
916eb3a to
dff2541
Compare
Author
|
Updated this PR to make Perplexity strictly opt-in instead of default — Exa remains the default backend. Force-pushed Changes vs. the previous revision:
To use Perplexity now: OPENCODE_ENABLE_PERPLEXITY=1 PERPLEXITY_API_KEY=pplx-... opencodeExisting Exa users see zero behavior change. |
Adds a Perplexity Search API backend for the `websearch` tool, opt-in via `OPENCODE_ENABLE_PERPLEXITY=1` with `PERPLEXITY_API_KEY` (or `PPLX_API_KEY`). Exa remains the default backend.
dff2541 to
837e85e
Compare
Author
|
Rebased onto latest Upstream changed
I integrated Perplexity into that new architecture rather than fighting it:
PR is |
6 tasks
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, opt-in backend. Exa remains the default. Users who want to use Perplexity explicitly setOPENCODE_ENABLE_PERPLEXITY=1with aPERPLEXITY_API_KEY(orPPLX_API_KEY).Why: 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, and gives everyone else a way to plug in a different search provider without rewriting the tool.
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:OPENCODE_ENABLE_EXA=1or provider isopencode-> Exa (default)OPENCODE_ENABLE_PERPLEXITY=1withPERPLEXITY_API_KEY(orPPLX_API_KEY) -> Perplexityflag.tsaddsOPENCODE_ENABLE_PERPLEXITY, which is strictly opt-in — setting just a Perplexity key does not enable it.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. Users who want Perplexity must explicitly opt in with
OPENCODE_ENABLE_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.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