Search
The gateway has a unified search API. You register search tools, each backed by a search provider such as Tavily, Brave, Exa, Serper, Linkup, Parallel, Firecrawl, DataForSEO, Google Programmable Search, SearXNG or DuckDuckGo, and applications and agents call one endpoint with one request format. The provider credential stays on the gateway, access to each tool is controlled per key and team, and every query is logged and costed.
A real-world scenario
A company gives three internal agents web search, but only the research team's agent may use the paid search provider while the others use a self-hosted SearXNG. The admin registers both tools, turns on deny by default, and grants each team only its tool, so a support agent that asks for the paid tool is refused.
Steps
-
Register the tools in
search_toolsas shown below, or in the Admin UI under Tools, Search Tools, + Add New Search Tool. -
Set
general_settings.search_tool_deny_by_default: true, then grant the tool to the team and to the team's key. Under deny by default a virtual key needs the tool on the key and on its team, so a grant on the team alone is not enough.curl -X POST http://localhost:4000/team/update \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"team_id": "research", "object_permission": {"search_tools": ["web-search"]}}'curl -X POST http://localhost:4000/key/update \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"key": "'"$RESEARCH_KEY"'", "object_permission": {"search_tools": ["web-search"]}}'In the Admin UI, open the team in Teams and the key in Virtual Keys, and add the tool under Allowed Search Tools in each one's settings.
-
List what the research key may use, then run a search with it.
curl http://localhost:4000/v1/search/tools -H "Authorization: Bearer $RESEARCH_KEY"curl -X POST http://localhost:4000/v1/search/web-search \-H "Authorization: Bearer $RESEARCH_KEY" -H "Content-Type: application/json" -d '{"query": "AI gateway release notes"}' -
Open Logs in the Admin UI to see the query and its cost.
Expected result
The research key lists web-search and gets results. A key of another team does not see web-search in its list, and calling it answers 403 with key_search_tool_access_denied, because the gateway checks the key's own grant first. A key that has the grant while its team does not gets team_search_tool_access_denied.
Registering search tools
search_tools:
- search_tool_name: web-search
spanway_params:
search_provider: tavily
api_key: os.environ/TAVILY_API_KEY
- search_tool_name: internal-search
spanway_params:
search_provider: searxng
api_base: https://searxng.internal.example.com
Each entry has a public search_tool_name and spanway_params with search_provider plus api_key, api_base, timeout and max_retries. Tools can also be added from the Search tools page of the Admin UI. search_tool_name may only use letters, numbers, hyphens and underscores, because keys call it as /v1/search/<search_tool_name>, and search_provider must be one of the providers in the table below.
Running a search
| Method | Path | Summary |
|---|---|---|
| POST | /v1/search | Run a web search through a search tool |
| POST | /v1/search/{search_tool_name} | Run a web search through a search tool |
| GET | /v1/search/tools | List the search tools the key may use |
curl -X POST http://localhost:4000/v1/search/web-search \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "latest AI gateway release notes", "max_results": 5, "search_domain_filter": ["arxiv.org"], "country": "US"}'
The request follows the Perplexity Search API shape. query is a string or a list of strings, max_results is 1 to 20, search_domain_filter limits domains, max_tokens_per_page caps page content, and country filters by country code. The tool name can also be sent in the body as search_tool_name instead of in the path. The response has results, each with title, url, snippet and, when the provider returns them, date and last_updated. GET /v1/search/tools lists the tools the calling key may use, applying the same key, team and user grants as the search route, so under deny by default a key never sees a tool it was not granted. A body that breaks this shape, such as max_results of 0 or 25, is refused with 422 before any provider is called.
Access control
object_permission.search_tools on keys, teams and users grants tools. Without deny by default, a non-empty list on the key or team narrows what it may call and an empty list allows every tool. With general_settings.search_tool_deny_by_default: true (off by default), a tool must be granted before it can be called: a virtual key needs the tool on the key and on its team, a team member without a key needs it on the team, and a user with neither needs it on the user. The unregistered search fallback is denied, and the master key and dashboard sessions are exempt. Turn it on to stop keys from running paid searches nobody approved. See access control.
Search for models without native web search
Web search interception lets any model use a registered search tool: the gateway intercepts the model's search tool call, runs it, and feeds the results back.
Cost
Each query is costed from the provider's per-query price in the bundled price map, and listed in the spend logs with the tool name. Provider details and prices are on the pages below.
| Provider | search_provider | Credentials | Page |
|---|---|---|---|
| Brave | brave | api_key or BRAVE_API_KEY | Brave |
| DataForSEO | dataforseo | DATAFORSEO_LOGIN and DATAFORSEO_PASSWORD | DataForSEO |
| DuckDuckGo | duckduckgo | none | DuckDuckGo |
| Exa | exa_ai | api_key or EXA_API_KEY | Exa |
| Firecrawl | firecrawl | api_key or FIRECRAWL_API_KEY | Firecrawl |
| Google Programmable Search | google_pse | api_key and GOOGLE_PSE_ENGINE_ID | Google PSE |
| Linkup | linkup | api_key or LINKUP_API_KEY | Linkup |
| Parallel | parallel_ai | api_key or PARALLEL_AI_API_KEY | Parallel |
| SearXNG | searxng | api_base of your instance | SearXNG |
| Serper | serper | api_key or SERPER_API_KEY | Serper |
| Tavily | tavily | api_key or TAVILY_API_KEY | Tavily |
| Perplexity | perplexity | api_key or PERPLEXITYAI_API_KEY, optional PERPLEXITY_API_BASE | this page |
| You.com | you_com | api_key or YOUCOM_API_KEY, optional YOUCOM_API_BASE | this page |
| SearchAPI | searchapi | api_key or SEARCHAPI_API_KEY, optional SEARCHAPI_API_BASE | this page |
| APIserpent | apiserpent | api_key or APISERPENT_API_KEY, optional APISERPENT_API_BASE | this page |
| fastCRW | fastcrw | api_key or CRW_API_KEY, optional CRW_API_BASE | this page |
| TinyFish | tinyfish | api_key or TINYFISH_API_KEY, optional TINYFISH_API_BASE | this page |
| Nimble | nimble | api_key or NIMBLE_API_KEY, optional NIMBLE_API_BASE | this page |
| Amazon Bedrock AgentCore | agentcore | AGENTCORE_GATEWAY_URL, AGENTCORE_GATEWAY_TOKEN, AGENTCORE_SEARCH_TOOL_NAME, optional AGENTCORE_MCP_PROTOCOL_VERSION | this page |
| Bing grounding on Azure AI Foundry | bing_grounding | BING_GROUNDING_PROJECT_ENDPOINT, BING_GROUNDING_CONNECTION_ID, BING_GROUNDING_MODEL, BING_GROUNDING_TOKEN | this page |
The providers marked "this page" have no page of their own yet. Register them like the others, with the values above in spanway_params or in the gateway environment.
Errors
| Status | Type or message | Meaning and fix |
|---|---|---|
| 400 | /search: Missing required parameter: 'search_tool_name'. | The request named no tool and the gateway has no default model. Send the tool in the path, /v1/search/<name>, or as search_tool_name in the body. |
| 400 | The search request body must be a JSON object, for example {"query": "..."}. | The body is not JSON, or is a list. Send a JSON object. |
| 403 | key_search_tool_access_denied, team_search_tool_access_denied, user_search_tool_access_denied | The key, its team or its user has no grant for the tool, checked in that order. Grant it with object_permission.search_tools on each layer that needs it, see access control. |
| 422 | A detail list naming a field | The body breaks the request shape, for example max_results outside 1 to 20 or no query. Fix the field named in loc. |
| 500 | Search tool '<name>' not found ... | The tool is not registered. Check GET /v1/search/tools. |
| 500 | A provider message | The provider refused the call, usually a wrong or expired credential. Fix it on the tool. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| WARNING | Search tool <id> was not re-encrypted: its stored spanway_params did not match on write | A stored tool kept its old encryption during a master key rotation. | Run the rotation again, see master key rotation. |
| WARNING | Search tool <name> has spanway_params that do not decrypt with the current key; keeping the loaded version. Restart the proxy if the master key was rotated. | The stored provider key cannot be read with the current master key, so the gateway keeps the copy it already loaded. | Restart the gateway after a master key change, or enter the provider key again on the Search Tools page. |
| ERROR | Search tool router refresh failed after a management write: <error> | A tool was saved but this gateway did not pick it up yet. The next config reload does. | None unless it repeats, then check the database. |
Related
- Search Tools page for the Admin UI.
- Web search interception for models without native web search.
- Error reference.