[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Set up a character recognition project\n\nThis page helps developers set up a Google Distributed Cloud (GDC) air-gapped appliance project to\nuse the Optical Character Recognition (OCR) service. This process includes creating a\nproject, enabling the OCR API, installing client libraries,\ndefining environment variables, and authenticating your credentials. If you are\nnew to Vertex AI, [learn more about character recognition features](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vertex-ai-ocr).\n\nYou set up a character recognition project using the GDC console and\ngdcloud CLI as follows:\n\n- **GDC console**: Enable the OCR API and view the service status and endpoint.\n- **The gdcloud CLI**: Configure service accounts to interact with the OCR API, install client libraries, and authenticate API requests.\n\nCreate a project\n----------------\n\nCreating a character recognition project organizes your OCR\nresources, which include collaborators, enabled APIs, authentication\ncredentials, and access controls.\n\nTo create your project, see [Set up a project for Vertex AI](/distributed-cloud/hosted/docs/latest/appliance/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 GDC air-gapped appliance projects.\n\nRequest developer permissions\n-----------------------------\n\nYou must have the AI OCR Developer role in your project to access\noptical character recognition features and generate an API token for request\nauthentication and authorization.\n\nAsk your Project IAM Admin to grant the AI OCR Developer\n(`ai-ocr-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/appliance/application/ao-user/vertex-ai-ao-permissions).\n\nEnable the OCR API\n------------------\n\nYou must [enable the OCR pre-trained API](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vertex-ai-enable-pre-trained-apis)\nfor your project. If enabled, you can [view the service status and endpoint for the OCR pre-trained API](/distributed-cloud/hosted/docs/latest/appliance/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 OCR API\nbecause they make it easier to access APIs.\n\n[Install the OCR client library](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vertex-ai-install-libraries)\nand follow these steps to ensure you have the correct version:\n\n1. Check if the OCR client library is installed and obtain\n the version number:\n\n pip freeze | grep vision\n\n If the client library is already installed, you obtain an output similar\n to the following example: \n\n google-cloud-vision==3.0.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-vision\n\n3. If you uninstalled the OCR client library, you must\n [reinstall it](/distributed-cloud/hosted/docs/latest/appliance/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 OCR 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/appliance/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 Python script.\n\n2. 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/appliance/application/ao-user/vertex-ai-set-up-project#set-up-service)\n in the project, such as `my-service-key.json`.\n3. Save the Python script with a name, such as `vision.py`.\n\n4. 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 `vision.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 OCR 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/appliance/application/ao-user/vertex-ai-api-auth)."]]