SDKs / Java
Java SDK
Package com.allvoraz:captcha-ocr-client, version 1.0.0. Requires Java 11+ (java.net.http client, Jackson).
Install
The SDK installs straight from our package server, captchaocr.allvoraz.com/sdk, with your usual tools. No public registry account is needed.
// Gradle (build.gradle.kts): add our Maven repository, then the dependency
repositories {
mavenCentral()
maven("https://captchaocr.allvoraz.com/sdk/maven")
}
dependencies {
implementation("com.allvoraz:captcha-ocr-client:1.0.0")
}
<!-- Maven (pom.xml) -->
<repositories>
<repository>
<id>allvoraz</id>
<url>https://captchaocr.allvoraz.com/sdk/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.allvoraz</groupId>
<artifactId>captcha-ocr-client</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>Prefer the code itself? Download the source (.zip).
Configure and solve
Create the client once with your API key (from Dashboard → API keys) and reuse it. Submit the answer only when reliable is true. Only reliable answers are charged.
import com.allvoraz.captchaocr.ApiClient;
import com.allvoraz.captchaocr.api.SolveApi;
import com.allvoraz.captchaocr.model.SolveRequest;
import com.allvoraz.captchaocr.model.Solved;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
String key = System.getenv("CAPTCHA_API_KEY");
ApiClient client = new ApiClient()
.setScheme("https").setHost("captchaocr.allvoraz.com").setPort(443)
.setRequestInterceptor(request -> request.header("Authorization", "Bearer " + key));
SolveApi solver = new SolveApi(client);
String image = Base64.getEncoder().encodeToString(Files.readAllBytes(Path.of("captcha.png")));
Solved res = solver.solve(new SolveRequest().image(image).numeric(true).length(6));
if (res.getReliable()) {
System.out.println(res.getText()); // only reliable answers are charged
}Options: numeric, uppercase, lowercase, length, math, hindi. See choosing options.
Batch
Up to 256 images in one call. Top-level options are shared, and each item can override them. Results keep the request order.
SolvedBatch batch = solver.solveBatch(new BatchRequest()
.numeric(true) // shared by every image
.addImagesItem(new BatchItem().image(b64("a.png")))
.addImagesItem(new BatchItem().image(b64("b.png")).length(5)) // per-image override
.addImagesItem(new BatchItem().image(b64("sum.png")).math(true)));
for (Solved r : batch.getResults()) { // same order as the request
System.out.println(r.getReliable() ? r.getText() : "refresh");
}Submit now, fetch later
submit returns a task id immediately and solves in the background. getResult returns processing, then ready with the same answer solve returns (or failed, credit returned). Pass wait (up to 30 s) to hold the call until it's ready.
// Submit: returns a task id at once, the captcha is solved in the background.
Submitted task = solver.submit(new SolveRequest().image(image).numeric(true).length(6));
// ... do other work ...
TaskResult r = solver.getResult(task.getId(), 10); // waits up to 10 s
if (r.getStatus() == TaskResult.StatusEnum.READY && r.getResult().getReliable()) {
System.out.println(r.getResult().getText());
}Or poll without holding the connection:
// Poll without holding the connection (wait = null).
TaskResult r = solver.getResult(task.getId(), null);
while (r.getStatus() == TaskResult.StatusEnum.PROCESSING) {
Thread.sleep(500);
r = solver.getResult(task.getId(), null);
}Balance
long credits = new AccountApi(client).balance().getCredits();Low-balance alert
One alert per account: when a solve leaves your credits below threshold, the service POSTs your payload to your HTTPS url. It fires once and re-arms when you add credits. testAlert sends it now; getAlert and deleteAlert read and remove it. See how alerts work.
AccountApi account = new AccountApi(client);
System.out.println(account.balance().getCredits());
// When credits drop below 500, POST this payload to your URL (one alert per account).
account.setAlert(new AlertRequest()
.threshold(500)
.url("https://hooks.example.org/captcha-credits")
.payload(Map.of("text", "Captcha credits low: {{credits}} left"))
.headers(Map.of("Authorization", "Bearer my-hook-secret")));
AlertTestResult test = account.testAlert(); // sends it now
System.out.println(test.getDelivered() + " " + test.getStatus());
// account.deleteAlert(); // remove itReport a wrong answer
If the site rejected a reliable answer, report its id within 48 hours to get the credit back.
// The site rejected res.getText(): get the credit back (within 48 hours).
ReportResult r = new AccountApi(client).report(new ReportRequest().id(res.getId()));Errors
HTTP errors (401 bad key, 402 no credits, 404 unknown task, 422 invalid options, 429 too many concurrent requests, 503 retry later) raise ApiException (getCode(), getResponseBody()). An undecodable image is not an exception: it's a normal result with error: "invalid_image". See errors.
More
- Source code and full reference (every class and model)
- API guide · API reference