如需在 Vertex AI 上使用 Gemini,您需要使用 Google Cloud API 密钥或使用应用默认凭据进行身份验证。我们建议您在测试时使用 API 密钥,在生产环境中使用应用默认凭据。本页介绍了如何配置应用默认凭据。
准备工作
选择项目、启用结算功能、启用 Vertex AI API、安装 gcloud CLI
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
创建本地身份验证凭据
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
发出您的第一个 API 请求
配置应用默认凭据后,请参阅 API 快速入门,了解如何发出第一个请求。