{"record":{"id":"3a45592493654153","repo":"google-gemini/gemini-cli","slug":"please-set-an-auth-method-in-your-user-settings","errorCode":null,"errorMessage":"Please set an Auth method in your ${USER_SETTINGS_PATH} or specify one of the following environment variables before running: GEMINI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA","messagePattern":"Please set an Auth method in your (.+?) or specify one of the following environment variables before running: GEMINI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/validateNonInterActiveAuth.ts","lineNumber":39,"sourceCode":"  configuredAuthType: AuthType | undefined,\n  useExternalAuth: boolean | undefined,\n  nonInteractiveConfig: Config,\n  settings: LoadedSettings,\n) {\n  try {\n    const effectiveAuthType = configuredAuthType || getAuthTypeFromEnv();\n\n    const enforcedType = settings.merged.security.auth.enforcedType;\n    if (enforcedType && effectiveAuthType !== enforcedType) {\n      const message = effectiveAuthType\n        ? `The enforced authentication type is '${enforcedType}', but the current type is '${effectiveAuthType}'. Please re-authenticate with the correct type.`\n        : `The auth type '${enforcedType}' is enforced, but no authentication is configured.`;\n      throw new Error(message);\n    }\n\n    if (!effectiveAuthType) {\n      const message = `Please set an Auth method in your ${USER_SETTINGS_PATH} or specify one of the following environment variables before running: GEMINI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA`;\n      throw new Error(message);\n    }\n\n    const authType: AuthType = effectiveAuthType;\n\n    if (!useExternalAuth) {\n      const err = await validateAuthMethod(String(authType));\n      if (err != null) {\n        throw new Error(err);\n      }\n    }\n\n    return authType;\n  } catch (error) {\n    if (nonInteractiveConfig.getOutputFormat() === OutputFormat.JSON) {\n      handleError(\n        error instanceof Error ? error : new Error(String(error)),\n        nonInteractiveConfig,\n        ExitCodes.FATAL_AUTHENTICATION_ERROR,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/validateNonInterActiveAuth.ts#L21-L57","documentation":"Thrown when no `enforcedType` is set and the effective auth type resolves to a falsy value — i.e. the caller has not configured any authentication at all. The message names the user settings path and the three environment variables (`GEMINI_API_KEY`, `GOOGLE_GENAI_USE_VERTEXAI`, `GOOGLE_GENAI_USE_GCA`) that would resolve an auth type, giving the user a concrete checklist.","triggerScenarios":"First-time headless run with no prior OAuth login, no API key in env, and no auth type written to the user settings file. `configuredAuthType` is empty, `getAuthTypeFromEnv()` returns undefined, and `enforcedType` is unset so the earlier branch is skipped.","commonSituations":"Brand-new install where the user skipped interactive setup; env vars lost after a shell change; running in CI without provisioning a key; the settings file at `USER_SETTINGS_PATH` is empty or missing.","solutions":["Set one of the listed environment variables before invoking the CLI (quickest: `GEMINI_API_KEY`).","Run the CLI once interactively to choose and persist an auth method in the user settings file.","Manually edit the user settings file to add an `selectedAuthType` / auth block.","If running in CI, inject the chosen credential via the CI secret store as the matching env var."],"exampleFix":"# before\n$ gemini -p 'hi'  # no creds anywhere\n\n# after\n$ export GEMINI_API_KEY=AIza...\n$ gemini -p 'hi'","handlingStrategy":"validation","validationCode":"function assertAnyAuthConfigured(effectiveType: string | undefined) {\n  if (!effectiveType) {\n    throw new Error(\n      'No auth configured. Set GEMINI_API_KEY, run interactive login, or set an auth type in settings.',\n    );\n  }\n}\n\nassertAnyAuthConfigured(configuredAuthType ?? getAuthTypeFromEnv());","typeGuard":"function hasAnyAuth(env: NodeJS.ProcessEnv): boolean {\n  return Boolean(\n    env.GEMINI_API_KEY ||\n      env.GOOGLE_GENAI_USE_VERTEXAI ||\n      env.GOOGLE_GENAI_USE_GCA,\n  );\n}","tryCatchPattern":"try {\n  await validateNonInteractiveAuth(configuredAuthType, useExternalAuth, cfg, settings);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Please set an Auth method')) {\n    // open onboarding / set env, then retry\n  }\n  throw e;\n}","preventionTips":["Always set an auth env var in CI templates, even for smoke tests.","Run interactive login once on dev machines to seed the settings file.","Add a `gemini doctor` style preflight that checks auth state."],"tags":["auth","config","headless","onboarding"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}