Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
Stay organized with collections
Save and categorize content based on your preferences.
To use Gemini on Vertex AI, 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 you're a
new or existing Google Cloud user.
Select if you have a Google Account with an existing Google Cloud project:
Create a Google Cloud API key
If you already have a Google Cloud project, use the following instructions to
get a standard Google Cloud API key. Alternatively, you can use application
default credentials instead of using an API key.
Before you begin
Select a project, enable billing, enable the Vertex AI API
Authenticate API calls through a service account: Selected.
Click Select service account.
Select the service account you created in the previous step and click Select.
Click Create.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Get a Google Cloud API key\n\nTo use Gemini on Vertex AI, authenticate by using\na **Google Cloud API key** or by using **[application default\ncredentials](/vertex-ai/generative-ai/docs/start/gcp-auth)**. We recommend using an API key for\ntesting and using application default credentials for production. This page\nshows you how to get a Google Cloud API key based on whether you're a\nnew or existing Google Cloud user.\n\nSelect if you have a Google Account with an existing Google Cloud project: \nI'm a new user to Google Cloud I already have a Google Cloud project\n\n*** ** * ** ***\n\nCreate a Google Cloud API key\n-----------------------------\n\nIf you already have a Google Cloud project, use the following instructions to\nget a standard Google Cloud API key. Alternatively, you can use [application\ndefault credentials](/vertex-ai/generative-ai/docs/start/gcp-auth) instead of using an API key.\n\nBefore you begin\n----------------\n\n#### Select a project, enable billing, enable the Vertex AI API\n\n- [Sign in](https://accounts.google.com/Login) to your Google Account.\n\n If you don't already have one, [sign up for a new account](https://accounts.google.com/SignUp).\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Vertex AI API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Vertex AI API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com)\n\nEnable service account API key creation\n---------------------------------------\n\n| **Important:** To perform this step, your user account must have the [Organization Policy Administrator](/resource-manager/docs/access-control-org#orgpolicy.policyAdmin) role enabled for your organization. If you don't have this role or can't make this configuration, use [application default credentials](/vertex-ai/generative-ai/docs/start/gcp-auth) instead.\n\n1. Open [**IAM \\& Admin \\\u003e Organization\n policies**](https://console.cloud.google.com/iam-admin/orgpolicies/list).\n2. In the list of policies, filter for policies called **iam.managed.disableServiceAccountApiKeyCreation**.\n3. Click **Actions \\\u003e Edit policy**.\n4. Under **Policy source** , select **Override parent's policy** , then click **Add a rule**.\n5. Under **Enforcement** , select **Off**.\n6. Click **Done**.\n7. Click **Set policy** . In the dialog that pops up, click **Set policy** again.\n\nCreate a new service account\n----------------------------\n\n1. Open [**IAM \\& Admin \\\u003e Service\n Accounts**](https://console.cloud.google.com/iam-admin/serviceaccounts).\n2. Click **Create service account**.\n3. Configure the service account as follows:\n - **Service account name** : `vertex-ai-runner`\n - **Service account ID** : `vertexairunner`\n4. Click **Create and continue**.\n5. Under **Permissions** , click **Select a role** and select **Vertex AI Platform Express User** from the menu.\n6. Click **Continue**.\n7. Click **Done**.\n\nCreate an API key\n-----------------\n\n1. Open [**APIs \\& Services \\\u003e\n Credentials**](https://console.cloud.google.com/apis/credentials).\n2. Click **Create credentials \\\u003e API key**.\n3. Configure the API key as follows:\n - **Name** : `vertexaiapikey`\n - **Authenticate API calls through a service account**: Selected.\n4. Click **Select service account**.\n5. Select the service account you created in [the previous step](#create-a-new-service-account) and click **Select**.\n6. Click **Create**.\n\nMake your first API request\n---------------------------\n\nAfter getting an API key, learn how to use your API key to make your first\nrequest in the [API quickstart](/vertex-ai/generative-ai/docs/start/quickstart?usertype=apikey#rest_1).\n\nOptional: Set up your API key locally\n-------------------------------------\n\nFor initial testing, you can hard code an API key, but this should only be\ntemporary since it is not secure. The rest of this section goes through how to\nset up your API key locally as an environment variable with different operating\nsystems. \n\n#### Click to expand instructions\n\n### Linux/macOS\n\n1. Run the following command to see which command-line shell you are\n using:\n\n ```\n echo $SHELL\n ```\n\n The output is similar to the following: \n\n ```\n /bin/bash\n ```\n2. Add a shell export variable for your API key, by doing one of the\n following:\n\n - If the output of the previous step is `/bin/bash`:\n\n 1. Open `.bashrc`:\n\n ```\n touch ~/.bashrc\n open ~/.bashrc\n ```\n 2. Add the following line to `.bashrc`:\n\n ```\n export GEMINI_API_KEY=YOUR_API_KEY\n ```\n 3. Save the file, then run the following to apply the changes:\n\n ```\n source ~/.bashrc\n ```\n - If the output of the previous step is `/bin/zsh`:\n\n 1. Open `.zshrc`:\n\n ```\n touch ~/.zshrc\n open ~/.zshrc\n ```\n 2. Add the following line to `.zshrc`:\n\n ```\n export GEMINI_API_KEY= YOUR_API_KEY\n ```\n 3. Save the file, then run the following to apply the changes:\n\n ```\n source ~/.zshrc\n ```\n\n### Windows\n\n1. Search for \"Environment Variables\" in the system settings\n2. Edit either \"User variables\" (for current user) or \"System variables\" (for all users - use with caution).\n3. Create the variable and add `export GEMINI_API_KEY=`\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\n4. Apply the changes\n\n*** ** * ** ***\n\n| **WARNING:** It's important to keep your API key secure. Here are a few things to keep in mind when using your API key:\n|\n| - Google Cloud recommends [application default credentials](/vertex-ai/generative-ai/docs/start/gcp-auth) as a production-safe way to authenticate your application\n| - Vertex AI uses API keys for authorization. If others get access to your API key, they can make calls using your project's quota, which could result in lost quota or additional charges for billed projects, in addition to accessing tuned models and files.\n| - Adding [API key restrictions](/api-keys/docs/add-restrictions-api-keys#add-api-restrictions) can help limit the surface area usable through each API key.\n| - You're responsible for keeping your API key secure.\n| - Do **not** check API keys into source control.\n| - Client-side applications (Android, Swift, web, and Dart/Flutter) risk exposing API keys. We don't recommend using the Google AI client SDKs in production apps to call the API directly from your mobile and web apps.\n|\n| For some general best practices, you can also review this\n| [support article](https://support.google.com/googleapi/answer/6310037)."]]