Openrouter Websearch
OpenCode plugin: web search via the OpenRouter web plugin, with in-TUI settings menu
1
322
28 in 7 days
37.9
Multi-signal model
3 days ago
2026-10-17
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-openrouter-websearch@1.0.0"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-openrouter-websearch@1.0.0"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D opencode-openrouter-websearchOpenCode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
OpenCode plugin: web search through the OpenRouter web plugin (Exa by default).
How it works
sequenceDiagram
participant Agent
participant Plugin as OpenRouterWebsearch
participant OpenRouter
participant Summarizer
Agent->>Plugin: websearch
Plugin->>OpenRouter: Search via web plugin
OpenRouter-->>Plugin: Search results
opt Summarization enabled
Plugin->>Summarizer: Summarize results
Summarizer-->>Plugin: Brief with citations and sources
end
Plugin-->>Agent: Search response
- Search call runs the configured model through OpenRouter's web plugin (Exa by default) and produces the raw answer plus results with page contents.
- Summarize call (only when
summarize: true, default) sends the answer plus all results — each truncated tosummarizeMaxCharscharacters — back to the model with a preservation-focused prompt: it must keep every distinct fact, number, date and exception, mark conflicts with sources, and cite claims as[n]. The agent then sees only the brief and the list of sources, so a typical query costs a few hundred tokens instead of several thousand. - If the summarize call fails, the plugin logs the error and falls back to raw results — search never breaks because of summarization.
Usage statistics
Every search appends to stats.json next to the plugin:
calls/searchCalls/summarizeCalls— call countssearchCost— web-plugin (search) part of the cost, from OpenRouterusage.cost_detailsmodelCost— rest of the search-call cost (model tokens)summarizeCost— cost of the summarization calltotalCost,inputTokens,outputTokens— cumulative totals in USD / tokens
View anytime:
node settings.mjs --stats
What it does
- Registers an
openrouterprovider for OpenCode's built-inwebsearchtool and sets it as the default. All agents get one clean web search tool. - Adds a "Websearch: plugin settings" entry to the command palette (Ctrl+P): pick the model from the live OpenRouter list, set result/token limits, engine, search prompt, include/exclude domains.
- Ships a CLI settings script as an alternative to the TUI menu.
Package stats
- npm page — versions, dependencies, dependents
- Download trends — weekly downloads over time
- npmjs stats — per-version download counts
Install
From npm (after publish):
// opencode.jsonc
{
"plugins": ["opencode-openrouter-websearch"]
}
From a local path:
{
"plugins": [
{ "package": "/path/to/opencode-openrouter-websearch" }
]
}
Requires an OpenRouter connection (opencode auth login → openrouter) or OPENROUTER_API_KEY.
Configuration
Stored in the plugin's own config.json:
{
"model": "openai/gpt-6-luna",
"maxResults": 5,
"maxOutputTokens": 4000,
"engine": "exa", "includeDomains": [],
"excludeDomains": []
}
Options from the plugins entry in opencode.jsonc (ctx.options) override config.json.
| Option | Default | Meaning |
|---|---|---|
model |
openai/gpt-6-luna |
Model used to run the search/answer |
maxResults |
5 |
Max results (web.max_results) |
maxOutputTokens |
4000 |
Answer token budget |
engine |
provider default | exa | native | firecrawl | parallel | perplexity |
mode |
— | OpenRouter web plugin mode |
searchPrompt |
— | Custom search prompt |
summarize |
true |
Return a compact brief instead of full contents |
summarizeMaxChars |
1200 |
Max chars per result fed to the summarizer |
includeDomains / excludeDomains |
— | Domain filters |
Settings
- TUI: Ctrl+P → "Websearch: plugin settings"
- CLI:
npm run settingsin the plugin directory (ornode settings.mjs)
Restart OpenCode after changing settings.
Layout
index.js— server plugin: websearch provider registrationtui.js— TUI plugin: settings menu in the command palettesettings.mjs— standalone CLI settings menuconfig.json— plugin configuration
Similar plugins
Jev Router
opencode-jev-router-plugin
OpenCode v2 plugin that routes each prompt to the cheapest capable model using the JEV classifier.
Bramhashiv
bramhashiv
Smart multi-provider coding router — plugin for OpenCode
Websearch
opencode-websearch
Web search plugin for OpenCode