Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Wenn Sie Gemini in Vertex AI verwenden möchten, authentifizieren Sie sich mit einem Google Cloud API-Schlüssel oder mit Standardanmeldedaten für Anwendungen. Wir empfehlen, für Tests einen API-Schlüssel und für die Produktion Standardanmeldedaten für Anwendungen zu verwenden. Auf dieser Seite erfahren Sie, wie Sie einen Google Cloud API-Schlüssel erhalten, je nachdem, ob Sie ein neuer oder ein bestehender Google Cloud Nutzer sind.
Wählen Sie aus, ob Sie ein Google-Konto mit einem vorhandenen Google Cloud Projekt haben:
Google Cloud API-Schlüssel erstellen
Wenn Sie bereits ein Google Cloud Projekt haben, folgen Sie der Anleitung unten, um einen Standard- Google Cloud API-Schlüssel zu erhalten. Alternativ können Sie Standardanmeldedaten für Anwendungen anstelle eines API-Schlüssels verwenden.
Hinweise
Projekt auswählen, Abrechnung aktivieren, Vertex AI API aktivieren
Klicken Sie auf Anmeldedaten erstellen > API-Schlüssel.
Konfigurieren Sie den API-Schlüssel so:
Name:vertexaiapikey
API-Aufrufe über ein Dienstkonto authentifizieren: Ausgewählt.
Klicken Sie auf Dienstkonto auswählen.
Wählen Sie das Dienstkonto aus, das Sie im vorherigen Schritt erstellt haben, und klicken Sie auf Auswählen.
Klicken Sie auf Erstellen.
Erste API-Anfrage stellen
Nachdem Sie einen API-Schlüssel erhalten haben, erfahren Sie in der API-Kurzanleitung, wie Sie Ihren API-Schlüssel verwenden, um Ihre erste Anfrage zu stellen.
Optional: API-Schlüssel lokal einrichten
Für erste Tests können Sie einen API-Schlüssel fest codieren. Dies sollte jedoch nur vorübergehend erfolgen, da es nicht sicher ist. Im Rest dieses Abschnitts wird beschrieben, wie Sie Ihren API-Schlüssel lokal als Umgebungsvariable für verschiedene Betriebssysteme einrichten.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]