SDK Installation

Getting started

JDK 11 or later is required.

The samples below show how a published SDK artifact is used:

Gradle:

implementation 'com.abbyy:documentai:0.1.2'

Maven:

<dependency>
    <groupId>com.abbyy</groupId>
    <artifactId>documentai</artifactId>
    <version>0.1.2</version>
</dependency>

How to build

After cloning the git repository to your file system you can build the SDK artifact from source to the build directory by running ./gradlew build on *nix systems or gradlew.bat on Windows systems.

If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):

On *nix:

./gradlew publishToMavenLocal -Pskip.signing

On Windows:

gradlew.bat publishToMavenLocal -Pskip.signing

Logging

A logging framework/facade has not yet been adopted but is under consideration.

For request and response logging (especially json bodies) use:

SpeakeasyHTTPClient.setDebugLogging(true); // experimental API only (may change without warning)

Example output:

Sending request: http://localhost:35123/bearer#global GET
Request headers: {Accept=[application/json], Authorization=[******], Client-Level-Header=[added by client], Idempotency-Key=[some-key], x-speakeasy-user-agent=[speakeasy-sdk/java 0.0.1 internal 0.1.0 org.openapis.openapi]}
Received response: (GET http://localhost:35123/bearer#global) 200
Response headers: {access-control-allow-credentials=[true], access-control-allow-origin=[*], connection=[keep-alive], content-length=[50], content-type=[application/json], date=[Wed, 09 Apr 2025 01:43:29 GMT], server=[gunicorn/19.9.0]}
Response body:
{
  "authenticated": true, 
  "token": "global"
}

WARNING: This should only used for temporary debugging purposes. Leaving this option on in a production system could expose credentials/secrets in logs. Authorization headers are redacted by default and there is the ability to specify redacted header names via SpeakeasyHTTPClient.setRedactedHeaders.

Another option is to set the System property -Djdk.httpclient.HttpClient.log=all. However, this second option does not log bodies.

SDK Example Usage

Example

package hello.world;

import com.abbyy.documentai.DocumentAI;
import com.abbyy.documentai.models.errors.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws BadRequestError, UnauthorizedError, TooManyRequestsError, InternalServerError, Exception {

        DocumentAI sdk = DocumentAI.builder()
                .apiKeyAuth("<YOUR_BEARER_TOKEN_HERE>")
            .build();

        sdk.documents().list()
                .cursor("<optional_pagination_cursor_goes_here>")
                .callAsStream()
                .forEach(item -> {
                   // handle item again
                });

    }
}

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

NameTypeScheme
apiKeyAuthhttpHTTP Bearer

To authenticate with the API the apiKeyAuth parameter must be set when initializing the SDK client instance. For example:

package hello.world;

import com.abbyy.documentai.DocumentAI;
import com.abbyy.documentai.models.errors.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws BadRequestError, UnauthorizedError, TooManyRequestsError, InternalServerError, Exception {

        DocumentAI sdk = DocumentAI.builder()
                .apiKeyAuth("<YOUR_BEARER_TOKEN_HERE>")
            .build();

        sdk.documents().list()
                .cursor("<optional_pagination_cursor_goes_here>")
                .callAsStream()
                .forEach(item -> {
                   // handle item again
                });

    }
}

Available Resources and Operations

The available API operations and SDK implementation examples can be found within our API Reference documentation

Pagination

Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will have a next method that can be called to pull down the next group of results. The next function returns an Optional value, which isPresent until there are no more pages to be fetched.

Here’s an example of one such pagination call:

package hello.world;

import com.abbyy.documentai.DocumentAI;
import com.abbyy.documentai.models.errors.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws BadRequestError, UnauthorizedError, TooManyRequestsError, InternalServerError, Exception {

        DocumentAI sdk = DocumentAI.builder()
                .apiKeyAuth("<YOUR_BEARER_TOKEN_HERE>")
            .build();

        sdk.documents().list()
                .cursor("<optional_pagination_cursor_goes_here>")
                .callAsStream()
                .forEach(item -> {
                   // handle item again
                });

    }
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.

By default, an API error will throw a models/errors/APIException exception. When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the list method throws the following exceptions:

Error TypeStatus CodeContent Type
models/errors/BadRequestError400application/json
models/errors/UnauthorizedError401application/json
models/errors/TooManyRequestsError429application/json
models/errors/InternalServerError500application/json
models/errors/APIException4XX, 5XX*/*

Example

package hello.world;

import com.abbyy.documentai.DocumentAI;
import com.abbyy.documentai.models.errors.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws BadRequestError, UnauthorizedError, TooManyRequestsError, InternalServerError, Exception {

        DocumentAI sdk = DocumentAI.builder()
                .apiKeyAuth("<YOUR_BEARER_TOKEN_HERE>")
            .build();

        sdk.documents().list()
                .cursor("<optional_pagination_cursor_goes_here>")
                .callAsStream()
                .forEach(item -> {
                   // handle item again
                });

    }
}

Was this page helpful?