本页可帮助开发者设置 Google Distributed Cloud (GDC) 空气隔离项目,以使用 Vertex AI Translation。此过程包括创建项目、启用 Vertex AI Translation API、安装客户端库、定义环境变量和验证您的凭据。如果您是 Vertex AI 新手,请详细了解翻译功能。
您可以使用 GDC 控制台和 gdcloud CLI 设置翻译项目,具体如下所示:
GDC 控制台:启用 Vertex AI Translation API,并查看服务状态和端点。
gdcloud CLI:配置服务账号以与 Vertex AI Translation API 互动、安装客户端库并对 API 请求进行身份验证。
创建项目
在分布式云 资源层次结构中创建翻译项目可整理您的 Vertex AI Translation 资源,包括协作者、已启用的 API、监控工具、结算信息、身份验证凭据和访问权限控制。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThis page guides developers through setting up a Google Distributed Cloud (GDC) air-gapped project for using Vertex AI Translation, including creating a project and configuring access.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the GDC console to enable the Vertex AI Translation API and the \u003ccode\u003egdcloud\u003c/code\u003e CLI to configure service accounts and manage API interactions.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers must obtain the AI Translation Developer role to access translation services and generate API tokens for authentication.\u003c/p\u003e\n"],["\u003cp\u003eInstall the Python client library, ensuring the version matches the one provided by your organization's GDC URL, to streamline interactions with the Vertex AI Translation API.\u003c/p\u003e\n"],["\u003cp\u003eSet environment variables in your Python script to manage service account keys and authenticate API requests by creating and running a JupyterLab notebook.\u003c/p\u003e\n"]]],[],null,["# Set up a translation project\n\nThis page helps developers set up a Google Distributed Cloud (GDC) air-gapped project\nto use Vertex AI Translation. This process includes creating a project,\nenabling the Vertex AI Translation API, installing\nclient libraries, defining environment variables, and authenticating your\ncredentials. If you are new to Vertex AI,\n[learn more about translation features](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-translation).\n\nYou set up a translation project using the GDC console and\ngdcloud CLI as follows:\n\n- **GDC console**: Enable the Vertex AI Translation API and view the service status and endpoint.\n- **The gdcloud CLI**: Configure service accounts to interact with the Vertex AI Translation API, install client libraries, and authenticate API requests.\n\nCreate a project\n----------------\n\nCreating a translation project within your Distributed Cloud [resource hierarchy](/distributed-cloud/hosted/docs/latest/gdch/overview#resource_hierarchy)\norganizes your Vertex AI Translation resources, which include collaborators,\nenabled APIs, monitoring tools, billing information, authentication credentials,\nand access controls.\n\nTo create your project, see [Set up a project for Vertex AI](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-set-up-project).\nYou need your project ID when making API calls.\n| **Tip:** Improve security, resource management, and cost tracking by isolating your experimental, testing, and production workloads in separate Distributed Cloud projects.\n\nRequest developer permissions\n-----------------------------\n\nYou must have the AI Translation Developer role in your project to\naccess translation services and generate an API token for request authentication\nand authorization.\n\nAsk your Project IAM Admin to grant the AI Translation Developer\n(`ai-translation-developer`) role to your user or service account\nwithin your project namespace. For information about this role, see\n[Prepare IAM permissions](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-ao-permissions).\n\nEnable the Vertex AI Translation API\n------------------------------------\n\nYou must [enable the Vertex AI Translation pre-trained API](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-enable-pre-trained-apis)\nfor your project. If enabled, you can [view the service status and endpoint for the Vertex AI Translation pre-trained API](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-api-status).\n\nInstall client libraries\n------------------------\n\nClient libraries are available for the Python programming language. We recommend\nusing these client libraries to make calls to the Vertex AI Translation API\nbecause they make it easier to access APIs.\n\n[Install the Vertex AI Translation client library](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-install-libraries)\nand follow these steps to ensure you have the correct version:\n\n1. Check if the Vertex AI Translation client library is installed and obtain\n the version number:\n\n pip freeze | grep translation\n\n If the client library is already installed, you obtain an output similar\n to the following example: \n\n google-cloud-translation==3.8.0\n\n The version number you obtain must match the client library at the\n following endpoint: \n\n https://\u003cvar translate=\"no\"\u003eGDC_URL\u003c/var\u003e/.well-known/static/client-libraries\n\n Replace \u003cvar translate=\"no\"\u003eGDC_URL\u003c/var\u003e with the\n URL of your organization in GDC.\n2. If the version numbers don't match, uninstall the client library:\n\n pip uninstall google-cloud-translation\n\n3. If you uninstalled the Vertex AI Translation client library, you must\n [reinstall it](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-install-libraries)\n by specifying the filename corresponding to your operating system.\n\nSet your environment variables\n------------------------------\n\nAfter installing the Vertex AI Translation client library, you can interact\nwith the API from a Python script.\n\nIf you [set up a service account](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-set-up-project#set-up-service)\nin your project to make authorized API calls programmatically, you can define\nenvironment variables in the Python script to access values such as the service\naccount keys when running.\n\nFollow these steps to set required environment variables on a Python script:\n\n1. [Create a JupyterLab notebook](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-workbench#create-notebook)\n to interact with the Vertex AI Translation pre-trained API.\n\n2. Create a Python script on the JupyterLab notebook.\n\n3. Add the following code to the Python script:\n\n import os\n\n os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = \"\u003cvar translate=\"no\"\u003eAPPLICATION_DEFAULT_CREDENTIALS_FILENAME\u003c/var\u003e\"\n\n Replace \u003cvar translate=\"no\"\u003eAPPLICATION_DEFAULT_CREDENTIALS_FILENAME\u003c/var\u003e with\n the name of the JSON file that contains [the service account keys you created](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-set-up-project#set-up-service)\n in the project, such as `my-service-key.json`.\n4. Save the Python script with a name, such as `translation.py`.\n\n5. Run the Python script to set the environment variables:\n\n python \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSCRIPT_NAME\u003c/span\u003e\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eSCRIPT_NAME\u003c/var\u003e with the name you gave to your\n Python script, such as `translation.py`.\n\n| **Note:** Keep the script open when using the environment variables from Python or getting an authentication token.\n\nSet up authentication\n---------------------\n\nBefore you can start using the Vertex AI Translation API, you must authenticate\nyour client credentials and request account access to your project resources.\nFor more information, see [Authenticate API requests](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/vertex-ai-api-auth)."]]