Get processor type (v1)

Get details for a specific Document AI processor type.

Code sample

Go

For more information, see the Document AI Go API reference documentation.

To authenticate to Document AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import (
	"context"
	"fmt"
	"io"

	documentai "cloud.google.com/go/documentai/apiv1beta3"
	"cloud.google.com/go/documentai/apiv1beta3/documentaipb"
	"google.golang.org/api/option"
)

// getProcessorType gets details of a Document AI processor type.
func getProcessorType(ctx context.Context, w io.Writer, projectID string, locationID string, processorTypeID string) error {
	name := fmt.Sprintf("projects/%s/locations/%s/processorTypes/%s", projectID, locationID, processorTypeID)

	endpoint := fmt.Sprintf("%s-documentai.googleapis.com:443", locationID)
	client, err := documentai.NewDocumentProcessorClient(ctx, option.WithEndpoint(endpoint))
	if err != nil {
		return fmt.Errorf("NewDocumentProcessorClient failed: %w", err)
	}
	defer client.Close()

	req := &documentaipb.GetProcessorTypeRequest{
		Name: name,
	}

	resp, err := client.GetProcessorType(ctx, req)
	if err != nil {
		return fmt.Errorf("GetProcessorType failed: %w", err)
	}

	fmt.Fprintf(w, "Processor type name: %s\n", resp.GetName())
	fmt.Fprintf(w, "Type: %s\n", resp.GetType())
	fmt.Fprintf(w, "Category: %s\n", resp.GetCategory())
	fmt.Fprintf(w, "Allow creation: %t\n", resp.GetAllowCreation())

	return nil
}

Java

For more information, see the Document AI Java API reference documentation.

To authenticate to Document AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.DocumentProcessorServiceSettings;
import com.google.cloud.documentai.v1.GetProcessorTypeRequest;
import com.google.cloud.documentai.v1.ProcessorType;
import com.google.cloud.documentai.v1.ProcessorTypeName;

public class GetProcessorType {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project-id";
    String locationId = "example-location-id";
    String processorTypeId = "example-processor-type-id";
    getProcessorType(projectId, locationId, processorTypeId);
  }

  public static void getProcessorType(String projectId, String locationId, String processorTypeId)
      throws Exception {
    // Configure regional endpoint for Document AI
    String endpoint = String.format("%s-documentai.googleapis.com:443", locationId);
    DocumentProcessorServiceSettings settings =
        DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();

    try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
      String name = ProcessorTypeName.of(projectId, locationId, processorTypeId).toString();

      GetProcessorTypeRequest request =
          GetProcessorTypeRequest.newBuilder().setName(name).build();

      ProcessorType processorType = client.getProcessorType(request);
      System.out.println("Processor Type: " + processorType.getType());
      System.out.println("Category: " + processorType.getCategory());
      System.out.println("Resource Name: " + processorType.getName());
    }
  }
}

Node.js

For more information, see the Document AI Node.js API reference documentation.

To authenticate to Document AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

'use strict';

const {DocumentProcessorServiceClient} = require('@google-cloud/documentai');
const {status} = require('@grpc/grpc-js');

const client = new DocumentProcessorServiceClient();

/**
 * Use the getProcessorType method
 *
 * @param {string} projectId - The Google Cloud project ID.
 * @param {string} locationId - The location ID where processor types are hosted (e.g., 'us' or 'eu').
 * @param {string} processorTypeId - The processor type identifier (e.g., 'OCR_PROCESSOR', 'INVOICE_PROCESSOR').
 */
async function getProcessorType(projectId, locationId, processorTypeId) {
  try {
    const name = `projects/${projectId}/locations/${locationId}/processorTypes/${processorTypeId}`;
    const request = {
      name,
    };

    const [processorType] = await client.getProcessorType(request);

    console.log(`Processor Type: ${processorType.type}`);
    console.log(`Category: ${processorType.category}`);
    console.log(`Available: ${processorType.allowCreation ? 'Yes' : 'No'}`);
    return processorType;
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Processor type not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied: ${err.message}`);
    } else {
      console.error(`API error: ${err.message}`);
    }
  }
}

module.exports = { getProcessorType };

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.