thedotmack/claude-mem · error · ServerClassifiedProviderError

auth_invalid

auth_invalid

Error message

Gemini API key not configured

What it means

Thrown by the GeminiObservationProvider constructor when options.apiKey is falsy. It is a ServerClassifiedProviderError with kind 'auth_invalid', meaning the Gemini generation provider cannot authenticate. Auth is validated at construction time so the failure is surfaced before any request is attempted.

Source

Thrown at src/server/generation/providers/GeminiObservationProvider.ts:137

    });
  }

  return classifyHttpProviderError({
    ...input,
    providerLabel: 'Gemini',
  });
}

export class GeminiObservationProvider implements ServerGenerationProvider {
  readonly providerLabel = 'gemini' as const;
  private readonly apiKey: string;
  private readonly model: string;
  private readonly maxOutputTokens: number;
  private readonly fetchImpl: typeof fetch;

  constructor(options: GeminiObservationProviderOptions) {
    if (!options.apiKey) {
      throw new ServerClassifiedProviderError('Gemini API key not configured', {
        kind: 'auth_invalid',
        cause: new Error('apiKey is required'),
      });
    }
    this.apiKey = options.apiKey;
    this.model = options.model ?? DEFAULT_MODEL;
    this.maxOutputTokens = options.maxOutputTokens ?? 4096;
    this.fetchImpl = options.fetchImpl ?? fetch;
  }

  async generate(
    context: ServerGenerationContext,
    signal?: AbortSignal,
  ): Promise<ServerGenerationResult> {
    const { prompt, skippedAll } = buildServerGenerationPrompt(context);
    if (skippedAll) {
      return {
        rawText: '<skip_summary reason="all_events_private" />',

View on GitHub (pinned to d768ba3643)

Solutions

  1. Set GEMINI_API_KEY (or the configured setting) to a valid key from Google AI Studio before launch.
  2. Switch to a different provider if Gemini was selected by mistake, supplying that provider's key.
  3. Confirm the settings/env layer resolves the key (check length, never the value).
  4. Re-run after fixing config.

Example fix

// before: no key supplied
new GeminiObservationProvider({ /* apiKey omitted */ });
// after
new GeminiObservationProvider({ apiKey: process.env.GEMINI_API_KEY });
// plus: export GEMINI_API_KEY=AIza... before launch
Defensive patterns

Strategy: validation

Validate before calling

function resolveGeminiKey(): string {
  const key = process.env.GEMINI_API_KEY ?? readSetting('geminiApiKey');
  if (!key || !key.trim()) {
    throw new Error('GEMINI_API_KEY is not set; cannot use the gemini provider');
  }
  return key.trim();
}

Type guard

function hasApiKey(opts: unknown): opts is { apiKey: string } {
  return typeof (opts as { apiKey?: unknown })?.apiKey === 'string'
    && (opts as { apiKey: string }).apiKey.trim().length > 0;
}

Try / catch

try {
  provider = new GeminiObservationProvider({ apiKey });
} catch (error) {
  if (error instanceof ServerClassifiedProviderError && error.kind === 'auth_invalid') {
    // pick a different configured provider or exit with guidance
  } else throw error;
}

Prevention

When it happens

Trigger: Instantiating GeminiObservationProvider with an empty/undefined apiKey; the configured provider is 'gemini' but GEMINI_API_KEY (or the equivalent setting) is unset; the settings layer resolved the key to an empty string.

Common situations: Operator selects the gemini provider but never exports the Gemini key. A .env file isn't loaded. The key was revoked in Google AI Studio. Local-dev bypass hides the gap until provider construction.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12). Data as JSON: /api/errors/26c9d40a80055c7d. Report an issue: GitHub.