Cookie usage notification

This site uses cookies. Cookies remember you, so we can provide you with personalized services. Read our privacy policy.

Logo of «GitHub»
  • We support API for «PHP» language
  • We support API for «Python» language
  • We support API for «Go» language
  • We support API for «Ruby» language
  • We support API for «C#» language
  • We support API for «Java» language
  • We support API for «JavaScript» language

Grid Method

Grid

The method can be used to bypass tasks where a grid is applied to an image and you need to click on grid tiles, like reCAPTCHA or hCaptcha images.

Returns the array of tile indexes, where 1 is top left tile.

Supported image formats: JPEG, PNG, GIF
Max file size: 600 kB
Max image size: 1000px on any side

GridTask task type specification

Property Type Required Description
type String Yes GridTask
body String Yes Image encoded into Base64 format. Data-URI format (containing data:content/type prefix) is also supported
rows Integer No Number of grid rows
columns Integer No Number of grid columns
comment String Yes* A comment will be shown to workers to help them to solve the captcha properly
imgInstructions String Yes* An image with instruction that will be shown to workers. Image should be encoded into Base64 format. Max file size: 100 kB
    • you should provide at least one of the properties: comment or imgInstructions

Request example

Method: createTask
API endpoint: https://api.2captcha.com/createTask

{
    "clientKey":"YOUR_API_KEY",
    "task": {
        "type":"GridTask",
        "body":"/9j/4AAQSkZJRgABAQAAAQ..HIAAAAAAQwAABtbnRyUkdCIFhZ.wc5GOGSRF//Z",
        "comment":"select all vehicles",
        "rows": 4,
        "columns": 4
    }
}

Response example

{
    "errorId": 0,
    "status": "ready",
    "solution": {
        "click": [
            4,
            8,
            12,
            16
        ]
    },
    "cost": "0.0012",
    "ip": "1.2.3.4",
    "createTime": 1692863536,
    "endTime": 1692863556,
    "solveCount": 1
}

Code examples

  // https://github.com/2captcha/2captcha-php

  require(__DIR__ . '/../src/autoloader.php');

  $solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');

  try {
      $result = $solver->grid('path/to/captcha.jpg');
  } catch (\Exception $e) {
      die($e->getMessage());
  }

  die('Captcha solved: ' . $result->code);
# https://github.com/2captcha/2captcha-python

import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from twocaptcha import TwoCaptcha

api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')

solver = TwoCaptcha(api_key)

try:
  result = solver.grid('path/to/captcha.jpg')

except Exception as e:
  sys.exit(e)

else:
  sys.exit('solved: ' + str(result))
  // https://github.com/2captcha/2captcha-csharp

  using System;
  using System.Linq;
  using TwoCaptcha.Captcha;

  namespace TwoCaptcha.Examples
  {
      public class GridExample
      {
          public static void Main()
          {
              var solver = new TwoCaptcha("YOUR_API_KEY");
              Grid captcha = new Grid("path/to/captcha.jpg");
              try
              {
                  solver.Solve(captcha).Wait();
                  Console.WriteLine("Captcha solved: " + captcha.Code);
              }
              catch (AggregateException e)
              {
                  Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
              }
          }
      }
  }
  // https://github.com/2captcha/2captcha-java

  package examples;

  import com.twocaptcha.TwoCaptcha;
  import com.twocaptcha.captcha.Grid;

  public class GridExample {
      public static void main(String[] args) {
          TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
          Grid captcha = new Grid("path/to/captcha.jpg");
          try {
              solver.solve(captcha);
              System.out.println("Captcha solved: " + captcha.getCode());
          } catch (Exception e) {
              System.out.println("Error occurred: " + e.getMessage());
          }
      }

  }
  // https://github.com/2captcha/2captcha-go

  package main

  import (
      "fmt"
      "log"
      "github.com/2captcha/2captcha-go"
  )

  func main() {
      client := api2captcha.NewClient("API_KEY")
      cap := api2captcha.Grid{
          File: "/path/to/captcha.jpg",
      }
      code, err := client.Solve(cap.ToRequest())
      if err != nil {
          log.Fatal(err);
      }
      fmt.Println("code "+code)
  }
  require 'api_2captcha'

  client =  Api2Captcha.new("YOUR_API_KEY")

  result = client.grid({ image: 'path/to/captcha.jpg'})
  # OR
  result = client.grid({
  image: 'https://site-with-captcha.com/path/to/captcha.jpg'
  })