# GeeTest

> Solve GeeTest with the NoptCHA API: type geetest, parameters, solution fields, createTask names and runnable examples.

Source: https://noptcha.com/docs/task-types/geetest/

## Summary

| Property | Value |
| --- | --- |
| v1 type | `geetest`  beta  |
| createTask names | `GeeTestTask`, `GeeTestTaskProxyless` |
| Proxy | optional ([Proxies](https://noptcha.com/docs/proxies.md)) |
| Deadline | 120 seconds (starting value). A task not solved by then fails with `timeout` and is not charged. |

> **Beta:** This type works like the others, but its parameters and success rate may still change.

## Parameters

The `params` object of `POST /v1/tasks`. Unknown fields are rejected with `422 invalid_params`.

Give at least one of `challenge`, `version`.

| Field | Type | Description |
| --- | --- | --- |
| `website_url`  required  | `string` |  Full URL of the page that shows the captcha (http or https).  format: uri · pattern: ^\[Hh\]\[Tt\]\[Tt\]\[Pp\]\[Ss\]?:// · min length 8 · max length 4,096  |
| `gt`  required  | `string` |  v3: the gt value. v4: the captcha\_id value.  min length 1 · max length 128  |
| `challenge`  optional  | `string` |  v3 only, required for v3: the challenge value. It changes on every load; fetch a fresh one for each task.  min length 1 · max length 256  |
| `version`  optional  | `enum` |  GeeTest version. Defaults to 3.  one of 3, 4  |
| `api_server_subdomain`  optional  | `string` |  GeeTest API server, if the site uses one other than api.geetest.com.  format: hostname · min length 1 · max length 253  |
| `get_lib`  optional  | `string` |  Path of the GeeTest script the page loads, as a JSON string. Only some sites need it.  min length 1 · max length 4,096  |
| `init_parameters`  optional  | `object` |  v4 only: extra parameters the page passes to initGeetest4. Copy riskType when the page sets it, e.g. {"riskType":"slide"}: without it some v4 challenges are not solved.  |
| `user_agent`  optional  | `string` |  Browser User-Agent.  min length 1 · max length 1,024  |
| `proxy`  optional  | `object` |  Proxy the solver must use. login and password are used in memory only and are never stored or logged.  |
| `proxy.type`  required  | `enum` |  one of "http", "https", "socks4", "socks5"  |
| `proxy.host`  required  | `string` |  IP address or host name. Private and loopback addresses are rejected.  min length 1 · max length 253  |
| `proxy.port`  required  | `integer` |  ≥ 1 · ≤ 65535  |
| `proxy.login`  optional  | `string` |  max length 256  |
| `proxy.password`  optional  | `string` |  max length 256  |

## Solution

The `solution` object of a solved task.

Give at least one of `challenge` + `validate` + `seccode`, `captcha_id` + `lot_number` + `pass_token` + `gen_time` + `captcha_output`.

| Field | Type | Description |
| --- | --- | --- |
| `challenge`  optional  | `string` |  v3: submit with validate and seccode.  min length 1 · max length 1,024  |
| `validate`  optional  | `string` |  v3.  min length 1 · max length 1,024  |
| `seccode`  optional  | `string` |  v3.  min length 1 · max length 1,024  |
| `captcha_id`  optional  | `string` |  v4: submit with lot\_number, pass\_token, gen\_time and captcha\_output.  min length 1 · max length 256  |
| `lot_number`  optional  | `string` |  v4.  min length 1 · max length 1,024  |
| `pass_token`  optional  | `string` |  v4.  min length 1 · max length 4,096  |
| `gen_time`  optional  | `string | integer` |  v4.  |
| `captcha_output`  optional  | `string` |  v4.  min length 1 · max length 16,384  |
| `user_agent`  optional  | `string` |  User-Agent the token was obtained with; use it when submitting the token.  min length 1 · max length 1,024  |

## Example: native API (v1)

Runs as is with a test key (`nop_test_…`) in the [sandbox](https://noptcha.com/docs/sandbox.md); use a live key for real tasks.

POST /v1/tasks

```json
{
  "type": "geetest",
  "params": {
    "website_url": "https://example.com/login",
    "gt": "022397c99c9f646f6477822485f30404",
    "challenge": "7f044f48bc951ecfbfc03842b5e1fe59",
    "version": 3,
    "api_server_subdomain": "api-na.geetest.com",
    "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
  }
}
```

**curl**

```bash
export NOPTCHA_KEY=nop_test_...  # your test or live key

# waits up to 60 s; 200 = finished (solved or failed), 202 = still processing
IDEMPOTENCY_KEY=$(uuidgen)  # one key per task you want; a retry of the same request reuses it
curl -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": "geetest",
  "params": {
    "website_url": "https://example.com/login",
    "gt": "022397c99c9f646f6477822485f30404",
    "challenge": "7f044f48bc951ecfbfc03842b5e1fe59",
    "version": 3,
    "api_server_subdomain": "api-na.geetest.com",
    "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
  }
}
EOF

# on 202: long-poll with the "id" from the response
TASK_ID=...
curl -s "https://api.noptcha.com/v1/tasks/$TASK_ID?wait=60" \
  -H "Authorization: Bearer $NOPTCHA_KEY"
```


**Python**

```python
import os
import time
import 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": "geetest",
        "params": {
            "website_url": "https://example.com/login",
            "gt": "022397c99c9f646f6477822485f30404",
            "challenge": "7f044f48bc951ecfbfc03842b5e1fe59",
            "version": 3,
            "api_server_subdomain": "api-na.geetest.com",
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
        },
    },
    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"])
```


**Node.js**

```js
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: "geetest",
    params: {
      website_url: "https://example.com/login",
      gt: "022397c99c9f646f6477822485f30404",
      challenge: "7f044f48bc951ecfbfc03842b5e1fe59",
      version: 3,
      api_server_subdomain: "api-na.geetest.com",
      user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
    },
  }),
});
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:

```json
{
  "challenge": "NOPTCHA_TEST_TOKEN_7259140378796032",
  "seccode": "NOPTCHA_TEST_VALIDATE|jordan",
  "validate": "NOPTCHA_TEST_VALIDATE"
}
```

## createTask API

| Name | Proxy |
| --- | --- |
| `GeeTestTask` | optional |
| `GeeTestTaskProxyless` | ignored |

Task fields (in `task`, next to `type`) and the v1 parameter each one becomes:

| createTask field | v1 parameter |
| --- | --- |
| `challenge` | `challenge` |
| `geetestApiServerSubdomain` | `api_server_subdomain` |
| `geetestGetLib` | `get_lib` |
| `gt` | `gt` |
| `initParameters` | `init_parameters` |
| `userAgent` | `user_agent` |
| `version` | `version` |
| `websiteURL` | `website_url` |
| `proxyType`, `proxyAddress`, `proxyPort`, `proxyLogin`, `proxyPassword` | `proxy` ([Proxies](https://noptcha.com/docs/proxies.md)) |

Solution fields in `getTaskResult`:

| createTask field | v1 solution field |
| --- | --- |
| `challenge` | `challenge` |
| `validate` | `validate` |
| `seccode` | `seccode` |
| `captcha_id` | `captcha_id` |
| `lot_number` | `lot_number` |
| `pass_token` | `pass_token` |
| `gen_time` | `gen_time` |
| `captcha_output` | `captcha_output` |
| `userAgent` | `user_agent` |

## Example: createTask API

POST /createTask

```json
{
  "clientKey": "nop_test_…",
  "task": {
    "type": "GeeTestTaskProxyless",
    "websiteURL": "https://example.com/login",
    "gt": "022397c99c9f646f6477822485f30404",
    "challenge": "7f044f48bc951ecfbfc03842b5e1fe59",
    "version": 3,
    "geetestApiServerSubdomain": "api-na.geetest.com",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
  }
}
```

**curl**

```bash
export NOPTCHA_KEY=nop_test_...  # your test or live key

# 1. create the task
curl -s -X POST "https://api.noptcha.com/createTask" \
  -H 'Content-Type: application/json' \
  -d @- <<EOF
{
  "clientKey": "$NOPTCHA_KEY",
  "task": {
    "type": "GeeTestTaskProxyless",
    "websiteURL": "https://example.com/login",
    "gt": "022397c99c9f646f6477822485f30404",
    "challenge": "7f044f48bc951ecfbfc03842b5e1fe59",
    "version": 3,
    "geetestApiServerSubdomain": "api-na.geetest.com",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
  }
}
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
}
EOF
```


**Python**

```python
import os
import 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": "GeeTestTaskProxyless",
    "websiteURL": "https://example.com/login",
    "gt": "022397c99c9f646f6477822485f30404",
    "challenge": "7f044f48bc951ecfbfc03842b5e1fe59",
    "version": 3,
    "geetestApiServerSubdomain": "api-na.geetest.com",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
}})
result = created  # some types are solved at once and come back with "status": "ready"
deadline = time.time() + 300
while result.get("status") != "ready":
    if time.time() > deadline:
        raise TimeoutError(created["taskId"])
    time.sleep(3)
    result = call("getTaskResult", {"taskId": created["taskId"]})
print(result["solution"])
```


**Node.js**

```js
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: "GeeTestTaskProxyless",
  websiteURL: "https://example.com/login",
  gt: "022397c99c9f646f6477822485f30404",
  challenge: "7f044f48bc951ecfbfc03842b5e1fe59",
  version: 3,
  geetestApiServerSubdomain: "api-na.geetest.com",
  userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
} });
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`:

```json
{
  "challenge": "NOPTCHA_TEST_TOKEN_7259140378796032",
  "seccode": "NOPTCHA_TEST_VALIDATE|jordan",
  "validate": "NOPTCHA_TEST_VALIDATE"
}
```
