2026-01-18 01:42:40 +00:00
---
2026-03-08 20:37:54 +05:30
summary: "Perplexity Search API and Sonar/OpenRouter compatibility for web_search"
2026-01-18 01:42:40 +00:00
read_when:
2026-03-04 04:57:19 +00:00
- You want to use Perplexity Search for web search
2026-03-08 20:37:54 +05:30
- You need PERPLEXITY_API_KEY or OPENROUTER_API_KEY setup
2026-03-22 16:02:25 -07:00
title: "Perplexity Search (legacy path)"
2026-01-18 01:42:40 +00:00
---
2026-03-04 04:57:19 +00:00
# Perplexity Search API
2026-01-18 01:42:40 +00:00
2026-03-08 14:10:26 +00:00
OpenClaw supports Perplexity Search API as a `web_search` provider.
It returns structured results with `title` , `url` , and `snippet` fields.
2026-01-18 01:42:40 +00:00
2026-03-08 20:37:54 +05:30
For compatibility, OpenClaw also supports legacy Perplexity Sonar/OpenRouter setups.
2026-03-17 23:59:17 -05:00
If you use `OPENROUTER_API_KEY` , an `sk-or-...` key in `plugins.entries.perplexity.config.webSearch.apiKey` , or set `plugins.entries.perplexity.config.webSearch.baseUrl` / `model` , the provider switches to the chat-completions path and returns AI-synthesized answers with citations instead of structured Search API results.
2026-03-08 20:37:54 +05:30
2026-03-04 04:57:19 +00:00
## Getting a Perplexity API key
2026-01-18 01:42:40 +00:00
2026-03-15 02:58:59 +01:00
1. Create a Perplexity account at [perplexity.ai/settings/api ](https://www.perplexity.ai/settings/api )
2026-03-04 04:57:19 +00:00
2. Generate an API key in the dashboard
2026-03-08 14:10:26 +00:00
3. Store the key in config or set `PERPLEXITY_API_KEY` in the Gateway environment.
2026-01-18 01:42:40 +00:00
2026-03-08 20:37:54 +05:30
## OpenRouter compatibility
2026-03-17 23:59:17 -05:00
If you were already using OpenRouter for Perplexity Sonar, keep `provider: "perplexity"` and set `OPENROUTER_API_KEY` in the Gateway environment, or store an `sk-or-...` key in `plugins.entries.perplexity.config.webSearch.apiKey` .
2026-03-08 20:37:54 +05:30
2026-03-17 23:59:17 -05:00
Optional compatibility controls:
2026-03-08 20:37:54 +05:30
2026-03-17 23:59:17 -05:00
- `plugins.entries.perplexity.config.webSearch.baseUrl`
- `plugins.entries.perplexity.config.webSearch.model`
2026-03-08 20:37:54 +05:30
## Config examples
### Native Perplexity Search API
2026-01-18 01:42:40 +00:00
``` json5
{
2026-03-17 23:59:17 -05:00
plugins: {
entries: {
perplexity: {
config: {
webSearch: {
apiKey: "pplx-...",
},
},
},
},
},
2026-01-18 01:42:40 +00:00
tools: {
web: {
search: {
provider: "perplexity",
2026-01-31 21:13:13 +09:00
},
},
},
2026-01-18 01:42:40 +00:00
}
```
2026-03-08 20:37:54 +05:30
### OpenRouter / Sonar compatibility
``` json5
{
2026-03-17 23:59:17 -05:00
plugins: {
entries: {
perplexity: {
config: {
webSearch: {
apiKey: "<openrouter-api-key>",
baseUrl: "https://openrouter.ai/api/v1",
model: "perplexity/sonar-pro",
},
},
},
},
},
2026-03-08 20:37:54 +05:30
tools: {
web: {
search: {
provider: "perplexity",
},
},
},
}
```
2026-03-08 14:10:26 +00:00
## Where to set the key
2026-01-18 01:42:40 +00:00
2026-03-08 14:10:26 +00:00
**Via config: ** run `openclaw configure --section web` . It stores the key in
2026-03-17 23:59:17 -05:00
`~/.openclaw/openclaw.json` under `plugins.entries.perplexity.config.webSearch.apiKey` .
2026-03-09 22:57:03 -05:00
That field also accepts SecretRef objects.
2026-03-04 04:57:19 +00:00
2026-03-08 20:37:54 +05:30
**Via environment: ** set `PERPLEXITY_API_KEY` or `OPENROUTER_API_KEY`
in the Gateway process environment. For a gateway install, put it in
2026-03-22 15:28:27 -07:00
`~/.openclaw/.env` (or your service environment). See [Env vars ](/help/faq#env-vars-and-env-loading ).
2026-03-04 04:57:19 +00:00
2026-03-09 22:57:03 -05:00
If `provider: "perplexity"` is configured and the Perplexity key SecretRef is unresolved with no env fallback, startup/reload fails fast.
2026-03-04 04:57:19 +00:00
## Tool parameters
2026-03-08 20:37:54 +05:30
These parameters apply to the native Perplexity Search API path.
2026-03-04 04:57:19 +00:00
| Parameter | Description |
| --------------------- | ---------------------------------------------------- |
| `query` | Search query (required) |
| `count` | Number of results to return (1-10, default: 5) |
| `country` | 2-letter ISO country code (e.g., "US", "DE") |
| `language` | ISO 639-1 language code (e.g., "en", "de", "fr") |
| `freshness` | Time filter: `day` (24h), `week` , `month` , or `year` |
| `date_after` | Only results published after this date (YYYY-MM-DD) |
| `date_before` | Only results published before this date (YYYY-MM-DD) |
| `domain_filter` | Domain allowlist/denylist array (max 20) |
| `max_tokens` | Total content budget (default: 25000, max: 1000000) |
| `max_tokens_per_page` | Per-page token limit (default: 2048) |
2026-04-04 10:16:02 +01:00
For the legacy Sonar/OpenRouter compatibility path:
- `query` , `count` , and `freshness` are accepted
- `count` is compatibility-only there; the response is still one synthesized
answer with citations rather than an N-result list
- Search API-only filters such as `country` , `language` , `date_after` ,
`date_before` , `domain_filter` , `max_tokens` , and `max_tokens_per_page`
return explicit errors
2026-03-08 20:37:54 +05:30
2026-03-04 04:57:19 +00:00
**Examples: **
``` javascript
// Country and language-specific search
await web _search ( {
query : "renewable energy" ,
country : "DE" ,
language : "de" ,
} ) ;
// Recent results (past week)
await web _search ( {
query : "AI news" ,
freshness : "week" ,
} ) ;
// Date range search
await web _search ( {
query : "AI developments" ,
date _after : "2024-01-01" ,
date _before : "2024-06-30" ,
} ) ;
// Domain filtering (allowlist)
await web _search ( {
query : "climate research" ,
domain _filter : [ "nature.com" , "science.org" , ".edu" ] ,
} ) ;
// Domain filtering (denylist - prefix with -)
await web _search ( {
query : "product reviews" ,
domain _filter : [ "-reddit.com" , "-pinterest.com" ] ,
} ) ;
// More content extraction
await web _search ( {
query : "detailed AI research" ,
max _tokens : 50000 ,
max _tokens _per _page : 4096 ,
} ) ;
```
2026-01-18 01:42:40 +00:00
2026-03-04 04:57:19 +00:00
### Domain filter rules
2026-01-20 07:27:25 +00:00
2026-03-04 04:57:19 +00:00
- Maximum 20 domains per filter
- Cannot mix allowlist and denylist in the same request
- Use `-` prefix for denylist entries (e.g., `["-reddit.com"]` )
2026-01-18 01:42:40 +00:00
2026-03-04 04:57:19 +00:00
## Notes
2026-01-18 01:42:40 +00:00
2026-03-08 14:10:26 +00:00
- Perplexity Search API returns structured web search results (`title` , `url` , `snippet` )
2026-03-17 23:59:17 -05:00
- OpenRouter or explicit `plugins.entries.perplexity.config.webSearch.baseUrl` / `model` switches Perplexity back to Sonar chat completions for compatibility
2026-04-04 10:16:02 +01:00
- Sonar/OpenRouter compatibility returns one synthesized answer with citations, not structured result rows
2026-03-04 04:57:19 +00:00
- Results are cached for 15 minutes by default (configurable via `cacheTtlMinutes` )
2026-01-18 01:42:40 +00:00
See [Web tools ](/tools/web ) for the full web_search configuration.
2026-03-04 04:57:19 +00:00
See [Perplexity Search API docs ](https://docs.perplexity.ai/docs/search/quickstart ) for more details.