Java
The official Java library for the Superslice API.
Java 11 or newer. The only dependency is Jackson (jackson-databind). Requests use java.net.http.HttpClient. Response types are immutable classes with getters (not records) so the library runs on Java 11.
Source, issues and releases: superslice-co/superslice-java.
Install
The package is not yet published to Maven Central. Until it is, install it from GitHub.
Clone it and install it into your local Maven repository:
git clone https://github.com/superslice-co/superslice-java.git
cd superslice-java
mvn installThen depend on it:
<dependency>
<groupId>co.superslice</groupId>
<artifactId>superslice-java</artifactId>
<version>0.1.0</version>
</dependency>Quickstart
import co.superslice.*;
import co.superslice.types.Slice;
import java.nio.file.Paths;
Superslice client = Superslice.builder().apiKey(System.getenv("SUPERSLICE_API_KEY")).build();
Slice slice = client.slices().create(SliceParams.builder()
.slicer("bambu-studio")
.printer("Bambu Lab A1 0.4 nozzle")
.process("0.20mm Standard @BBL A1")
.filament("Bambu PLA Basic @BBL A1")
.plateType("Textured PEI Plate")
.file(Paths.get("cube.stl"))
.build());
Slice result = client.slices().wait(slice.getId());
if (result.getStatus().equals("succeeded")) {
System.out.println(result.getResult().getPrintTimeS() + " s");
System.out.println(result.getResult().getFilamentG() + " g");
if (result.getPrice() != null) {
// money is an integer in the currency's minor unit
System.out.println(result.getPrice().getTotalMinor() + " " + result.getPrice().getCurrency());
}
} else {
System.out.println("failed: " + result.getError().getCode());
}wait returns the slice when it is succeeded or failed; it does not throw on failed. It polls every 2 seconds for up to 10 minutes and throws SupersliceTimeoutException after that: wait(id, Duration.ofSeconds(1), Duration.ofMinutes(2)).
Other ways to supply the model: .modelId("mdl_...") to reuse an upload, .modelUrl("https://...", "name.stl") to have the API download it, or .file("name.stl", bytes) / .file("name.stl", inputStream). Your own presets: .printerPreset("pst_..."), .processPreset(...), .filamentPreset(...).
To go through every slice, newest first:
for (Slice s : client.slices().listAll()) {
System.out.println(s.getId() + " " + s.getStatus());
}client.slices().list(limit, cursor) returns one page with getData() and getNextCursor().
Catalogue lookup
List<Engine> engines = client.engines().list();
String release = engines.get(0).getId(); // for example bambu-studio@02.09.02.62+02.09.00.89
List<Printer> printers = client.engines().printers(release);
List<Process> processes = client.engines().processes(release, "Bambu Lab A1 0.4 nozzle");
List<Filament> filaments = client.engines().filaments(release, "Bambu Lab A1 0.4 nozzle");
List<String> plates = client.engines().plateTypes(release, "Bambu Lab A1 0.4 nozzle");Releases contain @ and +. The library URL-encodes them; pass them as they are.
Idempotency
Pass a key as the second argument. Repeating a key returns the same slice, and a retry can never slice twice.
Slice slice = client.slices().create(params, "order-1234");Errors
Every error extends SupersliceException (unchecked) and carries getStatus(), getCode(), getTitle(), getErrors(), getRetryAfter() and getBody().
| Class | When |
|---|---|
AuthenticationException | 401 |
PermissionException | 403 |
NotFoundException | 404 |
ConflictException | 409 |
RateLimitException | 429 |
InvalidRequestException | 400, 413 |
PlanLimitException | 402 |
ServerException | 5xx |
SupersliceConnectionException | no response from the server |
SupersliceTimeoutException | a request or wait ran out of time |
SignatureVerificationException | a webhook did not verify |
try {
client.slices().get("job_missing");
} catch (NotFoundException e) {
System.out.println(e.getCode()); // not_found
} catch (SupersliceException e) {
System.out.println(e.getStatus() + " " + e.getCode());
}The connection and timeout classes are prefixed to avoid clashing with java.util.concurrent.TimeoutException.
Retries
A 429 waits for Retry-After seconds (1 second if absent). A 5xx or a network error backs off 0.5, 1 and 2 seconds. The default is 2 retries. A POST is retried only when you passed an idempotency key, so a retry cannot slice twice. Creating presets (POST /v1/presets) is never retried. GET, PUT, PATCH and DELETE retry freely.
Webhooks
Pass the raw request body, before any JSON parsing, and the Superslice-Signature header. verify throws SignatureVerificationException when the signature is wrong or the timestamp is more than 5 minutes off, and returns the event otherwise.
WebhookEvent event = Webhooks.verify(secret, signatureHeader, rawBody);
if (event.getEvent().equals("slice.completed")) {
Slice slice = event.slice();
System.out.println(slice.getId() + ": " + slice.getResult().getPrintTimeS() + " s");
}rawBody can be a String or byte[]. A fourth argument sets the tolerance in seconds. The same event can arrive twice: store event.getEventId() and ignore repeats.
Configuration
Superslice client = Superslice.builder()
.apiKey("...") // default: SUPERSLICE_API_KEY
.baseUrl("https://api.superslice.co") // default
.timeout(Duration.ofSeconds(60)) // default, per request
.maxRetries(2) // default
.build();A missing key throws IllegalArgumentException when you call build().
API surface
client.slices():create(params[, idempotencyKey]),get(id),list([limit, cursor]),listAll([pageSize]),wait(id[, interval, timeout])client.models():get(id),delete(id)client.engines():list(),printers(release),processes(release, printer),filaments(release, printer),plateTypes(release, printer)client.presets():create(path, slicer),list(),get(id),update(id, name),delete(id)client.pricing():get()(null when no rules),set(PricingParams),delete()client.slicers():list(),update(slicer, mode[, engineReleases])Webhooks.verify(secret, header, rawBody[, toleranceSeconds])
Response types live in co.superslice.types. Fields the API adds later are ignored, not errors. Status and enum values are plain strings.