{"record":{"id":"99f25c6235cffc06","repo":"musistudio/claude-code-router","slug":"gateway-brave-web-search-api-key-is-not-configur","errorCode":null,"errorMessage":"[gateway] Brave web search API key is not configured.","messagePattern":"\\[gateway\\] Brave web search API key is not configured\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/gateway/features/hosted-web-search/discovery.ts","lineNumber":541,"sourceCode":"    case \"bing\":\n      return searchBing(input);\n    case \"google_cse\":\n      return searchGoogleCse(input);\n    case \"serper\":\n      return searchSerper(input);\n    case \"serpapi\":\n      return searchSerpApi(input);\n    case \"tavily\":\n      return searchTavily(input);\n    case \"exa\":\n      return searchExa(input);\n  }\n}\n\nasync function searchBrave(input: WebSearchProviderInput): Promise<WebSearchProviderResult[]> {\n  const apiKey = searchEnv(input, \"BRAVE_SEARCH_API_KEY\");\n  if (!apiKey) {\n    console.warn(\"[gateway] Brave web search API key is not configured.\");\n    return [];\n  }\n  const url = new URL(searchEnv(input, \"BRAVE_SEARCH_ENDPOINT\") || \"https://api.search.brave.com/res/v1/web/search\");\n  url.searchParams.set(\"q\", input.query);\n  url.searchParams.set(\"count\", String(input.count));\n  const raw = await fetchJson(url.toString(), {\n    headers: { \"x-subscription-token\": apiKey },\n    signal: AbortSignal.timeout(input.timeoutMs)\n  });\n  const items = isRecord(raw) && isRecord(raw.web) && Array.isArray(raw.web.results) ? raw.web.results : [];\n  return items.map((item) => webSearchResult(item, \"title\", \"url\", \"description\")).filter(isWebSearchProviderResult);\n}\n\nasync function searchBing(input: WebSearchProviderInput): Promise<WebSearchProviderResult[]> {\n  const apiKey = searchEnv(input, \"BING_SEARCH_API_KEY\");\n  if (!apiKey) {\n    console.warn(\"[gateway] Bing web search API key is not configured.\");\n    return [];","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/gateway/features/hosted-web-search/discovery.ts#L523-L559","documentation":"The hosted web search feature selected the Brave provider, but no API key was found via the search environment resolution (BRAVE_SEARCH_API_KEY). The provider returns an empty result list rather than throwing, so searches silently yield nothing.","triggerScenarios":"Configuring web search provider to \"brave\" without setting BRAVE_SEARCH_API_KEY in the environment or provider-specific env config; the key being set in a different shell/process than the gateway runs in.","commonSituations":".env file not loaded by the gateway process; key set only in interactive shell but gateway runs as a service/container; renaming or removing the env var after a config change.","solutions":["Set BRAVE_SEARCH_API_KEY to a valid Brave Search API key in the environment the gateway runs in","If using a custom key name, configure the provider env mapping so searchEnv resolves it","Restart the gateway process after adding the key to .env or service environment"],"exampleFix":"# before\n# (no BRAVE_SEARCH_API_KEY set)\nWEB_SEARCH_PROVIDER=brave\n\n# after\nBRAVE_SEARCH_API_KEY=BSA...\nWEB_SEARCH_PROVIDER=brave","handlingStrategy":"validation","validationCode":"if (!process.env.BRAVE_SEARCH_API_KEY) {\n  throw new Error(\"BRAVE_SEARCH_API_KEY must be set before enabling the brave web search provider\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast at startup when a provider is configured but its key is missing","Centralize env validation in a config loader","Add integration tests that assert non-empty provider results"],"tags":["web-search","brave","env-var","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}