SDKs / Kotlin
Kotlin SDK
Package com.allvoraz:captcha-ocr-kotlin, version 1.0.0. Requires Kotlin 2.1+ on the JVM (OkHttp 5, Gson).
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-kotlin:1.0.0")
}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.apis.SolveApi
import com.allvoraz.captchaocr.infrastructure.ApiClient
import com.allvoraz.captchaocr.models.SolveRequest
import java.io.File
import java.util.Base64
ApiClient.accessToken = System.getenv("CAPTCHA_API_KEY") // sent as "Authorization: Bearer <key>"
val solver = SolveApi("https://captchaocr.allvoraz.com")
val image = Base64.getEncoder().encodeToString(File("captcha.png").readBytes())
val res = solver.solve(SolveRequest(image = image, numeric = true, length = 6))
if (res.reliable == true) println(res.text) // only reliable answers are chargedOptions: 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.
val batch = solver.solveBatch(
BatchRequest(
numeric = true, // shared by every image
images = listOf(
BatchItem(image = b64("a.png")),
BatchItem(image = b64("b.png"), length = 5), // per-image override
BatchItem(image = b64("sum.png"), math = true),
),
),
)
batch.results.forEach { println(if (it.reliable == true) it.text else "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.
val task = solver.submit(SolveRequest(image = image, numeric = true, length = 6))
// ... do other work ...
val r = solver.getResult(task.id, wait = 10) // waits up to 10 s
if (r.status == TaskResult.Status.ready && r.result?.reliable == true) println(r.result?.text)Or poll without holding the connection:
// Poll without holding the connection.
var r = solver.getResult(task.id)
while (r.status == TaskResult.Status.processing) {
Thread.sleep(500)
r = solver.getResult(task.id)
}Balance
val credits = AccountApi("https://captchaocr.allvoraz.com").balance().creditsLow-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.
val account = AccountApi("https://captchaocr.allvoraz.com")
println(account.balance().credits)
// When credits drop below 500, POST this payload to your URL (one alert per account).
account.setAlert(AlertRequest(
threshold = 500,
url = "https://hooks.example.org/captcha-credits",
payload = mapOf("text" to "Captcha credits low: {{credits}} left"),
headers = mapOf("Authorization" to "Bearer my-hook-secret"),
))
println(account.testAlert()) // sends it now: delivered=true, status=200
// 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.text: get the credit back (within 48 hours).
val r = AccountApi("https://captchaocr.allvoraz.com").report(ReportRequest(id = res.id!!))Errors
HTTP errors (401 bad key, 402 no credits, 404 unknown task, 422 invalid options, 429 too many concurrent requests, 503 retry later) raise ClientException / ServerException (statusCode, response). 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