Skip to content

Image to text

Send a text captcha image as Base64 and get back the letters and digits in it (solution.text). ImageToTextTaskOcrBase costs 2 points (¥0.002) per image and is synchronous: a single createTask request returns the result. If you need options such as case sensitivity, digits only or math, use the asynchronous ImageToTextTask.

POSThttps://api.yescaptcha.com/createTaskGlobal endpoint
POSThttps://cn.yescaptcha.com/createTaskChina endpoint

The request body is JSON authenticated with your clientKey.

Task typePriceModeNotes
ImageToTextTaskOcrBase2 points (¥0.002)Synchronous
ImageToTextTaskMuggle2 points (¥0.002)SynchronousDoes not support case/numeric options; use project_name to select a custom model
ImageToTextTask4 points (¥0.004)Asynchronous
ImageToTextTaskM115 points (¥0.015)Asynchronous
You need Use
Ordinary alphanumeric captchas, cheapest and fastest ImageToTextTaskOcrBase, ImageToTextTaskMuggle (synchronous)
A model trained for you ImageToTextTaskMuggle with project_name
Case sensitivity, digits only, math, length limits ImageToTextTask, ImageToTextTaskM1 (asynchronous)

The types use different models and routes, so results on the same kind of image may differ; test them and pick the best.

FieldTypeRequiredDescription
typestringYesTask type; see "Task types and pricing" on this page
bodystringYesBase64-encoded image without the data:image/...;base64, prefix and without line breaks
project_namestringNoName of a custom model, supported only by ImageToTextTaskMuggle. Omit to use the general alphanumeric model. Contact support for a custom model (ImageToTextTaskMuggle only)
phrasebooleanNotrue means the answer contains at least one space (ImageToTextTask, ImageToTextTaskM1 only)
casebooleanNotrue means the answer is case-sensitive (ImageToTextTask, ImageToTextTaskM1 only)
numericintegerNo0 no requirement; 1 digits only; 2 no digits (ImageToTextTask, ImageToTextTaskM1 only)
mathbooleanNotrue means the image is a math expression and the answer is its result (ImageToTextTask, ImageToTextTaskM1 only)
minLengthintegerNoMinimum answer length; 0 means no limit (ImageToTextTask, ImageToTextTaskM1 only)
maxLengthintegerNoMaximum answer length; 0 means no limit (ImageToTextTask, ImageToTextTaskM1 only)

body is the Base64 of the image file, without a data:image/...;base64, prefix and without line breaks. WebP images are converted automatically.

POST https://api.yescaptcha.com/createTask
{
"clientKey": "YOUR_CLIENT_KEY",
"task": {
"type": "ImageToTextTaskOcrBase",
"body": "BASE64_IMAGE"
}
}

Complete code (reads captcha.png from the current directory):

终端窗口
# Replace BASE64_IMAGE with the Base64-encoded image
curl -s https://api.yescaptcha.com/createTask \
-H 'Content-Type: application/json' \
-d '{
"clientKey": "YOUR_CLIENT_KEY",
"task": {
"type": "ImageToTextTaskOcrBase",
"body": "BASE64_IMAGE"
}
}'

An asynchronous task with options:

POST https://api.yescaptcha.com/createTask
{
"clientKey": "YOUR_CLIENT_KEY",
"task": {
"type": "ImageToTextTask",
"body": "BASE64_IMAGE",
"case": true,
"numeric": 0,
"minLength": 4,
"maxLength": 6
}
}

Synchronous types return directly from createTask:

{
"errorId": 0,
"status": "ready",
"solution": { "text": "LMResm" },
"taskId": "2376919c-1863-11ec-a012-94e6f7355a0b"
}

Asynchronous types (ImageToTextTask, ImageToTextTaskM1) first return a taskId; poll getTaskResult every 5 seconds until the same solution arrives.

FieldTypeDescription
textstringThe recognized text

The general model works on any alphanumeric captcha but is slightly less accurate than a model trained for one style. If your images always look the same, contact support for a custom model and then select it with ImageToTextTaskMuggle and project_name.

Synchronous types are charged whenever a result is returned, even if it is wrong. Compare other types or ask for a custom model.

I get ERROR_ZERO_CAPTCHA_FILESIZE or ERROR_PARSE_IMAGE_FAIL

Section titled “I get ERROR_ZERO_CAPTCHA_FILESIZE or ERROR_PARSE_IMAGE_FAIL”

The Base64 is incomplete, or contains a data: prefix or line breaks. Check the encoding; see Error codes.