{"record":{"id":"e488411d4f21be30","repo":"danny-avila/LibreChat","slug":"missing-this-envvarapikey-or-this-envvarsearc","errorCode":null,"errorMessage":"Missing ${this.envVarApiKey} or ${this.envVarSearchEngineId} environment variable.","messagePattern":"Missing (.+?) or (.+?) environment variable\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/app/clients/tools/structured/GoogleSearch.js","lineNumber":42,"sourceCode":"    return 'google';\n  }\n\n  static get jsonSchema() {\n    return googleSearchJsonSchema;\n  }\n\n  constructor(fields = {}) {\n    super(fields);\n    this.name = 'google';\n    this.envVarApiKey = 'GOOGLE_SEARCH_API_KEY';\n    this.envVarSearchEngineId = 'GOOGLE_CSE_ID';\n    this.override = fields.override ?? false;\n    this.apiKey = fields[this.envVarApiKey] ?? getEnvironmentVariable(this.envVarApiKey);\n    this.searchEngineId =\n      fields[this.envVarSearchEngineId] ?? getEnvironmentVariable(this.envVarSearchEngineId);\n\n    if (!this.override && (!this.apiKey || !this.searchEngineId)) {\n      throw new Error(\n        `Missing ${this.envVarApiKey} or ${this.envVarSearchEngineId} environment variable.`,\n      );\n    }\n\n    this.kwargs = fields?.kwargs ?? {};\n    this.name = 'google';\n    this.description =\n      'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events.';\n\n    this.schema = googleSearchJsonSchema;\n  }\n\n  async _call(input) {\n    const { query, max_results = 5 } = input;\n\n    const response = await fetch(\n      `https://www.googleapis.com/customsearch/v1?key=${this.apiKey}&cx=${\n        this.searchEngineId","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/app/clients/tools/structured/GoogleSearch.js#L24-L60","documentation":"Constructor guard for the GoogleSearch (Google Custom Search) tool. It resolves apiKey from fields.GOOGLE_SEARCH_API_KEY or process.env.GOOGLE_SEARCH_API_KEY, and searchEngineId from fields.GOOGLE_CSE_ID or process.env.GOOGLE_CSE_ID. If either is falsy and override is false, construction throws.","triggerScenarios":"Instantiating GoogleSearchResults (e.g., during structured-tool loading) when at least one of GOOGLE_SEARCH_API_KEY / GOOGLE_CSE_ID is absent from both the fields argument and process.env, and `fields.override` is not true.","commonSituations":"Enabled the Google search tool without creating a Custom Search Engine and API key in Google Cloud Console; set GOOGLE_API_KEY (wrong name) instead of GOOGLE_SEARCH_API_KEY; copied .env.example but left the CSE ID blank; deploy missing the secret injection.","solutions":["Create a Programmable Search Engine at google.com/cse, grab its ID, set `GOOGLE_CSE_ID=<id>`.","Enable Custom Search API in Google Cloud and create an API key, then set `GOOGLE_SEARCH_API_KEY=<key>`.","Restart the API process so it picks up the new env vars.","For manifest-only loading, pass `override: true` to skip the check.","Double-check the exact variable names: GOOGLE_SEARCH_API_KEY and GOOGLE_CSE_ID (not GOOGLE_SEARCH_KEY or CSE_ID)."],"exampleFix":"// before\nconst t = new GoogleSearchResults({}); // throws\n\n// after\n// .env:\n//   GOOGLE_SEARCH_API_KEY=AIza...\n//   GOOGLE_CSE_ID=a1b2c3d4...\nconst t = new GoogleSearchResults({ override: true }); // or rely on env","handlingStrategy":"validation","validationCode":"function assertGoogleSearchConfig(fields = {}) {\n  const env = process.env;\n  const apiKey = fields.GOOGLE_SEARCH_API_KEY || env.GOOGLE_SEARCH_API_KEY;\n  const cseId = fields.GOOGLE_CSE_ID || env.GOOGLE_CSE_ID;\n  if (!fields.override && (!apiKey || !cseId)) {\n    throw new Error('GoogleSearch requires GOOGLE_SEARCH_API_KEY and GOOGLE_CSE_ID.');\n  }\n}","typeGuard":"function hasGoogleSearchConfig(fields) {\n  const env = process.env;\n  return Boolean(\n    (fields?.GOOGLE_SEARCH_API_KEY || env.GOOGLE_SEARCH_API_KEY) &&\n      (fields?.GOOGLE_CSE_ID || env.GOOGLE_CSE_ID),\n  );\n}","tryCatchPattern":null,"preventionTips":["Use exact names GOOGLE_SEARCH_API_KEY and GOOGLE_CSE_ID.","Validate both at startup.","Pass override:true when registering the tool only for the catalog."],"tags":["google-search","google-cse","config","environment-variables"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}