# Dedicated search APIs

The extension exposes exactly one model-facing tool, `web_search`. In normal
mode it uses `query` / `urls`; when Parallel is active it switches to Parallel's
official `objective` / `search_queries` / `urls` schema. Standalone services do
not need a pi chat model or a luna/haiku/flash model id. No SDK or MCP dependency
is required: the adapters use Node's native fetch, existing cancellation,
timeout, error and fallback helpers.

This release adds **Parallel Search**, which is at the top of the new
[Artificial Analysis snapshot](https://artificialanalysis.ai/agents/search-api):
**Parallel advanced objective (83)** ties **Keenable Pro (83)**. Parallel fast
objective scores 82; Exa auto and Perplexity medium score 80. The no-search
baseline is **33** and integrated OpenAI Web Search scores **74**. See the
[21 Nov 2026 screenshot](../assets/search-index.png) and [benchmark methodology](https://artificialanalysis.ai/methodology/search-api).

## Interfaces

| Provider | Search | Fetch | Optional environment fallback |
|---|---|---|---|
| Parallel | `POST https://api.parallel.ai/v1/search` | `POST https://api.parallel.ai/v1/extract` | `PARALLEL_API_KEY` |
| DeepSeek | `POST https://api.deepseek.com/v1/tools/search` | `POST https://api.deepseek.com/v1/tools/fetch` | `DEEPSEEK_API_KEY` |
| Perplexity | `POST https://api.perplexity.ai/search` | **No** | `PERPLEXITY_API_KEY` |
| Keenable | `POST https://api.keenable.ai/v1/search` | `GET https://api.keenable.ai/v1/fetch` | `KEENABLE_API_KEY` or explicit public access |
| Exa | `POST https://api.exa.ai/search` | `POST https://api.exa.ai/contents` | `EXA_API_KEY` |

Successful responses omit known API bookkeeping before reaching the model:

| Provider | Omitted fields |
|---|---|
| Parallel search | `search_id`, `usage`, `warnings`, `session_id`, root `metadata` |
| Keenable search and fetch | `mode` (search request mode) and `usage` (billing, credits and remaining balance) |
| Perplexity search | `id` (request tracking) |
| Exa search | `requestId`, `costDollars`, `searchTime`, `warnings`, `resolvedSearchType` |

This filtering is shallow and provider-specific. Result objects, page text,
source dates, scores, citations, truncation indicators and unknown fields remain
unchanged. Provider timestamps such as Perplexity `server_time` are retained
verbatim; Exa `searchTime` is a processing duration and remains omitted.
Exa `notices` are retained because they explain how results were
produced; `warnings` are request diagnostics and `resolvedSearchType` is deprecated.
Exa fetch already returns individual documents rather than the response envelope.
Native model adapters select search results, answers and source evidence without
forwarding response-level token usage. HTTP errors retain their diagnostic details
for normal fallback and troubleshooting.

### Parallel: official advanced Search and Extract

Parallel is intentionally the special mode in this extension. Search sends the
official advanced request:

```json
{
  "mode": "advanced",
  "objective": "Find official TypeScript documentation.",
  "search_queries": ["TypeScript official documentation"]
}
```

Extract sends:

```json
{
  "urls": ["https://example.com/page"],
  "objective": "Summarize the page."
}
```

Search requires an `objective` and 1–3 `search_queries`; Extract accepts `urls`
with an optional objective. The model-facing schema changes to
`objective` / `search_queries` / `urls` while Parallel is active. Since that
schema is incompatible with the normal `query` / `urls` contract, Parallel
becomes the only search/fetch candidate: errors do not fall back to another
provider, and the provider picker is unavailable. Disable it with
`/web-search-api parallel` to restore the normal schema and fallback behavior.

Create a key at https://platform.parallel.ai and save it through
`/pi-better-web-search login`, or set `PARALLEL_API_KEY` before starting pi.
Requests use `X-API-Key`; the adapter matches returned results and errors by URL,
keeps successful pages, redacts the sent key, and omits root bookkeeping fields
listed above. No live validation request is made during login.

### DeepSeek: native Search/Fetch

Terminal login works without a pi chat model. Both native endpoints use the
resolved saved/environment key as a Bearer credential, and neither sends a
model name. Extension-saved keys are not silently forwarded to arbitrary
custom model gateways. It shares credential-specific `Retry-After` across search and fetch, and rejects
malformed header keys before HTTP.

Pi's official `deepseek` provider is also supported independently: credentials
saved by pi's `/login` or configured through `models.json` are resolved through
pi's registry at request time, not copied into this extension. Provider-level
Search/Fetch discovery works without an available chat model or `flash` id.
These routes retain pi's configured native/proxy base URL and headers; extension
API toggles still apply only to the separate saved/environment standalone path.
Third-party gateways merely listing DeepSeek chat models are not promoted to
native DeepSeek Search/Fetch.

### Perplexity: standard Search API only

The request is exactly:

```json
{ "query": "your query", "search_type": "web", "max_results": 10 }
```

Authorization is `Bearer <PERPLEXITY_API_KEY>`. **Fast search is not used.**
There is no `effort`, `preset`, `model`, `tools`, conversation state or generated
answer. Neither Agent nor Orchestrator APIs are called. `results`, `server_time`
and unknown fields are returned inside `search` without rewriting the results;
only the outer request `id` is omitted.

Perplexity alone exposes a query-only schema. Configure Keenable or an existing
URL-capable provider to add `urls`; a combined call can search with Perplexity
and fetch with another provider. A search success is preserved if fetch fails.

Create a key at https://console.perplexity.ai and save it through
`/pi-better-web-search login`. `PERPLEXITY_API_KEY` is an optional fallback. Never paste a key into chat. If a key is
exposed, rotate it in the console. Missing credentials never trigger an
unauthenticated Perplexity request.

### Keenable: pro search and live fetch

Search sends `{ "query": "...", "mode": "pro", "max_results": 10 }`, not the
fast `realtime` mode. Fetch uses GET with URL-encoded `url` and `live=true`,
without an LLM extraction `prompt`. Response content and source metadata are
preserved; the outer search `mode` and billing `usage` fields are omitted.
Keyed requests use `X-API-Key: <KEENABLE_API_KEY>`.

Without a key, explicit public access uses `/v1/search/public` and
`/v1/fetch/public` with `X-Keenable-Title: pi-better-web-search`. It is **off by
default**. The terminal asks for consent before enabling it: queries, URLs and
results are sent to Keenable under its public data policy and IP rate limits.
Do not send secrets or personal data. Get a production key at
https://docs.keenable.ai/api-keys. An invalid/expired key never silently
switches a request to public access. Each adapter request rechecks public
consent, including later requests in a URL batch. A key disappearing or logout
between search and fetch cannot silently enable public access; completed search
results/pages remain available while unresolved URLs follow normal fallback.

Target errors (404, extraction failure, target-blocked/private-URL 403 codes)
are per-URL failures. Auth, balance, rate limits and provider transport failures
stop that provider's batch while preserving completed pages for fallback.

### Exa: search highlights and full-text fetch

With `X-API-Key: <EXA_API_KEY>`, search sends the user-approved request:

```json
{
  "query": "your query",
  "numResults": 10,
  "contents": { "highlights": true }
}
```

`type` is omitted (server default `auto`). Raw `results`/highlights, `notices`
and unknown fields are preserved. Request tracking, cost, processing duration, request
warnings and the deprecated resolved search type are omitted as listed above.
There is no chat model, SDK, Answer/Agent API or generated objective. The
model-facing contract stays `query` / `urls`; other advanced options remain
off. See the [skill comparison and decision table](search-skills.md).

URL-only calls use `POST /contents` without performing a search:

```json
{ "urls": ["https://example.com/page"], "text": true }
```

Unlike search, extraction options belong at the top level of `/contents`.
Full text is used for known-page fetch, without also requesting highlights or
summary. No forced live crawl, freshness filter or extraction budget is added.
A combined `query` + `urls` call performs both operations independently.

Fetch batches the requested URLs, inspects per-URL `statuses` even on HTTP 200,
and returns each successful raw document unchanged as `fetched[].data`. Error
statuses match either `id` or `url`, including canonical redirect URLs. Error
redaction retains the credential actually sent if login rotates it in flight.
Result identity/URL matching handles reordered responses, omitted pages, redirects with
an original `id`, and repeated input URLs; documents are never paired by array
index. A failed status or missing page text produces a per-URL error. Only
unresolved URLs proceed to another fetch provider, without discarding successful
pages. Global HTTP/transport errors use the shared cooldown/fallback handling.

Create a key at https://dashboard.exa.ai/api-keys and save it with
`/pi-better-web-search login` → Exa. Alternatively set it in the environment of
the process that starts pi; the extension does not automatically load `.env`.
For example, in PowerShell, prompt locally without echoing the key:

```powershell
$key = Read-Host "EXA_API_KEY" -AsSecureString
$env:EXA_API_KEY = [System.Net.NetworkCredential]::new("", $key).Password
Remove-Variable key
pi
```

This sets the key for that terminal and child processes, not permanently. Do
not paste it into chat or commit it. Restart pi if its parent process did not
inherit the variable. Missing credentials never trigger an Exa HTTP request;
explicit enable still requires a key. No real key is bundled with this project.

## Terminal login and configuration

```text
/pi-better-web-search login
```

Choose one of **Parallel, DeepSeek, Exa, Keenable, or Perplexity** from the
five-provider menu, then type/paste a key into the masked input and press Enter. Esc/Ctrl+C cancels
without changing files. Saved keys take precedence over environment variables;
login enables that API and resyncs the tool immediately, without restarting pi
or switching the conversation model. No billable validation request is sent.
The actual key never enters chat, command arguments, UI output or ordinary
settings. Secret entry is local TUI only, not RPC or print mode.

`/pi-better-web-search status` reports presence only. Re-running login replaces
one saved key without losing the others. `/pi-better-web-search logout` confirms
removal and disables that standalone API; it does not remove environment or
pi conversation-provider credentials. Keenable does not silently switch to
public mode on logout or if a keyed login's credential file disappears. Public
access must be enabled separately with privacy consent. Manual search/fetch
provider choices are preserved.

Keys are stored in `<pi agent dir>/better-web-search-auth.json`, overridable
with `PI_BETTER_WEB_SEARCH_AUTH`. The store is **local plaintext, not encrypted**;
new files use mode 0600 and new parent directories 0700 where supported, with
Windows relying on the user profile's ACLs. Atomic writes and a cross-process
lock protect replacements; a corrupt file is never overwritten by login.
Do not commit/share this file or its backups. No OS keychain dependency is used.

`/web-search-api [parallel|deepseek|exa|keenable|perplexity]` remains the enable/disable
menu. It shows readiness and **key presence/source only**, never key values:

- **Automatic**: enable if a saved or environment key is present (the default).
- **Enable**: explicitly enable; non-public APIs still need their keys. Keenable
  can use public access after a privacy confirmation.
- **Disable**: exclude this standalone API even if its key exists.
- **Show setup instructions**: login command, console link and environment name.

Cancelling leaves settings unchanged. Saving immediately resyncs tool exposure
and URL support, without switching the conversation model. If the tool was
manually deactivated, that choice is respected.

`/web-search-provider [search|fetch]` continues to select a preferred provider
per phase, including the configured standalone APIs. While Parallel is active,
the picker reports that routing is locked and cannot change the priority.
Perplexity is absent from the fetch picker; Keenable, Exa, and Parallel support
both phases. Auto resets only that phase's preference.

## Priority and fallback

Search order:

1. Active Parallel, if configured: Parallel is the only candidate and no fallback
   is attempted because its schema is incompatible with the normal contract.
2. Explicit `/web-search-provider search` preference, if usable.
3. Configured Keenable, Exa, Perplexity, then standalone DeepSeek.
4. Existing current-provider, success-cache, native-family and sibling routing.

Fetch follows the same policy: active Parallel is exclusive; otherwise Keenable,
Exa, then standalone DeepSeek precede automatic native routing; Perplexity does
not support fetch. Both provider pickers remain preferences, not locks, except
for the active Parallel schema mode. Search and fetch each allow one initial
attempt and up to six fallback attempts. A successful empty search is valid.
The existing partial-success policy applies across dedicated and native APIs.

There are no hidden HTTP retries. `Retry-After` seconds and HTTP dates defer
subsequent requests to that service/credential **across search and fetch**;
other providers can run immediately. An explicit preference bypasses a previous
Retry-After for its first request. Automatic model routes remain subject to health
cooldowns, but those cooldowns never displace the explicit or standalone priorities.
If fallback cannot satisfy the requested operation, the agent receives the
provider's bounded, credential-redacted error body and original `Retry-After`
header. An active standalone backoff also reports its remaining time. Native
provider HTTP errors include the header, but the extension does not enforce a
native-provider backoff or sleep on the agent's behalf.
A 401 needs a corrected key; a 402 needs
credits and is not retried in the same attempt; a 429 is rate limiting. A
credential change does not reuse another credential's Retry-After state.

## Persisted settings

`<pi agent dir>/better-web-search-settings.json` (or
`PI_BETTER_WEB_SEARCH_SETTINGS`) stores only choices/toggles:

```json
{
  "version": 1,
  "search": "perplexity",
  "fetch": "keenable",
  "apis": { "parallel": true, "perplexity": true, "keenable": true, "exa": true, "deepseek": true, "keenableKeyRequired": true }
}
```

Keys are stored only in the separate credential file described above, never in
ordinary settings/cache. API availability and credential source join the cache
fingerprint, without credentials or credential hashes. Internal cache/health
identities (`perplexity/search`, `keenable/search-fetch`, `exa/search-fetch`,
`deepseek/search-fetch`) are
**not inference models**, are not registered with pi, and are never sent to the APIs. Terminal
routes show actual endpoints instead.

## Verification

```bash
npm run check
npm test
npm run verify:package
npm run test:live:search-apis -- all
```

The opt-in live test sends only a public example query and URL, prints HTTP
status/response shape, and skips Perplexity/Exa if neither saved nor environment
keys are available. It tests
Keenable's public endpoints if no Keenable key is present. It stops a provider
on failure rather than immediately retrying a 429. API calls may consume quota.

Sources: [Perplexity Search](https://docs.perplexity.ai/api-reference/search-post),
[pricing](https://docs.perplexity.ai/docs/getting-started/pricing),
[rate limits](https://docs.perplexity.ai/docs/admin/rate-limits-usage-tiers),
[Keenable Search](https://docs.keenable.ai/api-reference/search),
[Fetch](https://docs.keenable.ai/api-reference/fetch),
[errors](https://docs.keenable.ai/errors),
[Exa search reference](https://exa.ai/docs/reference/search),
[Exa contents reference](https://exa.ai/docs/reference/get-contents),
[Exa integration skill](https://github.com/exa-labs/agent-skills/tree/main/skills/build-with-exa).
