Get a Google Cloud API key

To use Gemini on Vertex AI, authenticate by using a Google Cloud API key or 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 you're a new or existing Google Cloud user.

Select your user type:


Create an express mode API key

The fastest way to get an API key is through an express mode account in the Google Cloud console. This streamlined experience is designed for rapid onboarding, creating an API key for you automatically, regardless of whether you are new to Google Cloud or are an existing Google Cloud user:

  • If you are new to Google Cloud, you are guided through a quick, no-cost setup that provides a free 90-day trial environment.
  • If you are an existing Google Cloud user, you can link your existing billing account to get an API key immediately within the simplified experience of Vertex AI in express mode.

To learn more about Vertex AI in express mode, see the express mode overview page.

Get an API key with express mode:

Get an API key with express mode

To view and manage your API keys, open APIs & Services > Credentials:

Go to Credentials

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 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 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 API_KEY=YOUR_API_KEY
  4. Apply the changes