Learn how to resolve some errors raised by Document AI. This topic discusses errors whose resolutions require more steps than can be easily described in an error message.
"The Application Default Credentials are not available"
If you receive this message:
The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
Document AI uses Application Default Credentials for authentication.
You must have a service account for your
project, download the key (JSON file) for your service account to
your development environment, and then set the location of that
JSON file to an environment variable named
GOOGLE_APPLICATION_CREDENTIALS
.
Furthermore, the GOOGLE_APPLICATION_CREDENTIALS
environment variable must be available within the
context that you call the Document AI API. For example, if you set
the variable from within an terminal session but run your code in the
debugger of your IDE, the execution context of your code might not
have access to the variable. In that circumtance, your request to
Document AI might fail for lack of proper
authentication.
For more information on how to set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable,
see the Document AI
quickstart
or the documentation on
using the Application Default Credentials.
"File ... (pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist!"
If you receive this message:
ERROR: (gcloud.auth.application-default.print-access-token) File /path/to/key.json (pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist! { "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } }
Verify that you have a valid service account key JSON file in
the location stored in the GOOGLE_APPLICATION_CREDENTIALS
environment variable and that the variable points to the correct
place.
To diagnose this error, try opening the service account key file from the folder from which you're attempting to call the Document AI API.
cat $GOOGLE_APPLICATION_CREDENTIALS
Forbidden: 403 POST API has not been used or is disabled
If you receive the message:
Forbidden: 403 POST Document AI API has not been used in project # before or it is disabled. Enable it by visitng [url] then retry. If you enabled this API recently, wait a few minutes for the action to propagate and retry.
- Visit the link specified in the error message and enable the Document AI API. Wait several minutes and then retry.
- Verify that you have a valid service account key JSON file stored in
the
GOOGLE_APPLICATION_CREDENTIALS
environment variable. To diagnose this error, try opening the service account key file from the folder from which you're attempting to call the Document AI API.cat $GOOGLE_APPLICATION_CREDENTIALS
"Error writing final output to: gs://..."
If you receive a message like the following when receiving the results of a batch process request:
{ "name": "projects/project-name/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.document.v1beta1.OperationMetadata", "state": "SUCCEEDED", "createTime": "2019-09-19T02:02:15.885267760Z", "updateTime": "2019-09-19T02:02:31.896425001Z" }, "done": true, "error": { "code": 5, "message": "Error writing final output to: gs://bucket-name/filename.json" } }
Your service account may not have the correct permissions to create objects in your Cloud Storage bucket. Be sure that you have assigned the correct permissions to your service account, as described in the quickstart.
You might also have misspelled the name of your Cloud Storage bucket. Verify that the bucket that you're attempting to access exists.
"Quota exceeded"
If you receive this message:
RESOURCE_EXHAUSTED: Quota exceeded.
You have reached the limit of your per-minute or daily quota. Review the quotas & limits for using Document AI.
You can request an increase to your quotas from the Google Cloud Console.