Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Para usar Gemini en Vertex AI, autentícate con una clave de la API o con credenciales predeterminadas de la aplicación.Google Cloud Te recomendamos que uses una clave de API para las pruebas y credenciales predeterminadas de la aplicación para la producción. En esta página, se muestra cómo obtener una clave de la API de Google Cloud según si eres un usuario Google Cloud nuevo o existente.
Selecciona si tienes una Cuenta de Google con un proyecto Google Cloud existente:
Crea una Google Cloud clave de API
Si ya tienes un proyecto Google Cloud , sigue estas instrucciones para obtener una clave de API Google Cloud estándar. Como alternativa, puedes usar credenciales predeterminadas de la aplicación en lugar de una clave de API.
Antes de comenzar
Selecciona un proyecto, habilita la facturación y la API de Vertex AI
Autenticar las llamadas a la API a través de una cuenta de servicio: Seleccionada.
Haz clic en Seleccionar cuenta de servicio.
Selecciona la cuenta de servicio que creaste en el paso anterior y haz clic en Seleccionar.
Haz clic en Crear.
Realiza tu primera solicitud a la API
Después de obtener una clave de API, consulta la guía de inicio rápido de la API para aprender a usarla y realizar tu primera solicitud.
Opcional: Configura tu clave de API de forma local
Para las pruebas iniciales, puedes codificar de forma rígida una clave de API, pero esto solo debe ser temporal, ya que no es seguro. En el resto de esta sección, se explica cómo configurar tu clave de API de forma local como una variable de entorno con diferentes sistemas operativos.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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)."]]