Skip to main content
Are you experiencing issues obtaining the token?
Contact support

ImageToText

ImageToText is a task type for recognizing text CAPTCHAs provided as images.

Attention!

Proxy servers are not required for this task.

Request parameters


IMPORTANT: retrieve the Base64 image immediately before creating the task to avoid solving errors (see the example below for obtaining a CAPTCHA image in Base64 format).


type<string>required

ImageToTextTask


body<string>required

CAPTCHA image encoded in Base64. Send the value as a single line without line breaks.


capMonsterModule<string>optional

Name of the module used to recognize the CAPTCHA.
Examples: yandex, special.
For the list of available modules and an alternative way to pass the module name, see Passing the module name.


recognizingThreshold<integer>optional

Minimum confidence threshold for the recognition result. Allowed values: from 0 to 100.
If the system confidence is below the specified value, the task ends with the ERROR_CAPTCHA_UNSOLVABLE error and no charge is applied.
For details, see Recognition confidence threshold.


case<boolean>optional

Specifies whether character case must be considered during recognition. Possible values: true, false.


numeric<integer>optional

Specifies whether the CAPTCHA contains digits only.
0 — the CAPTCHA may contain other characters;
1 — the CAPTCHA contains digits only.


math<boolean>optional

Specifies whether the mathematical operation shown in the image must be calculated.
false — no mathematical operation is required;
true — calculate the expression. For example, 2 + 6 returns 8.

Important: Do not use the math: true parameter for the captcha_math module.


Base64 is a way to represent binary data in text format.

Below is an example of obtaining a CAPTCHA image in Base64 format using the console in Developer Tools:

const captchaUrl = 'https://example.com/captcha.jpg';

function loadAndEncodeCaptchaToBase64(url) {
fetch(url)
.then(response => response.blob())
.then(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);

reader.onloadend = function() {
const base64Data = reader.result;
console.log('Base64 Encoded Captcha:', base64Data);

};
})
.catch(error => {
console.error('Error occurred while loading or encoding the captcha:', error);
});
}

loadAndEncodeCaptchaToBase64(captchaUrl);

Create task method

POST
https://api.capmonster.cloud/createTask

Request example

{
"clientKey": "API_KEY",
"task": {
"type": "ImageToTextTask",
"body": "BASE64_BODY_HERE!"
}
}

Response example

{
"errorId":0,
"taskId":407533072
}

Get task result method

Use the getTaskResult method to get the recognition result. Depending on the service load, the result is usually returned within 300 ms to 6 s.

POST
https://api.capmonster.cloud/getTaskResult

Request example

{
"clientKey":"API_KEY",
"taskId": 407533072
}

Response example

{
"errorId": 0,
"status": "ready",
"solution": {
"text": "answer"
}
}

PropertyTypeDescription
textStringCAPTCHA solution text

How to get parameters for task creation

Manually

  1. Open the page with the CAPTCHA in your browser.
  2. Open Developer Tools.

base64

Find the CAPTCHA image in the DOM tree. If the image is already represented in Base64 format, its value will be specified in the element attribute:

base64elements

If the image is loaded from a separate URL, open the Network tab, find the corresponding request, right-click it, and select Copy image as data URI. The Base64-encoded image will be copied to the clipboard.

base64network

Automatically

The CAPTCHA image can be obtained programmatically through a browser (including a headless browser such as Playwright) or directly from an HTTP request.

Retrieve the image immediately before creating the task because the CAPTCHA content may change.

Important!

The examples below demonstrate the general approach to obtaining a CAPTCHA image. The exact implementation depends on the website structure, HTML elements, and selectors used.

Show code (for browser)
(async () => {
const img = document.querySelector('img'); // Example selector

const imageUrl = img.src;

const response = await fetch(imageUrl);

if (!response.ok) {
throw new Error("Failed to load image");
}

const buffer = await response.arrayBuffer();

// Convert binary data to base64
const base64Image = btoa(String.fromCharCode(...new Uint8Array(buffer)));

console.log(base64Image);
})();
Show code (Node.js)
(async () => {
const imageUrl = "https://example/img/.jpg"; // Image URL

const response = await fetch(imageUrl);

if (!response.ok) {
throw new Error("Failed to load image");
}

const buffer = await response.arrayBuffer();

// Convert data to base64
const base64Image = Buffer.from(buffer).toString("base64");

console.log(base64Image);
})();

Use the SDK library

Show code (for browser)
// https://github.com/CapMonsterCloud/capmonster-nodejs-captcha-solver

import {
CapMonsterCloudClientFactory,
ClientOptions,
ImageToTextRequest,
// Import CapMonsterModules if you need a specific module
CapMonsterModules
} from "@zennolab_com/capmonstercloud-client";

document.addEventListener("DOMContentLoaded", async () => {

const API_KEY = "YOUR_API_KEY"; // Specify your CapMonster Cloud API key

const client = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: API_KEY })
);

// Proxies are not required for ImageToTextRequest
const imageToTextRequest = new ImageToTextRequest({
body: "your_image_base64",

// Specify additional parameters if necessary
CapMonsterModule: CapMonsterModules.Yandex,
recognizingThreshold: 80,
Case: true,
numeric: 0,
math: false,
});

// You can check your balance if necessary
const balance = await client.getBalance();
console.log("Balance:", balance);

const result = await client.Solve(imageToTextRequest);
console.log("Solution:", result.solution);
});
Show code (Node.js)
// https://github.com/CapMonsterCloud/capmonster-nodejs-captcha-solver

const {
CapMonsterCloudClientFactory,
ClientOptions,
ImageToTextRequest,
// Import CapMonsterModules if you need a specific module
CapMonsterModules,
} = require("@zennolab_com/capmonstercloud-client");

const API_KEY = "YOUR_API_KEY"; // Specify your CapMonster Cloud API key

async function solveImageToText() {
const client = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: API_KEY }),
);

// Proxies are not required for ImageToTextRequest
const imageToTextRequest = new ImageToTextRequest({
body: "your_image_base64",
// Specify additional parameters if necessary
CapMonsterModule: CapMonsterModules.Yandex,
recognizingThreshold: 80,
Case: true,
numeric: 0,
math: false,
});

// You can check your balance if necessary
const balance = await client.getBalance();
console.log("Balance:", balance);

const result = await client.Solve(imageToTextRequest);
console.log("Solution:", result.solution);
}

solveImageToText().catch(console.error);