Get a Google Cloud API key

To use Gemini on Vertex AI, you need to authenticate by using a Google Cloud API key or by using application default credentials. We recommend using an API key for testing and using application default credentials for production. This page shows you how to get a Google Cloud API key based on whether or not you already have a Google Cloud account.

Select whether you have a Google Cloud account:


Create an express mode API key

If you don't have a Google Cloud account, the fastest way to get started is by registering for a Google Cloud express mode account and getting an express mode API key in the Google Cloud console. To learn more about Vertex AI in express mode, see the express mode overview page.

Get an express mode account and API key

Make your first API request

After getting an API key, learn how to use your API key to make your first request in the API quickstart.

Optional: Set up your API key locally

For initial testing, you can hard code an API key, but this should only be temporary since it is not secure. The rest of this section goes through how to set up your API key locally as an environment variable with different operating systems.

Click to expand instructions

Linux/macOS

  1. Run the following command to see which command-line shell you are using:

    echo $SHELL

    The output is similar to the following:

    /bin/bash
  2. Add a shell export variable for your API key, by doing one of the following:

    • If the output of the previous step is /bin/bash:

      1. Open .bashrc:

        touch ~/.bashrc
                open ~/.bashrc
      2. Add the following line to .bashrc:

        export GEMINI_API_KEY=YOUR_API_KEY
      3. Save the file, then run the following to apply the changes:

        source ~/.bashrc
    • If the output of the previous step is /bin/zsh:

      1. Open .zshrc:

        touch ~/.zshrc
                open ~/.zshrc
      2. Add the following line to .zshrc:

        export GEMINI_API_KEY= YOUR_API_KEY
      3. Save the file, then run the following to apply the changes:

        source ~/.zshrc

Windows

  1. Search for "Environment Variables" in the system settings
  2. Edit either "User variables" (for current user) or "System variables" (for all users - use with caution).
  3. Create the variable and add export GEMINI_API_KEY=YOUR_API_KEY
  4. Apply the changes