From f1647d9e19bf6930bc50bd2e66d2929f8f771503 Mon Sep 17 00:00:00 2001 From: Marat Boshernitsan Date: Tue, 8 Jul 2025 09:37:10 -0700 Subject: Improve auth env var validation logic and messaging to detect settings that confuse GenAI SDK (#1381) Co-authored-by: Scott Densmore Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- docs/cli/authentication.md | 6 +----- docs/cli/configuration.md | 7 +++---- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'docs/cli') diff --git a/docs/cli/authentication.md b/docs/cli/authentication.md index 3dddb897..f797e454 100644 --- a/docs/cli/authentication.md +++ b/docs/cli/authentication.md @@ -47,18 +47,16 @@ The Gemini CLI requires you to authenticate with Google's AI services. On initia gcloud auth application-default login ``` For more information, see [Set up Application Default Credentials for Google Cloud](https://cloud.google.com/docs/authentication/provide-credentials-adc). - - Set the `GOOGLE_CLOUD_PROJECT`, `GOOGLE_CLOUD_LOCATION`, and `GOOGLE_GENAI_USE_VERTEXAI` environment variables. In the following methods, replace `YOUR_PROJECT_ID` and `YOUR_PROJECT_LOCATION` with the relevant values for your project: + - Set the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` environment variables. In the following methods, replace `YOUR_PROJECT_ID` and `YOUR_PROJECT_LOCATION` with the relevant values for your project: - You can temporarily set these environment variables in your current shell session using the following commands: ```bash export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID" export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION" # e.g., us-central1 - export GOOGLE_GENAI_USE_VERTEXAI=true ``` - For repeated use, you can add the environment variables to your [.env file](#persisting-environment-variables-with-env-files) or your shell's configuration file (like `~/.bashrc`, `~/.zshrc`, or `~/.profile`). For example, the following commands add the environment variables to a `~/.bashrc` file: ```bash echo 'export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"' >> ~/.bashrc echo 'export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"' >> ~/.bashrc - echo 'export GOOGLE_GENAI_USE_VERTEXAI=true' >> ~/.bashrc source ~/.bashrc ``` - If using express mode: @@ -66,12 +64,10 @@ The Gemini CLI requires you to authenticate with Google's AI services. On initia - You can temporarily set these environment variables in your current shell session using the following commands: ```bash export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY" - export GOOGLE_GENAI_USE_VERTEXAI=true ``` - For repeated use, you can add the environment variables to your [.env file](#persisting-environment-variables-with-env-files) or your shell's configuration file (like `~/.bashrc`, `~/.zshrc`, or `~/.profile`). For example, the following commands add the environment variables to a `~/.bashrc` file: ```bash echo 'export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"' >> ~/.bashrc - echo 'export GOOGLE_GENAI_USE_VERTEXAI=true' >> ~/.bashrc source ~/.bashrc ``` 4. **Cloud Shell:** diff --git a/docs/cli/configuration.md b/docs/cli/configuration.md index 31931391..5f0514b0 100644 --- a/docs/cli/configuration.md +++ b/docs/cli/configuration.md @@ -242,12 +242,12 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - **`GOOGLE_API_KEY`**: - Your Google Cloud API key. - Required for using Vertex AI in express mode. - - Ensure you have the necessary permissions and set the `GOOGLE_GENAI_USE_VERTEXAI=true` environment variable. + - Ensure you have the necessary permissions. - Example: `export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"`. - **`GOOGLE_CLOUD_PROJECT`**: - Your Google Cloud Project ID. - Required for using Code Assist or Vertex AI. - - If using Vertex AI, ensure you have the necessary permissions and set the `GOOGLE_GENAI_USE_VERTEXAI=true` environment variable. + - If using Vertex AI, ensure you have the necessary permissions in this project. - **Cloud Shell Note:** When running in a Cloud Shell environment, this variable defaults to a special project allocated for Cloud Shell users. If you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud Shell, it will be overridden by this default. To use a different project in Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. - Example: `export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - **`GOOGLE_APPLICATION_CREDENTIALS`** (string): @@ -258,8 +258,7 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - Example: `export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - **`GOOGLE_CLOUD_LOCATION`**: - Your Google Cloud Project Location (e.g., us-central1). - - Required for using Vertex AI in non-express mode. - - If using Vertex AI, ensure you have the necessary permissions and set the `GOOGLE_GENAI_USE_VERTEXAI=true` environment variable. + - Required for using Vertex AI in non express mode. - Example: `export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"`. - **`GEMINI_SANDBOX`**: - Alternative to the `sandbox` setting in `settings.json`. -- cgit v1.2.3