Modzy's Java SDK provides a convenient wrapper around many of Modzy's most popular API routes. SDK functions include querying models, submitting inference jobs, and returning results directly to your IDE or program.

Installation

Clone the repository

$ git clone https://github.com/modzy/sdk-java.git

Use maven to install the SDK

$ ./mvnw install -DskipTests=true

Add the dependency in your pom.xml file

<dependency>
    <groupId>com.modzy</groupId>
    <artifactId>modzy-sdk</artifactId>
    <version>0.0.1</version>
</dependency>

Usage

Get your API key

API keys are security credentials required to perform API requests to Modzy. Our API keys are composed of an ID that is split by a dot into two parts: a public and private part.

The public part is the API keys' visible part only used to identify the key and by itself, it’s unable to perform API requests.

The private part is the public part's complement and it’s required to perform API requests. Since it’s not stored on Modzy’s servers, it cannot be recovered. Make sure to save it securely. If lost, you can replace the API key.

Find your API key in your user profile. To get your full API key click on "Get key".

Initialize

Once you have a model and version identified, get authenticated with your API key.

ModzyClient modzyClient = new ModzyClient(API_URL, API_KEY);

Replace API_URL with the base URL of your instance of Modzy and add "/api" at the end, such as "https://trial.app.modzy.com/api"

Replace API_KEY with a valid API key string, such as "q0CsemRk8Xb9ev5CPck2.5SUav09fKPX0o1IX1xqG" Here's how to download an API Key from Modzy

Basic usage

Submit a job providing the model, version, and input file:

Job job = modzyClient.submitJobText("ed542963de", "0.0.27", "Modzy is great!");

Hold until the inference is complete and results become available:

Job job = modzyClient.blockUntilComplete(job, 20000);

Get the output results:

JobOutput<JsonNode> jobResult = modzyClient.getResult(job);
Map<String,Map<String,JsonNode>> results = jobResult.getResults();

Fetch Errors

Errors may arise for different reasons. Fetch errors to know what is their cause and how to fix them.

ErrorDescription
ApiExceptionWrapper for different exceptions, check the message and the stacktrace.

Functions & Methods

Currently, the Java SDK supports the following API routes:

Function or MethodDescription
modzyClient.getAllModelsRetrieve all the models
modzyClient.getModelsRetrieve some models
modzyClient.getModelRetrieve model details by identifier
modzyClient.getModelByNameRetrieve model details by name
modzyClient.getRelatedModelsRetrieve the list of related models
modzyClient.getModelVersionsRetrieve the versions of a model by identifier
modzyClient.getModelVersionRetrieve the version details
modzyClient.getModelVersionInputSampleRetrieve the raw JSON input sample of a model and version
modzyClient.getModelVersionOutputSampleRetrieve the output sample of a model and version
modzyClient.getJobClient().getJobHistoryList the job history
modzyClient.getJobClient().submitJobSubmit a job
modzyClient.submitJobTextSubmit a job using text as inputs
modzyClient.submitJobEmbeddedSubmit a job using bytes as inputs
modzyClient.submitJobFileSubmit a job using files as inputs
modzyClient.submitAWSS3Submit a job using aws s3 files as inputs
modzyClient.submitJobJDBCSubmits a job using a SQL query with JDBC access params
modzyClient.getJobRetrieve the job information from Modzy
modzyClient.getJobClient().cancelJobSend a request to cancel the job processing
modzyClient.getResultRetrieve the results of a job