> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omocaptcha.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ImageToTextTask

> Solve image-based captchas using OCR

A regular captcha is an image containing distorted text that humans can read. To solve the captcha, the user must type the text from the image.

<Frame>
  <img src="https://mintcdn.com/omocaptcha/Jc1mwaiUF23R0W3R/images/image-to-text-captcha-examples.png?fit=max&auto=format&n=Jc1mwaiUF23R0W3R&q=85&s=37ceb86340dad52bd98c03eb7316454d" alt="Common ImageToText captcha examples" width="913" height="503" data-path="images/image-to-text-captcha-examples.png" />
</Frame>

## 1. Create task

### Request

```http theme={null}
POST https://api.omocaptcha.com/v2/createTask
Content-Type: application/json
```

#### Body Parameters

| Parameter          | Type     | Required | Description                    |
| ------------------ | -------- | :------: | ------------------------------ |
| `clientKey`        | `String` |     ✅    | Your account API key           |
| `task.type`        | `String` |     ✅    | Captcha service class name     |
| `task.imageBase64` | `String` |     ✅    | Base64-encoded image           |
| `task.module`      | `String` |     ❌    | Captcha module name (optional) |

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.omocaptcha.com/v2/createTask \
    -H "Content-Type: application/json" \
    -d '{
      "clientKey": "OMO_API_KEY",
      "task": {
        "type": "ImageToTextTask",
        "imageBase64": "BASE64_BODY_HERE",
        "module": "module_1"
      }
    }'
  ```

  ```javascript Node.js theme={null}
  const res = await fetch("https://api.omocaptcha.com/v2/createTask", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      clientKey: "OMO_API_KEY",
      task: {
        type: "ImageToTextTask",
        imageBase64: "BASE64_BODY_HERE",
        module: "module_1"
      }
    })
  });
  console.log(await res.json());
  ```

  ```python Python theme={null}
  import requests

  res = requests.post(
      "https://api.omocaptcha.com/v2/createTask",
      json={
          "clientKey": "OMO_API_KEY",
          "task": {
              "type": "ImageToTextTask",
              "imageBase64": "BASE64_BODY_HERE",
              "module": "module_1"
          }
      }
  )
  print(res.json())
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init("https://api.omocaptcha.com/v2/createTask");
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
      "clientKey" => "OMO_API_KEY",
      "task" => [
          "type" => "ImageToTextTask",
          "imageBase64" => "BASE64_BODY_HERE",
          "module" => "module_1"
      ]
  ]));
  $response = curl_exec($ch);
  echo $response;
  ```
</CodeGroup>

### Response

<CodeGroup>
  ```json Success theme={null}
  {
    "errorId": 0,
    "taskId": "49f9f60a-c809-4af0-93c0-0409b72e67e0"
  }
  ```

  ```json Error theme={null}
  {
    "errorId": 1,
    "errorCode": "",
    "errorDescription": ""
  }
  ```
</CodeGroup>

* Server returns `errorId = 0` and `taskId` → success
* Server returns `errorId = 1` with `errorCode` → error (see [Error Codes](/en/api/error-codes))

## 2. Retrieve the result

### Request

```http theme={null}
POST https://api.omocaptcha.com/v2/getTaskResult
Content-Type: application/json
```

```json theme={null}
{
  "clientKey": "OMO_API_KEY",
  "taskId": "49f9f60a-c809-4af0-93c0-0409b72e67e0"
}
```

### Response

<CodeGroup>
  ```json Success theme={null}
  {
    "errorId": 0,
    "status": "ready",
    "solution": {
      "text": "ABC"
    }
  }
  ```

  ```json Processing theme={null}
  {
    "status": "processing",
    "errorId": 0,
    "errorCode": "",
    "errorDescription": ""
  }
  ```

  ```json Failed theme={null}
  {
    "errorId": 1,
    "errorCode": "ERROR_JOB_STATUS",
    "errorDescription": "Job failed",
    "status": "fail",
    "solution": {}
  }
  ```
</CodeGroup>

* `errorId = 0` & `status = "ready"` → read the result from `solution.text`
* `errorId = 0` & `status = "processing"` → job in progress, **wait 2 seconds** and retry
* `errorId = 1` → failed, check `errorCode` in [Error Codes](/en/api/error-codes)
