The Phenoml Java library provides convenient access to the Phenoml API from Java.
Instantiate and use the client with the following:
package com.example.usage;
import com.phenoml.api.Client;
import com.phenoml.api.resources.agent.requests.AgentCreateRequest;
import java.util.ArrayList;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
// Use client with automatic authentication
Client client = Client.withCredentials("your-username", "your-password", "https://api.example.com");
// Or use with existing token
// Client client = Client.withToken("your-token", "https://api.example.com");
client.agent().create(
AgentCreateRequest
.builder()
.name("name")
.prompts(
new ArrayList<String>(
Arrays.asList("prompt_123", "prompt_456")
)
)
.isActive(true)
.build()
);
}
}This SDK allows you to configure different environments for API requests.
import com.phenoml.api.PhenoML;
import com.phenoml.api.core.Environment;
PhenoML client = PhenoML
.builder()
.environment(Environment.Default)
.build();You can set a custom base URL when constructing the client.
import com.phenoml.api.PhenoML;
PhenoML client = PhenoML
.builder()
.url("https://example.com")
.build();When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.
import com.phenoml.api.core.PhenomlApiApiException;
try {
client.agent().create(...);
} catch (PhenomlApiApiException e) {
// Do something with the API exception...
}This SDK is built to work with any instance of OkHttpClient. By default, if no client is provided, the SDK will construct one.
However, you can pass your own client like so:
import com.phenoml.api.PhenoML;
import okhttp3.OkHttpClient;
OkHttpClient customClient = ...;
PhenoML client = PhenoML
.builder()
.httpClient(customClient)
.build();The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the maxRetries client option to configure this behavior.
import com.phenoml.api.PhenoML;
PhenoML client = PhenoML
.builder()
.maxRetries(1)
.build();The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
import com.phenoml.api.PhenoML;
import com.phenoml.api.core.RequestOptions;
// Client level
PhenoML client = PhenoML
.builder()
.timeout(10)
.build();
// Request level
client.agent().create(
...,
RequestOptions
.builder()
.timeout(10)
.build()
);While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!