Invoice parser

Document AI allows you to take invoices in a variety of formats and return structured data to reduce manual document processing.

The invoice parser extracts both header and line item fields, such as invoice number, supplier name, invoice amount, tax amount, invoice date, due date, and line item amounts.

Request document processing from a smaller file (<=5 pages for most processors) using the process method, and larger file requests (files with a large number of pages) use the batchProcess method. The status of batch (asynchronous) requests can be checked using the operations resource.

Example invoice:

invoice example with API annotations

Fields extracted

The following is a list of the exemplar annotations returned in a Document response object's entities and entityRelations fields.

This example list may be expanded in current or future API versions:

Field Annotations
entities
  • invoice_id
  • invoice_date
  • purchase_order
  • total_amount
  • total_tax_amount
  • amount_due
  • due_date
  • payment_terms
  • supplier_name
  • currency
  • receiver_name
  • receiver_address
  • delivery_date
  • supplier_address
  • supplier_tax_id
  • customer_tax_id
  • carrier
  • ship_to_name
  • ship_to_address
  • ship_from_name
  • ship_from_address
entityRelations
  • line_item/amount
  • line_item/unit_price
  • line_item/quantity
  • line_item/unit
  • line_item/description
  • line_item/product_code

Processor details

File types supported PDF, TIFF, GIF
Maximum number of pages (online/synchronous) 5
Maximum number of pages (offline/asynchronous/batch) 2000
Maximum file size 20Mb

Small file online processing

Synchronous ("online") requests target a document with a small number of pages and size stored in Cloud Storage. Synchronous requests immediately return a response inline.

The following code samples show you how to process an invoice document.

  • IMAGE_CONTENT: Inline document content, represented as a stream of bytes. For JSON represenations, the base64 encoding (ASCII string) of your binary image data. This string should look similar to the following string:
    • /9j/4QAYRXhpZgAA...9tAVx/zDQDlGxn//2Q==
    Visit Vision API's Base64 encode topic for more information.
  • HTTP method and URL:

    POST https://LOCATION-documentai.googleapis.com/v1beta3/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:process

    Request JSON body:

    {
      "document": {
        "mimeType": "MIME_TYPE",
        "content": "IMAGE_CONTENT"
      }
    }
    

    To send your request, choose one of these options:

    curl

    Save the request body in a file called request.json, and execute the following command:

    curl -X POST \
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    https://LOCATION-documentai.googleapis.com/v1beta3/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:process

    PowerShell

    Save the request body in a file called request.json, and execute the following command:

    $cred = gcloud auth application-default print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-documentai.googleapis.com/v1beta3/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:process" | Select-Object -Expand Content

    If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format. The response body contains an instance of Document.