ImageToText

ImageToText is a task type for recognizing text CAPTCHAs provided as images.
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>requiredImageToTextTask
body<string>requiredCAPTCHA image encoded in Base64. Send the value as a single line without line breaks.
capMonsterModule<string>optionalName 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>optionalMinimum 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>optionalSpecifies whether character case must be considered during recognition. Possible values: true, false.
numeric<integer>optionalSpecifies whether the CAPTCHA contains digits only.
0 — the CAPTCHA may contain other characters;
1 — the CAPTCHA contains digits only.
math<boolean>optionalSpecifies 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
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.
https://api.capmonster.cloud/getTaskResult
Request example
{
"clientKey":"API_KEY",
"taskId": 407533072
}
Response example
{
"errorId": 0,
"cost": 0.0003,
"status": "ready",
"solution": {
"text": "answer"
}
}
| Property | Type | Description |
|---|---|---|
| text | String | CAPTCHA solution text |
How to get parameters for task creation
Manually
- Open the page with the CAPTCHA in your browser.
- 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:

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.

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.
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.
- JavaScript
- Python
- C#
- Rust
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);
})();
Show code
import requests
import base64
# Image URL
image_url = "https://example/img.jpg"
response = requests.get(image_url)
if response.status_code == 200:
# Convert image binary data to base64
base64_image = base64.b64encode(response.content).decode('utf-8')
print(base64_image)
else:
print("Failed to load image")
Show code
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Image URL
string imageUrl = "https://example/img.jpg";
using (HttpClient client = new HttpClient())
{
try
{
byte[] imageBytes = await client.GetByteArrayAsync(imageUrl);
// Convert image binary data to base64
string base64Image = Convert.ToBase64String(imageBytes);
Console.WriteLine(base64Image);
}
catch (Exception ex)
{
Console.WriteLine("Failed to load image: " + ex.Message);
}
}
}
}
Show code
// https://github.com/CapMonsterCloud/capmonster-rust-captcha-solver
// The example uses direct HTTP requests (reqwest).
// Add to Cargo.toml: reqwest, tokio, base64.
use base64::{engine::general_purpose::STANDARD, Engine};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Image URL
let image_url = "https://example/img.jpg";
let response = reqwest::get(image_url).await?;
if response.status().is_success() {
let bytes = response.bytes().await?;
// binary image data to base64
let base64_image = STANDARD.encode(&bytes);
println!("{base64_image}");
} else {
println!("Failed to load the image");
}
Ok(())
}
Use the SDK library
- JavaScript / TypeScript
- Python
- C#
- Rust
- Go
- PHP
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);
Show code
# https://github.com/CapMonsterCloud/capmonster-python-captcha-solver
import asyncio
import base64
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import ImageToTextRequest
# Import TextModules if you need a specific module
from capmonstercloudclient.requests.enums import TextModules
API_KEY = "YOUR_API_KEY" # Specify your CapMonster Cloud API key
async def solve_image_to_text():
client = CapMonsterClient(
options=ClientOptions(api_key=API_KEY)
)
# Proxies are not required for ImageToTextRequest
base64_body = "your_image_base64"
image_to_text_request = ImageToTextRequest(
image_bytes=base64.b64decode(base64_body),
# Specify additional parameters if necessary
module_name=TextModules.yandex_captcha.value,
threshold=80,
case=True,
numeric=0,
math=False,
)
# You can check your balance if necessary
balance = await client.get_balance()
print("Balance:", balance)
result = await client.solve_captcha(image_to_text_request)
print("Solution:", result)
asyncio.run(solve_image_to_text())
Show code
// https://github.com/CapMonsterCloud/capmonster-dotnet-captcha-solver
using System;
using System.Threading.Tasks;
using Zennolab.CapMonsterCloud;
using Zennolab.CapMonsterCloud.Requests;
class Program
{
static async Task Main(string[] args)
{
// Specify your CapMonster Cloud API key
var clientOptions = new ClientOptions
{
ClientKey = "YOUR_API_KEY"
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
// Proxies are not required for ImageToTextRequest
var imageToTextRequest = new ImageToTextRequest
{
Body = "your_image_base64",
// Specify additional parameters if necessary
CapMonsterModule = "Yandex",
RecognizingThreshold = 80,
CaseSensitive = true,
Numeric = false,
Math = false
};
// You can check your balance if necessary
var balance = await cmCloudClient.GetBalanceAsync();
Console.WriteLine("Balance: " + balance);
var imageToTextResult =
await cmCloudClient.SolveAsync(imageToTextRequest);
Console.WriteLine("Solution: " + imageToTextResult.Solution.Value);
}
}
Show code
For Rust, use the official SDK: crates.io and Github.
// https://github.com/CapMonsterCloud/capmonster-rust-captcha-solver
use capmonstercloud_client::requests::{ImageToTextRequest, TextModule};
use capmonstercloud_client::{CapMonsterClient, ClientOptions};
#[tokio::main]
async fn main() -> capmonstercloud_client::Result<()> {
// Set your CapMonster Cloud API key
let client = CapMonsterClient::new(ClientOptions::new("YOUR_API_KEY"))?;
// Set the path to the captcha image file
let image_bytes = std::fs::read("image.png").expect("failed to read the image");
let request = ImageToTextRequest::new(image_bytes)
// add optional parameters if needed
.with_module_name(TextModule::Yandex)
.with_threshold(80)
.with_case(true)
.with_numeric(false)
.with_math(false);
let solution = client.solve_captcha(&request).await?;
println!("Solution: {solution}");
Ok(())
}
Show code
For Go, use the official SDK: Github.
// https://github.com/CapMonsterCloud/capmonster-go-captcha-solver
package main
import (
"context"
"fmt"
"log"
capmonster "github.com/CapMonsterCloud/capmonster-go-captcha-solver/v2"
)
func main() {
ctx := context.Background()
// Specify your CapMonster Cloud API key
client := capmonster.New("YOUR_API_KEY")
// Proxies are not required for ImageToTextRequest
// Set the path to the captcha image file
imageToTextRequest, err := capmonster.ImageToTextFromFile("image.png")
if err != nil {
log.Fatal(err)
}
// Specify additional parameters if necessary
imageToTextRequest.CapMonsterModule = capmonster.ModuleGoogle
imageToTextRequest.RecognizingThreshold = capmonster.Int(80)
imageToTextRequest.Case = capmonster.Bool(true)
imageToTextRequest.Numeric = capmonster.Bool(false)
imageToTextRequest.Math = capmonster.Bool(false)
// You can check your balance if necessary
balance, err := client.GetBalance(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("Balance:", balance)
solution, err := client.Solve(ctx, imageToTextRequest)
if err != nil {
log.Fatal(err)
}
fmt.Println("Solution:", string(solution))
}
Show code
For PHP, use the official SDK: Github. It requires PHP 8.1+ with the curl and json extensions. Install it with Composer: composer require capmonstercloud/capmonster-client.
<?php
// https://github.com/CapMonsterCloud/capmonster-php-captcha-solver
require 'vendor/autoload.php';
use CapMonsterCloud\CapMonsterClient;
use CapMonsterCloud\ClientOptions;
use CapMonsterCloud\Requests\ImageToTextRequest;
// Import TextModule if you need a specific module
use CapMonsterCloud\Requests\TextModule;
// Specify your CapMonster Cloud API key
$client = new CapMonsterClient(new ClientOptions('YOUR_API_KEY'));
// Proxies are not required for ImageToTextRequest
$request = new ImageToTextRequest(
'your_image_base64',
// Specify additional parameters if necessary
capMonsterModule: TextModule::YANDEX,
recognizingThreshold: 80,
case: true,
numeric: false,
math: false,
);
$solution = $client->solve($request);
print_r($solution);
