Developers / SDKs
Java SDK.
Java 11+, no dependencies. One file. Give it a page address, get the token.
1. Add the client
Save the client as Captora.java in your source folder. It returns the task as JSON, so parse it with the JSON library you already use.
Captora.java
// Captora.java: zero-dependency Captora client for Java 11+ (uses java.net.http).import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;import java.time.Duration;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Captora { private final String apiKey; private final String baseUrl; private final long pollMs; private final long timeoutMs; private final HttpClient http = HttpClient.newHttpClient(); public Captora(String apiKey) { this(apiKey, "https://api.captora.me", 3000, 180000); } public Captora(String apiKey, String baseUrl, long pollMs, long timeoutMs) { this.apiKey = apiKey; this.baseUrl = baseUrl; this.pollMs = pollMs; this.timeoutMs = timeoutMs; } private String request(String method, String path, String jsonBody) throws Exception { HttpRequest.Builder b = HttpRequest.newBuilder(URI.create(baseUrl + path)) .timeout(Duration.ofSeconds(60)) .header("Authorization", "Bearer " + apiKey) .header("Content-Type", "application/json") .header("User-Agent", "captora-java/1.0"); b = jsonBody == null ? b.method(method, HttpRequest.BodyPublishers.noBody()) : b.method(method, HttpRequest.BodyPublishers.ofString(jsonBody)); HttpResponse<String> res = http.send(b.build(), HttpResponse.BodyHandlers.ofString()); if (res.statusCode() >= 400) { throw new RuntimeException("Captora error " + res.statusCode() + ": " + res.body()); } return res.body(); } /** Returns the raw JSON, e.g. {"balance_paise":12345} (100 paise = Rs 1). */ public String balance() throws Exception { return request("GET", "/v1/balance", null); } /** * The simple way: give the address of a page with a captcha. Captora recognises the captcha, solves it, * and returns the full task JSON, which contains "result" (usually the token). If the captcha is added by * JavaScript or the page needs a login, use solveJson with a "html" field instead. */ public String solveUrl(String websiteUrl) throws Exception { String escaped = websiteUrl.replace("\\", "\\\\").replace("\"", "\\\""); return solveJson("/v1/solve", "{\"websiteURL\":\"" + escaped + "\"}"); } /** * Advanced: you already know the captcha type. * jsonBody example: {"type":"recaptcha_v2","websiteURL":"https://example.com","websiteKey":"your_site_key"} */ public String solve(String jsonBody) throws Exception { return solveJson("/v1/tasks", jsonBody); } /** Sends any JSON body to /v1/solve or /v1/tasks, waits for the task, and returns its JSON. */ public String solveJson(String path, String jsonBody) throws Exception { String task = request("POST", path, jsonBody); long deadline = System.currentTimeMillis() + timeoutMs; String id = field(task, "taskId"); String status = field(task, "status"); while ("processing".equals(status) && System.currentTimeMillis() < deadline) { Thread.sleep(pollMs); task = request("GET", "/v1/tasks/" + id, null); status = field(task, "status"); } if ("completed".equals(status)) { return task; } throw new RuntimeException("failed".equals(status) ? "Could not be solved (refunded)" : "Timed out"); } private static String field(String json, String name) { Matcher m = Pattern.compile("\"" + name + "\"\\s*:\\s*\"([^\"]*)\"").matcher(json); return m.find() ? m.group(1) : null; }}2. Solve a captcha with one call
Put your API key in the CAPTORA_API_KEY environment variable (create one in your dashboard).
Example.java
public class Example { public static void main(String[] args) throws Exception { Captora captora = new Captora(System.getenv("CAPTORA_API_KEY")); // Give it the page with the captcha. Captora finds the captcha and solves it. String task = captora.solveUrl("https://example.com/login"); System.out.println(task); // JSON containing result.token }}3. That's it. No captcha type to pick
Captora recognises the captcha on the page. For pages that add it with JavaScript or sit behind a login, pass the page's HTML as well (see the docs). If you already know the type, the client has a second method for that. Every captcha we support, and its price, is on the captchas page.
Keep in mind
- Keep your API key on your server. Never ship it in a browser or mobile app.
- Solving can take from a few seconds to a minute or more, so run it in the background of your app.
- Unsolved tasks raise an error and are refunded automatically.