Skip to main content

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​

  1. Register the tools in search_tools as shown below, or in the Admin UI under Tools, Search Tools, + Add New Search Tool.

  2. 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.

  3. 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"}'
  4. 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.

MethodPathSummary
POST/v1/searchRun a web search through a search tool
POST/v1/search/{search_tool_name}Run a web search through a search tool
GET/v1/search/toolsList 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.

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.

Providersearch_providerCredentialsPage
Bravebraveapi_key or BRAVE_API_KEYBrave
DataForSEOdataforseoDATAFORSEO_LOGIN and DATAFORSEO_PASSWORDDataForSEO
DuckDuckGoduckduckgononeDuckDuckGo
Exaexa_aiapi_key or EXA_API_KEYExa
Firecrawlfirecrawlapi_key or FIRECRAWL_API_KEYFirecrawl
Google Programmable Searchgoogle_pseapi_key and GOOGLE_PSE_ENGINE_IDGoogle PSE
Linkuplinkupapi_key or LINKUP_API_KEYLinkup
Parallelparallel_aiapi_key or PARALLEL_AI_API_KEYParallel
SearXNGsearxngapi_base of your instanceSearXNG
Serperserperapi_key or SERPER_API_KEYSerper
Tavilytavilyapi_key or TAVILY_API_KEYTavily
Perplexityperplexityapi_key or PERPLEXITYAI_API_KEY, optional PERPLEXITY_API_BASEthis page
You.comyou_comapi_key or YOUCOM_API_KEY, optional YOUCOM_API_BASEthis page
SearchAPIsearchapiapi_key or SEARCHAPI_API_KEY, optional SEARCHAPI_API_BASEthis page
APIserpentapiserpentapi_key or APISERPENT_API_KEY, optional APISERPENT_API_BASEthis page
fastCRWfastcrwapi_key or CRW_API_KEY, optional CRW_API_BASEthis page
TinyFishtinyfishapi_key or TINYFISH_API_KEY, optional TINYFISH_API_BASEthis page
Nimblenimbleapi_key or NIMBLE_API_KEY, optional NIMBLE_API_BASEthis page
Amazon Bedrock AgentCoreagentcoreAGENTCORE_GATEWAY_URL, AGENTCORE_GATEWAY_TOKEN, AGENTCORE_SEARCH_TOOL_NAME, optional AGENTCORE_MCP_PROTOCOL_VERSIONthis page
Bing grounding on Azure AI Foundrybing_groundingBING_GROUNDING_PROJECT_ENDPOINT, BING_GROUNDING_CONNECTION_ID, BING_GROUNDING_MODEL, BING_GROUNDING_TOKENthis 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​

StatusType or messageMeaning 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.
400The search request body must be a JSON object, for example {"query": "..."}.The body is not JSON, or is a list. Send a JSON object.
403key_search_tool_access_denied, team_search_tool_access_denied, user_search_tool_access_deniedThe 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.
422A detail list naming a fieldThe body breaks the request shape, for example max_results outside 1 to 20 or no query. Fix the field named in loc.
500Search tool '<name>' not found ...The tool is not registered. Check GET /v1/search/tools.
500A provider messageThe provider refused the call, usually a wrong or expired credential. Fix it on the tool.

Logs​

LevelLineMeaningAction
WARNINGSearch tool <id> was not re-encrypted: its stored spanway_params did not match on writeA stored tool kept its old encryption during a master key rotation.Run the rotation again, see master key rotation.
WARNINGSearch 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.
ERRORSearch 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.