{"record":{"id":"87fbcbddea828fd2","repo":"musistudio/claude-code-router","slug":"gateway-google-cse-web-search-api-key-or-engine","errorCode":null,"errorMessage":"[gateway] Google CSE web search API key or engine ID is not configured.","messagePattern":"\\[gateway\\] Google CSE web search API key or engine ID is not configured\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/gateway/features/hosted-web-search/discovery.ts","lineNumber":577,"sourceCode":"    return [];\n  }\n  const url = new URL(searchEnv(input, \"BING_SEARCH_ENDPOINT\") || \"https://api.bing.microsoft.com/v7.0/search\");\n  url.searchParams.set(\"q\", input.query);\n  url.searchParams.set(\"count\", String(input.count));\n  url.searchParams.set(\"mkt\", \"en-US\");\n  const raw = await fetchJson(url.toString(), {\n    headers: { \"ocp-apim-subscription-key\": apiKey },\n    signal: AbortSignal.timeout(input.timeoutMs)\n  });\n  const items = isRecord(raw) && isRecord(raw.webPages) && Array.isArray(raw.webPages.value) ? raw.webPages.value : [];\n  return items.map((item) => webSearchResult(item, \"name\", \"url\", \"snippet\")).filter(isWebSearchProviderResult);\n}\n\nasync function searchGoogleCse(input: WebSearchProviderInput): Promise<WebSearchProviderResult[]> {\n  const apiKey = searchEnv(input, \"GOOGLE_SEARCH_API_KEY\");\n  const cx = searchEnv(input, \"GOOGLE_SEARCH_CX\");\n  if (!apiKey || !cx) {\n    console.warn(\"[gateway] Google CSE web search API key or engine ID is not configured.\");\n    return [];\n  }\n  const url = new URL(searchEnv(input, \"GOOGLE_SEARCH_ENDPOINT\") || \"https://www.googleapis.com/customsearch/v1\");\n  url.searchParams.set(\"key\", apiKey);\n  url.searchParams.set(\"cx\", cx);\n  url.searchParams.set(\"q\", input.query);\n  url.searchParams.set(\"num\", String(Math.min(input.count, 10)));\n  const raw = await fetchJson(url.toString(), { signal: AbortSignal.timeout(input.timeoutMs) });\n  const items = isRecord(raw) && Array.isArray(raw.items) ? raw.items : [];\n  return items.map((item) => webSearchResult(item, \"title\", \"link\", \"snippet\")).filter(isWebSearchProviderResult);\n}\n\nasync function searchSerper(input: WebSearchProviderInput): Promise<WebSearchProviderResult[]> {\n  const apiKey = searchEnv(input, \"SERPER_API_KEY\");\n  if (!apiKey) {\n    console.warn(\"[gateway] Serper web search API key is not configured.\");\n    return [];\n  }","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/gateway/features/hosted-web-search/discovery.ts#L559-L595","documentation":"The Google Custom Search Engine provider requires both an API key (GOOGLE_SEARCH_API_KEY) and an engine ID (GOOGLE_SEARCH_CX). Either or both are missing from the resolved environment, so the provider returns no results.","triggerScenarios":"Configuring web search provider to \"google\" while only setting GOOGLE_SEARCH_API_KEY and not GOOGLE_SEARCH_CX (or vice versa); misspelling either variable; the CSE not being created in the Google Cloud console so the cx value was never obtained.","commonSituations":"Devs obtain an API key but forget they must also create a Custom Search Engine and copy its cx ID; env vars set in a different environment; using the Google Search API (deprecated) variable names instead of CSE ones.","solutions":["Create a Programmable Search Engine at programmablesearchengine.google.com and copy its cx ID","Set both GOOGLE_SEARCH_API_KEY and GOOGLE_SEARCH_CX in the gateway environment","Enable the Custom Search API on the key's GCP project and restart the gateway"],"exampleFix":"# before\nGOOGLE_SEARCH_API_KEY=AIza...\n\n# after\nGOOGLE_SEARCH_API_KEY=AIza...\nGOOGLE_SEARCH_CX=0123456789abcdef:xyz\nWEB_SEARCH_PROVIDER=google","handlingStrategy":"validation","validationCode":"const missing = [\"GOOGLE_SEARCH_API_KEY\", \"GOOGLE_SEARCH_CX\"].filter((k) => !process.env[k]);\nif (missing.length) throw new Error(`Google CSE requires: ${missing.join(\", \")}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember Google CSE needs key AND cx — check both","Create the Programmable Search Engine before enabling the provider","Add startup validation of provider env pairs"],"tags":["web-search","google-cse","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"}