SDKs
Java SDK
Java watermarking SDK for Etchv. Watermark images, PDFs and videos, detect watermarks, and handle assets, async jobs and webhooks from your Java app.
Needs Java 21 or later. Gson is the only runtime dependency. Create one client and reuse it; it is safe to use from many threads at once. Close it when you are done. MIT licensed.
Install
Maven:
<dependency>
<groupId>com.etchv</groupId>
<artifactId>etchv-sdk</artifactId>
<version>1.0.0</version>
</dependency>Gradle (Kotlin DSL):
implementation("com.etchv:etchv-sdk:1.0.0")Embed a file
Set ETCHV_API_KEY on your server. This example needs an API key with the watermarks:embed and watermarks:detect scopes, an active plan and available credits.
import com.etchv.EtchvClient;
import java.nio.file.*;
import java.util.Map;
class Example {
public static void main(String[] args) throws Exception {
try (var client = new EtchvClient(System.getenv("ETCHV_API_KEY"))) {
System.out.println(client.getApiKeyInfo().scopes()); // no credits used
var result = client.embedImage(Files.readAllBytes(Path.of("photo.jpg")),
Map.of("asset", "photo-123"), new EtchvClient.Options("photo.jpg", null));
Files.write(Path.of(result.filename()), result.bytes());
var detection = client.detectImage(result.bytes(), null);
System.out.println(detection.watermarked() + " " + detection.confidence());
}
}
}getApiKeyInfo checks your API key and uses no credits. Save the output bytes as they are. Do not re-encode the file.
Images, documents and video
For every media type, result.bytes() holds the watermarked file in its original format. Embedding also returns watermarkId(), requestId(), contentType(), filename(), assetId(), sourceAssetId() and storageDeliveryId().
Detection returns the watermark it found, a confidence score, and results for each frame or page. It does not return the JSON you sent when you embedded the file. Result fields · Credits.
Client configuration
EtchvClient(key, baseUrl, Duration) sets the timeout. The default is 120 seconds. Each call blocks until it finishes. If the thread is interrupted, the call throws InterruptedException. Use new EtchvClient.Options(filename, idempotencyKey) for media requests. Run the examples below inside the open client’s scope.
Retries and recovery
Embedding and video detection retry and check job status for you. Image and PDF detection do not. Before you upload, save an idempotency key (a value you choose so a retry isn't run twice). With it, you can recover the request even after your program restarts.
| Situation | Action |
|---|---|
| Client timeout | The accepted job keeps running. Resume it, or resend the same inputs with the same key |
| Resume a job | getEmbedResult( / getDetectionResult( |
| Changed inputs | Use a new key. Reusing a key with different inputs returns 409 |
| Collect a saved result | Within 24 hours. See retention |
- Client timeout
- Action
- The accepted job keeps running. Resume it, or resend the same inputs with the same key
- Resume a job
- Action
getEmbedResult(/requestId) getDetectionResult(requestId)
- Changed inputs
- Action
- Use a new key. Reusing a key with different inputs returns
409
- Collect a saved result
- Action
- Within 24 hours. See retention
Error types and handling
Errors throw EtchvClient.EtchvException, an unchecked exception. It has statusCode(), requestId(), idempotencyKey() and detail(). Status 0 means no response was received. isGone() tells you the status was HTTP 410.
try {
var result = client.getEmbedResult(requestId);
} catch (EtchvClient.EtchvException e) {
if (e.isGone()) {
// Saved result expired or its asset was deleted; retrying does not charge again.
}
log.warn("Etchv failed: status={} requestId={}", e.statusCode(), e.requestId());
}See HTTP errors and retry behavior. When you report a failure, include the request ID.
Asset library
These calls use no credits. Downloads need the assets:read scope, and edits need assets:write. Deleting needs assets:delete and the owner or admin role.
List, edit and download assets
var page = client.listAssets(Map.of("kind", "watermarked", "limit", "25"));
for (var item : page.items()) {
var asset = client.getAsset(item.id());
var updated = client.updateAsset(asset.id(), asset.version(),
Map.of("metadata", Map.of("campaign", "spring")));
if (updated.fileAvailable()) {
byte[] bytes = client.downloadAsset(updated.id());
}
}
// Use nextCursor() with the same filters to continue listing.An edit replaces the metadata and must send the asset's current version. A 409 conflict means the asset changed since you read it, so fetch it again and redo your edit. deleteAsset deletes one asset. deleteAssets deletes 1–50 assets as one action: either all are deleted or none are. Asset fields, filters and retention.
Async jobs and webhooks
To start a job without waiting for the result, call submitEmbed or submitDetection. Set the media type to images, documents or videos. The call returns a JSON receipt.
Check an embedding job with getJob(requestId, false) and a detection job with getJob(requestId, true).
Submit and collect an async job
Read the file into memory before you submit it.
var job = client.submitEmbed("documents", pdfBytes, Map.of("delivery", "delivery_001"),
new EtchvClient.Options("document.pdf", "delivery_001"), webhookId);
String requestId = job.get("request_id").getAsString();
var status = client.getJob(requestId, false); // queued, running, retrying, succeeded, failed
var result = client.getEmbedResult(requestId); // waits while the job is pendingThe webhook is optional. In Java or Rust, pass null or None to skip it. Save the receipt. Job handling.
Manage endpoints and verify webhooks
Methods: createWebhook, listWebhooks, updateWebhook, deleteWebhook, listWebhookDeliveries, redeliverWebhook. Viewing webhooks needs webhooks:read. Managing them needs webhooks:write and the owner or admin role. The signing secret is shown only once, so save it.
boolean valid = EtchvClient.verifyWebhookSignature(rawBody,
request.getHeader("X-Etchv-Timestamp"), request.getHeader("X-Etchv-Signature"), signingSecret);
if (!valid) throw new SecurityException("Invalid webhook signature");
// Then check the body id equals X-Etchv-Event-ID, deduplicate, enqueue work, and return 2xx.verifyWebhookSignature checks the signature and timestamp. Reject an invalid signature. Then check that the event ID in the body matches X-Etchv-Event-ID. Pass the raw request bytes and use a 300-second timestamp tolerance. Then skip events you already handled, queue the work and return 2xx. Verification rules.
GPU processing
On Business or Enterprise plans, pass options.withAccelerator(EtchvClient.Accelerator.GPU). GPU processing uses 3× the credits. If processing falls back to CPU, it uses normal credits. result.accelerator() shows which one was used. See
GPU processing.
Choose where results are stored
Connect your bucket. Then pass its destination ID and, if you like, an object key (the file's path in the bucket). Leave both out to use Etchv storage.
Deliver to your bucket
var job = client.submitEmbed("documents", pdfBytes,
Map.of("recipient", "customer-123"),
new EtchvClient.Options("report.pdf", "report-export-001", destinationId,
"reports/watermarked.pdf"), null);
// After the watermark job reports succeeded:
var delivery = client.getStorageDelivery(job.get("storage_delivery_id").getAsString());After the job succeeds, check the delivery with the storage:read scope. Checking before then returns 404. When the status is stored, download the file with downloadStorageDelivery.
retryStorageDelivery retries a failed or cancelled delivery at no cost. It needs storage:write and the owner or admin role. To manage destinations and deliveries, use createStorageDestination, verifyStorageDestination, updateStorageDestination, deleteStorageDestination, createStorageDelivery. See delivery recovery.