Java
Documentation for the Document AI API Java SDK
SDK Installation
Getting started
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
Maven:
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:
On Windows:
Logging
A logging framework/facade has not yet been adopted but is under consideration.
For request and response logging (especially json bodies) use:
Example output:
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
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKeyAuth | http | HTTP Bearer |
To authenticate with the API the apiKeyAuth
parameter must be set when initializing the SDK client instance. For example:
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:
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 Type | Status Code | Content Type |
---|---|---|
models/errors/BadRequestError | 400 | application/json |
models/errors/UnauthorizedError | 401 | application/json |
models/errors/TooManyRequestsError | 429 | application/json |
models/errors/InternalServerError | 500 | application/json |
models/errors/APIException | 4XX, 5XX | */* |