{"record":{"id":"f19054c27f62deaa","repo":"ruvnet/ruflo","slug":"authentication-f19054","errorCode":"AUTHENTICATION","errorMessage":"Google API key is required","messagePattern":"Google API key is required","errorType":"exception","errorClass":"AuthenticationError","httpStatus":401,"severity":"error","filePath":"v3/@claude-flow/providers/src/google-provider.ts","lineNumber":129,"sourceCode":"        currency: 'USD',\n      },\n      'gemini-pro': {\n        promptCostPer1k: 0.0005,\n        completionCostPer1k: 0.0015,\n        currency: 'USD',\n      },\n    },\n  };\n\n  private baseUrl: string = 'https://generativelanguage.googleapis.com/v1beta';\n\n  constructor(options: BaseProviderOptions) {\n    super(options);\n  }\n\n  protected async doInitialize(): Promise<void> {\n    if (!this.config.apiKey) {\n      throw new AuthenticationError('Google API key is required', 'google');\n    }\n\n    this.baseUrl = this.config.apiUrl || 'https://generativelanguage.googleapis.com/v1beta';\n  }\n\n  protected async doComplete(request: LLMRequest): Promise<LLMResponse> {\n    const geminiRequest = this.buildRequest(request);\n    const model = request.model || this.config.model;\n    const url = `${this.baseUrl}/models/${model}:generateContent?key=${this.config.apiKey}`;\n\n    const controller = new AbortController();\n    const timeout = setTimeout(() => controller.abort(), this.config.timeout || 60000);\n\n    try {\n      const response = await fetch(url, {\n        method: 'POST',\n        headers: { 'Content-Type': 'application/json' },\n        body: JSON.stringify(geminiRequest),","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/providers/src/google-provider.ts#L111-L147","documentation":"GoogleProvider.doInitialize() runs during provider.initialize(); if config.apiKey is falsy it throws AuthenticationError before any HTTP call. The key is appended as ?key=... on every request to https://generativelanguage.googleapis.com/v1beta (or config.apiUrl).","triggerScenarios":"new GoogleProvider({ name: 'google', config: { model: 'gemini-2.0-flash' } }) with no apiKey, or apiKey: process.env.GOOGLE_API_KEY when the variable is unset.","commonSituations":"GOOGLE_API_KEY (or GEMINI_API_KEY) not exported in CI/containers; .env not loaded; a Vertex AI service-account setup assumed where this provider requires an AI Studio API key instead.","solutions":["Create a key in Google AI Studio and pass it: config: { apiKey: process.env.GOOGLE_API_KEY, model: 'gemini-2.0-flash' }","Export the env var in the runtime environment and verify with printenv GOOGLE_API_KEY","Add a startup validator for required env vars so the failure is explicit and early"],"exampleFix":"// before\nconst provider = new GoogleProvider({\n  name: 'google',\n  config: { model: 'gemini-2.0-flash' }, // no apiKey -> AuthenticationError at initialize()\n});\n\n// after\nconst provider = new GoogleProvider({\n  name: 'google',\n  config: { apiKey: process.env.GOOGLE_API_KEY!, model: 'gemini-2.0-flash' },\n});","handlingStrategy":"validation","validationCode":"const apiKey = process.env.GOOGLE_API_KEY;\nif (!apiKey) {\n  throw new Error('GOOGLE_API_KEY is not set - cannot create google provider');\n}\nconst provider = new GoogleProvider({ name: 'google', config: { apiKey, model: 'gemini-2.0-flash' } });","typeGuard":"import { AuthenticationError } from './types.js';\nfunction isAuthError(e: unknown): e is AuthenticationError {\n  return e instanceof AuthenticationError;\n}","tryCatchPattern":"try {\n  await provider.initialize();\n} catch (e) {\n  if (e instanceof AuthenticationError) {\n    throw new Error(`google credentials missing or invalid: ${e.message}`); // fail fast, no retry\n  }\n  throw e;\n}","preventionTips":["Assert GOOGLE_API_KEY at startup before constructing providers","Remember this provider needs an AI Studio API key, not a Vertex service account","Centralize required-env-var checks in a config validator shared by all providers"],"tags":["authentication","config","env-var","google","gemini","initialization"],"backgroundTag":"missing-api-key","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}