A partire dal 29 aprile 2025, i modelli Gemini 1.5 Pro e Gemini 1.5 Flash non sono disponibili nei progetti che non li hanno mai utilizzati, inclusi i nuovi progetti. Per maggiori dettagli, vedi Versioni e ciclo di vita dei modelli.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Per utilizzare Gemini su Vertex AI, esegui l'autenticazione utilizzando una Google Cloud chiave API o le credenziali predefinite dell'applicazione. Ti consigliamo di utilizzare una chiave API per i test e le credenziali predefinite dell'applicazione per la produzione. Questa pagina
mostra come ottenere una chiave API Google Cloud in base al fatto che tu sia un utente Google Cloud
nuovo o esistente.
Seleziona se hai un Account Google con un progetto Google Cloud esistente:
Crea una chiave API Google Cloud
Se hai già un progetto Google Cloud , segui queste istruzioni per ottenere una chiave API Google Cloud standard. In alternativa, puoi utilizzare le credenziali predefinite
dell'applicazione anziché una chiave API.
Prima di iniziare
Seleziona un progetto, abilita la fatturazione e l'API Vertex AI
Autentica le chiamate API tramite un service account: selezionata.
Fai clic su Seleziona service account.
Seleziona il service account che hai creato nel passaggio precedente e fai clic su Seleziona.
Fai clic su Crea.
Effettua la tua prima richiesta API
Dopo aver ottenuto una chiave API, scopri come utilizzarla per effettuare la tua prima
richiesta nella guida rapida all'API.
(Facoltativo) Configura la chiave API in locale
Per i test iniziali, puoi codificare una chiave API, ma questa deve essere
temporanea perché non è sicura. Il resto di questa sezione spiega come
configurare la chiave API localmente come variabile di ambiente con sistemi
operativi diversi.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 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)."]]