Captcha OCR

SDKs / Dart / Flutter

Dart / Flutter SDK

Package captcha_ocr, version 1.0.0. Requires Dart 3+ (Flutter included).

Install

The SDK installs straight from our package server, captchaocr.allvoraz.com/sdk, with your usual tools. No public registry account is needed.

# pubspec.yaml
dependencies:
  captcha_ocr:
    hosted: https://captchaocr.allvoraz.com/sdk/pub
    version: ^1.0.0

# then
dart pub get        # or: flutter pub get

# or from the command line
dart pub add 'captcha_ocr:{"hosted":"https://captchaocr.allvoraz.com/sdk/pub"}'

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 'dart:convert';
import 'dart:io';

import 'package:captcha_ocr/api.dart';

final client = ApiClient(
  basePath: 'https://captchaocr.allvoraz.com',
  authentication: HttpBearerAuth()..accessToken = Platform.environment['CAPTCHA_API_KEY'],
);
final solver = SolveApi(client);

final image = base64Encode(File('captcha.png').readAsBytesSync());
final res = (await solver.solve(SolveRequest(image: image, numeric: true, length: 6)))!;
if (res.reliable) print(res.text); // 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.

final batch = (await solver.solveBatch(BatchRequest(
  numeric: true, // shared by every image
  images: [
    BatchItem(image: b64('a.png')),
    BatchItem(image: b64('b.png'), length: 5), // per-image override
    BatchItem(image: b64('sum.png'), math: true),
  ],
)))!;
for (final r in batch.results) {
  print(r.reliable ? r.text : 'refresh'); // same order as the request
}

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.
final task = (await solver.submit(SolveRequest(image: image, numeric: true, length: 6)))!;

// ... do other work ...

final r = (await solver.getResult(task.id, wait: 10))!; // waits up to 10 s
if (r.status == TaskResultStatusEnum.ready && r.result!.reliable) print(r.result!.text);

Or poll without holding the connection:

// Poll without holding the connection.
var r = (await solver.getResult(task.id))!;
while (r.status == TaskResultStatusEnum.processing) {
  await Future.delayed(const Duration(milliseconds: 500));
  r = (await solver.getResult(task.id))!;
}

Balance

final credits = (await AccountApi(client).balance())!.credits;

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.

final account = AccountApi(client);
print((await account.balance())!.credits);

// When credits drop below 500, POST this payload to your URL (one alert per account).
await account.setAlert(AlertRequest(
  threshold: 500,
  url: 'https://hooks.example.org/captcha-credits',
  payload: {'text': 'Captcha credits low: {{credits}} left'},
  headers: {'Authorization': 'Bearer my-hook-secret'},
));
final test = (await account.testAlert())!; // sends it now
print('${test.delivered} ${test.status}');
// await account.deleteAlert();            // remove it

Report 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).
final r = await AccountApi(client).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 ApiException (code, message). An undecodable image is not an exception: it's a normal result with error: "invalid_image". See errors.

More