A partir de 29 de abril de 2025, os modelos Gemini 1.5 Pro e Gemini 1.5 Flash não estarão disponíveis em projetos que não os usaram antes, incluindo novos projetos. Para mais detalhes, consulte Versões e ciclo de vida do modelo.
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Para usar o Gemini na Vertex AI, faça a autenticação usando
uma chave de APIGoogle Cloud ou credenciais
padrão de aplicativo. Recomendamos usar uma chave de API para testes e credenciais padrão do aplicativo para produção. Nesta página, mostramos como conseguir uma chave de API Google Cloud dependendo se você é um usuário Google Cloud novo ou atual.
Selecione se você tem uma Conta do Google com um projeto Google Cloud :
Criar uma chave de API do Google Cloud
Se você já tiver um projeto Google Cloud , siga estas instruções para
receber uma chave de API Google Cloud padrão. Como alternativa, use as credenciais padrão do aplicativo em vez de uma chave de API.
Antes de começar
Selecionar um projeto, ativar o faturamento e a API Vertex AI
Autenticar chamadas de API por uma conta de serviço: selecionada.
Clique em Selecionar conta de serviço.
Selecione a conta de serviço que você criou na etapa anterior e clique em Selecionar.
Clique em Criar.
Fazer sua primeira solicitação de API
Depois de receber uma chave de API, saiba como usá-la para fazer sua primeira
solicitação no guia de início rápido da API.
Opcional: configurar a chave de API localmente
Para testes iniciais, você pode codificar uma chave de API, mas isso só deve ser
temporário, já que não é seguro. O restante desta seção mostra como
configurar a chave de API localmente como uma variável de ambiente com diferentes sistemas
operacionais.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)."]]