{"record":{"id":"26c9d40a80055c7d","repo":"thedotmack/claude-mem","slug":"auth-invalid-26c9d4","errorCode":"auth_invalid","errorMessage":"Gemini API key not configured","messagePattern":"Gemini API key not configured","errorType":"validation","errorClass":"ServerClassifiedProviderError","httpStatus":null,"severity":"error","filePath":"src/server/generation/providers/GeminiObservationProvider.ts","lineNumber":137,"sourceCode":"    });\n  }\n\n  return classifyHttpProviderError({\n    ...input,\n    providerLabel: 'Gemini',\n  });\n}\n\nexport class GeminiObservationProvider implements ServerGenerationProvider {\n  readonly providerLabel = 'gemini' as const;\n  private readonly apiKey: string;\n  private readonly model: string;\n  private readonly maxOutputTokens: number;\n  private readonly fetchImpl: typeof fetch;\n\n  constructor(options: GeminiObservationProviderOptions) {\n    if (!options.apiKey) {\n      throw new ServerClassifiedProviderError('Gemini API key not configured', {\n        kind: 'auth_invalid',\n        cause: new Error('apiKey is required'),\n      });\n    }\n    this.apiKey = options.apiKey;\n    this.model = options.model ?? DEFAULT_MODEL;\n    this.maxOutputTokens = options.maxOutputTokens ?? 4096;\n    this.fetchImpl = options.fetchImpl ?? fetch;\n  }\n\n  async generate(\n    context: ServerGenerationContext,\n    signal?: AbortSignal,\n  ): Promise<ServerGenerationResult> {\n    const { prompt, skippedAll } = buildServerGenerationPrompt(context);\n    if (skippedAll) {\n      return {\n        rawText: '<skip_summary reason=\"all_events_private\" />',","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/server/generation/providers/GeminiObservationProvider.ts#L119-L155","documentation":"The Gemini provider's constructor refuses to instantiate when `options.apiKey` is falsy. It throws a ServerClassifiedProviderError with kind 'auth_invalid' because requests without a key would fail Google's auth check anyway. This fails fast at construction time instead of at first request.","triggerScenarios":"Constructing `new GeminiObservationProvider({...})` with an options object whose `apiKey` property is undefined, null, or an empty string.","commonSituations":"Missing GEMINI_API_KEY / GOOGLE_API_KEY environment variable; reading the env var with the wrong name; a config loader returning undefined for an unset key; passing a variable that was never populated due to a typo in the key lookup.","solutions":["Set the Gemini API key env var (e.g. GEMINI_API_KEY) in the shell, .env file, or deployment secret store","Check the exact option/env name used where the provider is constructed — the value is likely undefined, not absent by design","Print the value's type (not its contents) to confirm it is a non-empty string before constructing the provider","Verify .env files are actually loaded in the runtime (dotenv config called before provider construction)"],"exampleFix":"// before\nconst provider = new GeminiObservationProvider({ apiKey: process.env.GEMINI_KEY });\n\n// after\nconst apiKey = process.env.GEMINI_API_KEY;\nif (!apiKey) throw new Error('GEMINI_API_KEY is not set');\nconst provider = new GeminiObservationProvider({ apiKey });","handlingStrategy":"validation","validationCode":"const apiKey = process.env.GEMINI_API_KEY;\nif (typeof apiKey !== 'string' || apiKey.length === 0) {\n  throw new Error('GEMINI_API_KEY must be a non-empty string');\n}\nconst provider = new GeminiObservationProvider({ apiKey });","typeGuard":"function hasApiKey(o: GeminiObservationProviderOptions): o is GeminiObservationProviderOptions & { apiKey: string } {\n  return typeof o.apiKey === 'string' && o.apiKey.length > 0;\n}","tryCatchPattern":"try {\n  provider = new GeminiObservationProvider({ apiKey });\n} catch (e) {\n  if (e instanceof ServerClassifiedProviderError && e.kind === 'auth_invalid') {\n    throw new ConfigError('Gemini provider misconfigured: apiKey missing. Set GEMINI_API_KEY.');\n  }\n  throw e;\n}","preventionTips":["Validate all required provider keys at application startup, before wiring providers","Use a typed config loader that asserts presence of required env vars","Never pass optional-chained values (config.x?.key) straight into provider constructors","Document required env vars in .env.example and CI"],"tags":["api-key","authentication","configuration","gemini"],"backgroundTag":"missing-api-key","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}