musistudio/claude-code-router · warning
[gateway] SerpAPI web search API key is not configured.
Error message
[gateway] SerpAPI web search API key is not configured.
What it means
The SerpAPI web search provider was selected, but SERPAPI_API_KEY is missing from the resolved environment. The provider returns empty results rather than failing the request.
Source
Thrown at packages/core/src/gateway/features/hosted-web-search/discovery.ts:612
return [];
}
const raw = await fetchJson(searchEnv(input, "SERPER_SEARCH_ENDPOINT") || "https://google.serper.dev/search", {
body: JSON.stringify({ num: input.count, q: input.query }),
headers: {
"content-type": "application/json",
"x-api-key": apiKey
},
method: "POST",
signal: AbortSignal.timeout(input.timeoutMs)
});
const items = isRecord(raw) && Array.isArray(raw.organic) ? raw.organic : [];
return items.map((item) => webSearchResult(item, "title", "link", "snippet")).filter(isWebSearchProviderResult);
}
async function searchSerpApi(input: WebSearchProviderInput): Promise<WebSearchProviderResult[]> {
const apiKey = searchEnv(input, "SERPAPI_API_KEY");
if (!apiKey) {
console.warn("[gateway] SerpAPI web search API key is not configured.");
return [];
}
const url = new URL(searchEnv(input, "SERPAPI_SEARCH_ENDPOINT") || "https://serpapi.com/search.json");
url.searchParams.set("api_key", apiKey);
url.searchParams.set("engine", "google");
url.searchParams.set("q", input.query);
url.searchParams.set("num", String(input.count));
const raw = await fetchJson(url.toString(), { signal: AbortSignal.timeout(input.timeoutMs) });
const items = isRecord(raw) && Array.isArray(raw.organic_results) ? raw.organic_results : [];
return items.map((item) => webSearchResult(item, "title", "link", "snippet")).filter(isWebSearchProviderResult);
}
async function searchTavily(input: WebSearchProviderInput): Promise<WebSearchProviderResult[]> {
const apiKey = searchEnv(input, "TAVILY_API_KEY");
if (!apiKey) {
console.warn("[gateway] Tavily web search API key is not configured.");
return [];
}View on GitHub (pinned to 99f24806c6)
Solutions
- Set SERPAPI_API_KEY in the gateway's runtime environment
- Verify with a quick curl 'https://serpapi.com/search.json?api_key=...&q=test' that the key works
- Restart the gateway process
Example fix
# before WEB_SEARCH_PROVIDER=serpapi # after SERPAPI_API_KEY=<serpapi-key> WEB_SEARCH_PROVIDER=serpapi
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.SERPAPI_API_KEY) throw new Error("SERPAPI_API_KEY required for serpapi provider"); Prevention
- Validate keys at startup
- Sync secrets into the service environment via deployment tooling
- Test one search after config changes
When it happens
Trigger: Configuring web search provider to "serpapi" without SERPAPI_API_KEY; key set only in a local .env not loaded in production.
Common situations: Signing up at serpapi.com but never exporting the key; containerized gateway missing the secret; key rotation leaving the env stale.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- [gateway] Brave web search API key is not configured.
- [gateway] Bing web search API key is not configured.
- [gateway] Google CSE web search API key or engine ID is not
- [gateway] Serper web search API key is not configured.
- [gateway] Tavily web search API key is not configured.
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/01697da2fcb0e8e2.
Report an issue: GitHub.