Skip to main content

What is Gemini CLI?

The Gemini command line interface (CLI) is Google’s official AI coding assistant that runs directly in your terminal. It understands your codebase and helps you code faster through natural language commands.

Prerequisites

Before integrating Gemini CLI with TrueFoundry, ensure you have:
  1. TrueFoundry Account: A TrueFoundry account with at least one Google Gemini or Vertex AI Provider Account configured and a Personal Access Token (Generate here)
  2. Gemini CLI Installation: Install Gemini CLI by running:
    npm install -g @google/gemini-cli
    

Setup Configuration

1. Create Provider Account

Create a provider account for either Google Gemini or Vertex AI:
Provider Support: Both Google Gemini and Vertex AI providers are supported. The gateway automatically handles the necessary transformations for Vertex AI when using the Gemini CLI.

2. Get Configuration Details

Get the base URL and Provider Name from your TrueFoundry AI Gateway playground using the unified code snippet: Screenshot2025 09 24at7 39 04PM Pn

3. Configure Environment Variables

Choose the configuration that matches your provider. Google Gemini and Vertex AI use different environment variables and auth mechanisms.
export GOOGLE_GEMINI_BASE_URL="https://{controlPlaneURL}/gemini/{providerAccountName}/proxy"
export GEMINI_API_KEY="your-truefoundry-api-key"
export GOOGLE_VERTEX_BASE_URL="https://{controlPlaneURL}/gemini/{providerAccountName}/proxy"
export GOOGLE_API_KEY="your-truefoundry-api-key"
export GEMINI_API_KEY_AUTH_MECHANISM="bearer"
Replace the placeholders:
PlaceholderDescription
controlPlaneURLYour TrueFoundry Control Plane URL
providerAccountNameYour Provider Account name (either Google Gemini or Vertex AI)
your-truefoundry-api-keyYour TrueFoundry Personal Access Token
Vertex AI users: You must use the Vertex AI configuration above (with GOOGLE_VERTEX_BASE_URL, GOOGLE_API_KEY, and GEMINI_API_KEY_AUTH_MECHANISM="bearer"). The older Gemini-style config is no longer supported for Vertex AI with Gemini CLI due to upstream changes affecting models such as gemini-3.1-pro. If you were previously using Vertex AI with the Gemini config, see Migrating from Gemini config to Vertex AI config below.

Migrating from Gemini config to Vertex AI config

If you were using Vertex AI with the previous Gemini-style configuration (GOOGLE_GEMINI_BASE_URL + GEMINI_API_KEY), you need to switch to the Vertex AI–specific configuration. Gemini CLI has made changes that make Vertex AI Gemini models (when used via Gemini CLI in gemini mode) unusable for gemini-3.1-pro unless you use the new Vertex AI config and auth type.
Action required for Vertex AI users: Migrate to the new Vertex AI configuration and re-select Vertex AI as the auth type in Gemini CLI. Until you do, Vertex AI models such as gemini-3.1-pro may not work correctly with Gemini CLI.
Follow one of the migration options below.

Option 1: Reset auth via CLI (/auth and logout)

  1. Set the Vertex AI environment variables (see the Vertex AI accordion above) in your shell profile or environment.
  2. Start the CLI with gemini, then run the /auth command.
  3. Use the logout option in the auth flow to clear the current auth type.
  4. When prompted, select Vertex AI as the auth type.

Option 2: Reset auth via settings file

  1. Open the Gemini CLI settings file (e.g. ~/.gemini/settings.json .
  2. Delete the selectedType field from the auth object so that the CLI no longer uses the old auth selection.
  3. Set the Vertex AI environment variables (see the Vertex AI accordion above) in your shell profile or environment.
  4. Start the CLI with gemini. When prompted for authentication, choose Vertex AI.
After removing selectedType, the next time you run gemini you will be asked to pick an auth type again. Select Vertex AI to use the new configuration.

Using Gemini CLI

  1. Start the CLI:
    gemini
    
  2. Setup Authentication:
    • Google Gemini users: If you see authentication options, choose Use Gemini API Key. If not prompted, type /auth and select Use Gemini API Key.
    • Vertex AI users: Choose Vertex AI (or the Vertex AI auth type). If not prompted, type /auth and select Vertex AI. Ensure you have set the Vertex AI environment variables (see the Vertex AI accordion above) before starting.
Screenshot2025 09 24at7 46 24PM Pn
  1. Start using Gemini:
    # Ask about your code
    > Explain this function
    
    # Get code suggestions
    > Write a function to validate email addresses
    
    # Debug issues
    > Why is this giving me a syntax error?
    
You can now use Gemini CLI with all requests going through your TrueFoundry AI Gateway.