Captcha OCR

SDKs / C# / .NET

C# / .NET SDK

Package Allvoraz.CaptchaOcr, version 1.0.0. Requires .NET 8+.

Install

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

# Add our NuGet feed once, then the package
dotnet nuget add source https://captchaocr.allvoraz.com/sdk/nuget/index.json --name allvoraz
dotnet add package Allvoraz.CaptchaOcr --version 1.0.0

# Or in NuGet.config:
#   <add key="allvoraz" value="https://captchaocr.allvoraz.com/sdk/nuget/index.json" />
# Visual Studio: Tools > NuGet Package Manager > Package Sources > add the same URL.

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.

using Allvoraz.CaptchaOcr.Api;
using Allvoraz.CaptchaOcr.Client;
using Allvoraz.CaptchaOcr.Model;

var config = new Configuration
{
    BasePath = "https://captchaocr.allvoraz.com",
    AccessToken = Environment.GetEnvironmentVariable("CAPTCHA_API_KEY"),
};
var solver = new SolveApi(config);

var image = Convert.ToBase64String(File.ReadAllBytes("captcha.png"));
var res = await solver.SolveAsync(new SolveRequest(image: image, numeric: true, length: 6));
if (res.Reliable) Console.WriteLine(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.

var batch = await solver.SolveBatchAsync(new BatchRequest(
    numeric: true, // shared by every image
    images: new List<BatchItem>
    {
        new(image: B64("a.png")),
        new(image: B64("b.png"), length: 5), // per-image override
        new(image: B64("sum.png"), math: true),
    }));

foreach (var r in batch.Results) // same order as the request
    Console.WriteLine(r.Reliable ? r.Text : "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.
var task = await solver.SubmitAsync(new SolveRequest(image: image, numeric: true, length: 6));

// ... do other work ...

var r = await solver.GetResultAsync(task.Id, wait: 10); // waits up to 10 s
if (r.Status == TaskResult.StatusEnum.Ready && r.Result.Reliable) Console.WriteLine(r.Result.Text);

Or poll without holding the connection:

// Poll without holding the connection.
var r = await solver.GetResultAsync(task.Id);
while (r.Status == TaskResult.StatusEnum.Processing)
{
    await Task.Delay(500);
    r = await solver.GetResultAsync(task.Id);
}

Balance

var credits = (await new AccountApi(config).BalanceAsync()).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.

var account = new AccountApi(config);
Console.WriteLine((await account.BalanceAsync()).Credits);

// When credits drop below 500, POST this payload to your URL (one alert per account).
await account.SetAlertAsync(new AlertRequest(
    threshold: 500,
    url: "https://hooks.example.org/captcha-credits",
    payload: new Dictionary<string, object> { ["text"] = "Captcha credits low: {{credits}} left" },
    headers: new Dictionary<string, string> { ["Authorization"] = "Bearer my-hook-secret" }));
var test = await account.TestAlertAsync(); // sends it now
Console.WriteLine($"{test.Delivered} {test.Status}");
// await account.DeleteAlertAsync();       // 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).
var r = await new AccountApi(config).ReportAsync(new ReportRequest(id: res.Id!.Value));

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 (ErrorCode, ErrorContent). An undecodable image is not an exception: it's a normal result with error: "invalid_image". See errors.

More