Learn how to resolve some errors raised by Document AI. This topic discusses errors whose resolutions require more steps than can be described in an error message.
See the Cloud API documentation for recommended practices of error handling.
Permissions
The resolution requires a few steps to be carried out as outlined in the error message.
Application default credentials are not available
If you receive this message:
The Application Default Credentials are not available. They are available if running in 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 a 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.
Permission denied
If you receive this message:
ERROR: (gcloud.auth.application-default.print-access-token) File
(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 visiting [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_CREDENTIALSenvironment 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
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.
P4SA no access to Cloud Storage
When Document AI Per-Product Service Account (P4SA) has no permission to access some Cloud Storage resources.
message: "Cloud DocumentAI P4SA doesn't have access to this Cloud Storage resource:"
Service Account cannot create object in Cloud Storage
When Document AI Per-Product Service Account (P4SA) has no permission to create object in Cloud Storage.
message: "Service account service-123@gcp-sa-prod-dai-core.iam.gserviceaccount.com
does not have permission storage.objects.create to create
Google Cloud Storage object in bucket gs://foo."
Document AI service account might not have the correct permissions to create objects in your Cloud Storage bucket. Be sure that you have assigned the correct permissions to the Document AI service account, as described in the cross project file access setup.
You might also have misspelled the name of your Cloud Storage bucket. Verify that the bucket that you're attempting to access exists.
Caller cannot get objects in Cloud Storage
When the caller of Document AI API has no permission to get objects in Cloud Storage.
message: "The caller does not have permission storage.objects.get to get Google
Cloud Storage objects in bucket gs://foo."
The caller of the API might not have the correct permissions to get objects in your Cloud Storage bucket. Be sure that you have assigned the correct permissions to the caller.
You might also have misspelled the name of your Cloud Storage bucket. Verify that the bucket that you're attempting to access exists.
Invalid arguments
The resolution requires a few steps to be carried out as outlined in the error message.
API version unsupported
When a request is made to an API version that doesn't support the operation.
message: "The requested operation is unsupported for the API version."
Processor type unsupported
When a request is made to an API method that doesn't support the given processor type.
message: "The requested operation is unsupported for the processor type: ${PROCESSOR_TYPE}."
Bad Request
When an API request is made but the request fields have one or more violations.
Each violation is captured as a field_violations in the google.rpc.BadRequest
details.
message: "Request contains an invalid argument."
details {
[type.googleapis.com/google.rpc.BadRequest] {
field_violations { field: "foo" description: "bar" }
}
}
Batch processing all documents failed
When every document in a batch processing request fails to process.
message: "Failed to process all documents."
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "FAILED_TO_PROCESS_ALL_DOCUMENTS"
domain: "documentai.googleapis.com"
}
}
No documents
When documents are required or expected but none are provided, such as when importing documents by Cloud Storage URI.
message: "No valid documents found in ${training|test} directory. Ensure files are in a supported MIME type. For details, see https://cloud.google.com/document-ai/docs/file-types."
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "NO_DOCUMENTS"
domain: "documentai.googleapis.com"
}
}
The gcsUriPrefix and gcsOutputConfig.gcsUri parameters need to begin with gs:// and end with a trailing backslash character (/). Check the configuration for the bucket URIs.
Example: gs://bucket/directory/
Training is not supported
When a train processor version request is made on a processor type that doesn't support training.
message: "Training is not supported on processor type: ${DOCUMENT_TYPE}_PROCESSOR."
No documents selected
When documents are expected, but none are selected in the dataset, such as when creating data labeling jobs.
message: No documents selected. Please select at least one document."
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "NO_DOCUMENTS_SELECTED"
domain: "documentai.googleapis.com"
}
}
Document type not found
When a document's class (like license, passport, or invoice) does not match the classification necessary for the processor type. An example is when the classifier step in the W2 parser doesn't find elements from an invoice.
This may also appear as Couldn't preview the document: Unable to find a document of type: 'foo' in the Google Cloud console.
This error message is applicable to legacy processors.
message: "Unable to find a document of type: 'foo'"
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "DOCUMENT_OF_TYPE_NOT_FOUND"
domain: "documentai.googleapis.com"
}
}
Document size limit exceeded
When the upper limit for the file size of a document has been exceeded while importing dataset or while running prediction.
message: "Document size (2) exceeds limit: 1 (bytes)."
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "DOCUMENT_SIZE_LIMIT_EXCEEDED"
domain: "documentai.googleapis.com"
metadata { key: "limit" value: "1" }
metadata { key: "size" value: "2" }
}
}
Document limit exceeded
When the upper limit for the count of documents has been exceeded.
message: "Document count exceed the limit: 5 got 6"
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "DOCUMENT_LIMIT_EXCEEDED"
domain: "documentai.googleapis.com"
metadata { key: "document_limit" value: "5" }
metadata { key: "documents" value: "6" }
}
}
Unsupported MIME type
When an unsupported MIME type was provided. The system verifies the file format (MIME type) when you import a dataset or make a prediction call. Go to Supported files (and for Layout Parser) to see the available file types. If the file format is not supported, you see the following error message:
message: "INVALID_ARGUMENT: Unsupported MIME type: 'foo'."
details {
[type.googleapis.com/google.rpc.ErrorInfo] {
reason: "UNSUPPORTED_MIME_TYPE"