Image to text
Summary
| Property | Value |
|---|---|
| v1 type | image.text |
| Compatibility names | ImageToTextTask |
| Proxy | not used |
| Deadline | 60 seconds (starting value). A task not solved by then fails with timeout and is not charged. |
| 2captcha legacy API | method=base64 or method=post (details) |
Parameters
The params object of POST /v1/tasks. Unknown fields are rejected with 422 invalid_params.
| Field | Type | Description |
|---|---|---|
imagerequired | string | Base64-encoded PNG, JPEG, GIF, WebP or BMP image (standard or URL-safe alphabet; a data:image/...;base64, prefix, line breaks and missing padding are accepted). At most 1,000,000 characters, 8192 pixels per side and 8,388,608 pixels in total; animated images at most 1000 frames and 8,388,608 pixels for frames x width x height; multi-picture JPEG (MPO), JPEG with more than 100 scans, malformed or truncated images are rejected. min length 1 · max length 1,000,000 |
case_sensitiveoptional | boolean | The answer is case-sensitive. |
numericoptional | enum | 0 no requirement; 1 digits only; 2 no digits. one of 0, 1, 2 |
phraseoptional | boolean | The answer contains at least one space. |
mathoptional | boolean | The image is an arithmetic expression; the answer is its result. |
min_lengthoptional | integer | Minimum answer length; 0 means no limit. ≥ 0 · ≤ 100 |
max_lengthoptional | integer | Maximum answer length; 0 means no limit. ≥ 0 · ≤ 100 |
Solution
The solution object of a solved task.
| Field | Type | Description |
|---|---|---|
textrequired | string | Recognized text. min length 1 · max length 1,024 |
Example: native API (v1)
Runs as is with a test key (nop_test_…) in the sandbox; use a live key for real tasks.
{ "type": "image.text", "params": { "image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "case_sensitive": false, "numeric": 0 }}export NOPTCHA_KEY=nop_test_... # your test or live key
# waits up to 60 s; 200 = finished (solved or failed), 202 = still processingIDEMPOTENCY_KEY=$(uuidgen) # one key per task you want; a retry of the same request reuses itcurl -s -X POST "https://api.noptcha.com/v1/tasks" \ -H "Authorization: Bearer $NOPTCHA_KEY" \ -H 'Prefer: wait=60' \ -H "Idempotency-Key: $IDEMPOTENCY_KEY" \ -H 'Content-Type: application/json' \ -d @- <<EOF{ "type": "image.text", "params": { "image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "case_sensitive": false, "numeric": 0 }}EOF
# on 202: long-poll with the "id" from the responseTASK_ID=...curl -s "https://api.noptcha.com/v1/tasks/$TASK_ID?wait=60" \ -H "Authorization: Bearer $NOPTCHA_KEY"import osimport timeimport uuid
import requests
API = "https://api.noptcha.com"HEADERS = {"Authorization": f"Bearer {os.environ['NOPTCHA_KEY']}"} # a nop_test_ key runs in the sandbox
# One Idempotency-Key per task you want. If you retry this request after a network error, send the same key and# the same body bytes: you get the same task back, not a second one (see Idempotency on the Tasks page).idempotency_key = str(uuid.uuid4())r = requests.post( f"{API}/v1/tasks", headers={**HEADERS, "Prefer": "wait=60", "Idempotency-Key": idempotency_key}, json={ "type": "image.text", "params": { "image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "case_sensitive": False, "numeric": 0, }, }, timeout=100,)task = r.json()if r.status_code >= 400: raise RuntimeError(f"{task['code']}: {task.get('detail', '')}")while task["status"] == "processing": # 202: not finished within the wait time.sleep(1) # a long poll can return early (for example when wait slots are full) r = requests.get(f"{API}/v1/tasks/{task['id']}", params={"wait": 60}, headers=HEADERS, timeout=100) task = r.json() if r.status_code >= 400: raise RuntimeError(f"{task['code']}: {task.get('detail', '')}")
if task["status"] == "solved": print(task["solution"])else: print("failed:", task["error"]["code"], task["error"]["message"])import { randomUUID } from 'node:crypto';
const API = 'https://api.noptcha.com';const HEADERS = { Authorization: `Bearer ${process.env.NOPTCHA_KEY}` }; // a nop_test_ key runs in the sandbox
async function v1(path, init = {}) { const res = await fetch(`${API}${path}`, { ...init, headers: { ...HEADERS, ...init.headers } }); const data = await res.json(); if (!res.ok) throw new Error(`${data.code}: ${data.detail ?? ''}`); return data;}
// One Idempotency-Key per task you want. If you retry this request after a network error, send the same key and// the same body bytes: you get the same task back, not a second one (see Idempotency on the Tasks page).const idempotencyKey = randomUUID();let task = await v1('/v1/tasks', { method: 'POST', headers: { 'Content-Type': 'application/json', Prefer: 'wait=60', 'Idempotency-Key': idempotencyKey }, body: JSON.stringify({ type: "image.text", params: { image: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", case_sensitive: false, numeric: 0, }, }),});while (task.status === 'processing') { await new Promise((r) => setTimeout(r, 1000)); // a long poll can return early (for example when wait slots are full) task = await v1(`/v1/tasks/${task.id}?wait=60`); // long poll}if (task.status === 'solved') console.log(task.solution);else console.log('failed:', task.error.code, task.error.message);In the sandbox the task is solved at once and solution is:
{ "text": "noptcha"}Compatibility API
| Name | Proxy | Notes |
|---|---|---|
ImageToTextTask | ignored |
Task fields (in task, next to type) and the v1 parameter each one becomes:
| Compatibility field | v1 parameter |
|---|---|
body | image |
case | case_sensitive |
image | image |
math | math |
maxLength | max_length |
minLength | min_length |
numeric | numeric |
phrase | phrase |
Solution fields in getTaskResult:
| Compatibility field | v1 solution field |
|---|---|
text | text |
Example: compatibility API
{ "clientKey": "nop_test_…", "task": { "type": "ImageToTextTask", "body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "case": false, "numeric": 0 }}export NOPTCHA_KEY=nop_test_... # your test or live key
# 1. create the taskcurl -s -X POST "https://api.noptcha.com/createTask" \ -H 'Content-Type: application/json' \ -d @- <<EOF{ "clientKey": "$NOPTCHA_KEY", "task": { "type": "ImageToTextTask", "body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "case": false, "numeric": 0 }}EOF
# 2. poll with the taskId from step 1 every few seconds until "status" is "ready"TASK_ID=...curl -s -X POST "https://api.noptcha.com/getTaskResult" \ -H 'Content-Type: application/json' \ -d @- <<EOF{ "clientKey": "$NOPTCHA_KEY", "taskId": $TASK_ID}EOFimport osimport time
import requests
API = "https://api.noptcha.com"KEY = os.environ["NOPTCHA_KEY"] # a nop_test_ key runs in the sandbox: free, fixed answers
def call(method, payload): r = requests.post(f"{API}/{method}", json={"clientKey": KEY, **payload}, timeout=30) r.raise_for_status() data = r.json() if data["errorId"]: raise RuntimeError(f"{data['errorCode']}: {data.get('errorDescription', '')}") return data
created = call("createTask", {"task": { "type": "ImageToTextTask", "body": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "case": False, "numeric": 0,}})result = created # some types are solved at once and come back with "status": "ready"deadline = time.time() + 300while result.get("status") != "ready": if time.time() > deadline: raise TimeoutError(created["taskId"]) time.sleep(3) result = call("getTaskResult", {"taskId": created["taskId"]})print(result["solution"])const API = 'https://api.noptcha.com';const KEY = process.env.NOPTCHA_KEY; // a nop_test_ key runs in the sandbox: free, fixed answers
async function call(method, payload) { const res = await fetch(`${API}/${method}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientKey: KEY, ...payload }), }); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); if (data.errorId) throw new Error(`${data.errorCode}: ${data.errorDescription ?? ''}`); return data;}
const created = await call('createTask', { task: { type: "ImageToTextTask", body: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", case: false, numeric: 0,} });let result = created; // some types are solved at once and come back with status "ready"const deadline = Date.now() + 300_000;while (result.status !== 'ready') { if (Date.now() > deadline) throw new Error(`timed out: ${created.taskId}`); await new Promise((r) => setTimeout(r, 3000)); result = await call('getTaskResult', { taskId: created.taskId });}console.log(result.solution);In the sandbox getTaskResult returns "status": "ready" and solution:
{ "text": "noptcha"}