SDKs / TypeScript / JavaScript
TypeScript / JavaScript SDK
Package @allvoraz/captcha-ocr, version 1.0.0. Requires Node.js 18+ (global fetch), Deno, Bun or any modern browser; ESM and CommonJS.
Install
The SDK installs straight from our package server, captchaocr.allvoraz.com/sdk, with your usual tools. No public registry account is needed.
# npm / yarn / pnpm
npm install https://captchaocr.allvoraz.com/sdk/npm/allvoraz-captcha-ocr-1.0.0.tgz
yarn add https://captchaocr.allvoraz.com/sdk/npm/allvoraz-captcha-ocr-1.0.0.tgz
pnpm add https://captchaocr.allvoraz.com/sdk/npm/allvoraz-captcha-ocr-1.0.0.tgz
# package.json gets:
# "@allvoraz/captcha-ocr": "https://captchaocr.allvoraz.com/sdk/npm/allvoraz-captcha-ocr-1.0.0.tgz"
# then: import { Configuration, SolveApi } from "@allvoraz/captcha-ocr";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 { readFileSync } from "node:fs";
import { Configuration, SolveApi } from "@allvoraz/captcha-ocr";
const config = new Configuration({
basePath: "https://captchaocr.allvoraz.com",
accessToken: process.env.CAPTCHA_API_KEY,
});
const solver = new SolveApi(config);
const image = readFileSync("captcha.png").toString("base64");
const res = await solver.solve({ solveRequest: { image, numeric: true, length: 6 } });
console.log(res.reliable ? res.text : "refresh the captcha"); // 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.
import { readFileSync } from "node:fs";
import { Configuration, SolveApi } from "@allvoraz/captcha-ocr";
const solver = new SolveApi(new Configuration({ basePath: "http://localhost:8080" }));
const b64 = (path: string) => readFileSync(path).toString("base64");
const batch = await solver.solveBatch({
batchRequest: {
numeric: true, // shared by every image
images: [
{ image: b64("a.png") },
{ image: b64("b.png"), length: 5 }, // per-image override
{ image: b64("sum.png"), math: true },
],
},
});
for (const r of batch.results) console.log(r.reliable ? r.text : `refresh (${r.error ?? "unsure"})`);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.
const task = await solver.submit({ solveRequest: { image, numeric: true, length: 6 } });
// ... do other work ...
const r = await solver.getResult({ taskId: task.id, wait: 10 }); // waits up to 10 s
if (r.status === "ready" && r.result?.reliable) console.log(r.result.text);Or poll without holding the connection:
// Poll without holding the connection.
let r = await solver.getResult({ taskId: task.id });
while (r.status === "processing") {
await new Promise((done) => setTimeout(done, 500));
r = await solver.getResult({ taskId: task.id });
}
console.log(r.status, r.result?.text ?? r.error);Balance
import { AccountApi } from "@allvoraz/captcha-ocr";
const { credits } = await new AccountApi(config).balance();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.
const account = new AccountApi(config);
console.log((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" },
} });
console.log(await account.testAlert()); // sends it now: { delivered: true, status: 200 }
// await 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).
const r = await new AccountApi(config).report({ reportRequest: { id: res.id! } });
console.log(r.refunded, r.reason);Errors
HTTP errors (401 bad key, 402 no credits, 404 unknown task, 422 invalid options, 429 too many concurrent requests, 503 retry later) raise ResponseError (error.response.status). 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