Amniscient Detection SDK for Java
Java client for the Amniscient Inference API, over HTTPS or NATS (WebSocket). It gives you low-latency object detection behind one call, client.detect(image, modelId).
Requires Java 8 or later, and is tested on 8, 11, 17 and 21. It has two dependencies, both Java 8 compatible: Jackson (JSON) and jnats (the NATS transport). HTTP is the JDK’s built-in HttpURLConnection, and compression and annotation use the JDK’s ImageIO and 2D graphics.
This SDK follows the same contract as the Python and TypeScript SDKs and passes the same conformance suite (sdk/contract). The calls, errors, retries and result shape are identical; only the language differs.
Install
Maven:
Gradle:
Quick start
One client is thread-safe; share it across your application and close it on shutdown.
How it works
- Auth is validated first: a missing API key throws
AuthenticationExceptionbefore any image work or network call. - The image is prepared: checked (JPEG, PNG or WebP), then resized to fit 3840 px on the long side and JPEG-encoded at quality 70, unless you turn compression off.
- The request is sent over HTTPS or NATS. A transient failure (network error, timeout, 5xx) is retried with exponential backoff.
- The reply becomes a
DetectionResult, or a typed exception is thrown (see Errors).
Over NATS (WebSocket)
For lower latency and a persistent connection, use the NATS transport. The same API key works. The organization is resolved from the key when you don’t pass it, and the server confines the connection to that organization.
- One tenant per client. NATS binds the key to the connection, so per-call
apiKey/organizationIdinDetectOptionsthrowIllegalArgumentException. Use one client per tenant, or HTTP for a multi-tenant proxy. - Same errors and retries as HTTP. A rejected key is an
AuthenticationException; timeouts and 5xx replies are retried. close()drains the connection. Use try-with-resources or close the client on shutdown.
Usage
Options per call
To resolve the model from an inference point instead of a model id, set .inferencePointId("…") and pass null for the model id.
Barcodes and QR codes
With detectBarcodes(true), result.barcodes() lists the decoded codes. Object detection is unchanged.
- Types:
qr,upc-a,upc-e,code-39. - When it’s empty: the list is empty when the option is off, no codes are found, or decoding fails. Decoding never fails the call.
Filtering results
Raw responses
detectRaw(bytes, modelId, options) returns the server’s JSON as a Map<String, Object>, the xywh centre-box shape. Use it when you need fields the model doesn’t cover. result.raw() gives you the same map.
Multi-tenant / per-request credentials (HTTP)
Build one shared client with no stored credentials and pass them per call. They ride the request and nothing is kept:
Login gate, model picker, default model
validate() returns false only for a rejected key. A route that isn’t deployed (EndpointNotAvailableException), a server error or a connection problem is thrown, never reported as false.
Annotating detections
Configuration
Other environments: https://api.stage.amniscient.com/uat/inference + wss://nats-server.uat.internal.amniscient.com, …/dev/… + wss://nats-server.dev.internal.amniscient.com, https://api.sandbox.amniscient.com/sandbox/inference + wss://nats-server.sandbox.internal.amniscient.com. All of them are listed in Contract.HTTP_ENDPOINTS and Contract.NATS_ENDPOINTS.
Errors
Every failure is an unchecked exception under DetectionException. Each carries getStatusCode() and getResponseBody() when a server answered.
Live harness
HarnessRunner drives the SDK end to end against a live endpoint. It runs validate(), listModels(), then detect() over one image or a folder, and prints a summary. Config comes from the environment, so no secrets go on the command line:
Build & test
Requires JDK 8+ and Maven.
Contract.java is generated from sdk/contract/contract.json; don’t edit it by hand. Run python3 sdk/contract/generate.py instead.