# Solve

> POST /solve solves a task and returns the result.

Source: https://docs.peak.fo/docs/api/solve

`POST https://api.peak.fo/solve`

Sends a task to Peak Solutions and waits for the result. The `task_type` field picks what to solve, and each task page lists the fields it needs.

## Request [#request]

Headers:

| Header         | Value              |
| -------------- | ------------------ |
| `X-API-Key`    | Your API key.      |
| `Content-Type` | `application/json` |

Body fields, for all tasks:

| Field            | Type               | Used by            | Description                                                                                                  |
| ---------------- | ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------ |
| `task_type`      | `string`           | All                | What to solve. Not case-sensitive. See the table below.                                                      |
| `url`            | `string`           | All                | The page with the challenge.                                                                                 |
| `proxy`          | `string`           | All                | Your proxy, as `protocol://user:pass@host:port`. Optional for proxyless tasks. See [Proxies](/docs/proxies). |
| `proxy_type`     | `string`           | All                | Or use proxy parameters: the protocol, such as `http` or `socks5`. Defaults to `http`.                    |
| `proxy_address`  | `string`           | All                | The proxy's host name or IP.                                                                                 |
| `proxy_port`     | `number`, `string` | All                | The proxy's port.                                                                                            |
| `proxy_login`    | `string`           | All                | The proxy username, if it has one.                                                                           |
| `proxy_password` | `string`           | All                | The proxy password, if it has one.                                                                           |
| `sitekey`        | `string`           | Turnstile          | The widget's sitekey.                                                                                        |
| `action`         | `string`           | Turnstile          | The widget's `data-action`, if the page sets one.                                                            |
| `cdata`          | `string`           | Turnstile          | The widget's `data-cdata`, if the page sets one.                                                             |
| `user_agent`     | `string`           | 5-second challenge | The Windows Chrome user-agent your code sends.                                                               |
| `html`           | `string`           | 5-second challenge | The challenge page you already loaded.                                                                       |
| `appId`          | `string`           | All                | Optional. Your app ID, if you build a tool on Peak Solutions. `app_id` also works. See [App IDs](/docs/earn#app-ids). |

Send the proxy either as one `proxy` URL or as the five proxy parameters, not both. If you send both, `proxy` is used. See [Proxies](/docs/proxies#proxy-parameters).

The body can be up to 4 MB.

| `task_type`              | Task                                                     |
| ------------------------ | -------------------------------------------------------- |
| `turnstiletask`          | [Turnstile](/docs/tasks/turnstile)                       |
| `turnstiletaskproxyless` | [Turnstile (Proxyless)](/docs/tasks/turnstile-proxyless) |
| `cloudflare5stask`       | [5-Second Challenge (WAF)](/docs/tasks/cloudflare-5s)    |

## Example [#example]

```bash title="Terminal"
curl https://api.peak.fo/solve \
  -H "X-API-Key: pk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "task_type": "turnstiletask",
    "url": "https://example.com/login",
    "sitekey": "0x4AAAAAAA...",
    "proxy": "http://user:pass@1.2.3.4:8080"
  }'
```

## Response [#response]

| Field        | Type      | Description                                                        |
| ------------ | --------- | ------------------------------------------------------------------ |
| `success`    | `boolean` | `true` if the solve worked.                                        |
| `data`       | `object`  | The result. Its fields depend on the task, see each task page.     |
| `cost`       | `number`  | What the solve was charged, in USD.                                |
| `error`      | `string`  | On failure: what went wrong, in words.                             |
| `error_code` | `string`  | On failure: what went wrong, as a stable [code](/docs/api/errors). |
| `task_id`    | `string`  | The solve's id, when a solve was tried. See below.                 |

```json tab="Success"
{
  "success": true,
  "data": {
    "token": "0.AgAAAB..."
  },
  "cost": 0.0009,
  "task_id": "5f0c2b1e-8a4d-4c3e-9b7a-2d6e1f4a8c90"
}
```

```json tab="Failed solve"
{
  "success": false,
  "error": "Challenge was flagged - try using a different proxy with a cleaner IP reputation",
  "error_code": "challenge_flagged",
  "task_id": "5f0c2b1e-8a4d-4c3e-9b7a-2d6e1f4a8c90"
}
```

```json tab="Rejected request"
{
  "success": false,
  "error": "Missing required fields: sitekey, url, proxy",
  "error_code": "missing_fields"
}
```

- **Failed solve:** HTTP `200`. Peak Solutions tried and couldn't solve it. Not charged.
- **Rejected request:** a `4xx` or `5xx` status, before any solving. Not charged, and no `task_id`.

### task_id [#task_id]

Every solve that was tried, successful or failed, returns a `task_id`. Keep it:

- If the token or cookies don't work on the site, send it to [`POST /feedback`](/docs/api/feedback).
- When you ask [support](/docs/support) about a solve, include it.

## Errors [#errors]

These can happen on any task:

| `error_code`           | HTTP  | What to do                                                                   |
| ---------------------- | ----- | ---------------------------------------------------------------------------- |
| `invalid_request_body` | `400` | Send valid JSON.                                                             |
| `invalid_task_type`    | `400` | Use a `task_type` from the table above.                                      |
| `missing_fields`       | `400` | Add the fields that `error` lists.                                           |
| `invalid_proxy`        | `400` | Fix the `proxy_` field that `error` names.                                   |
| `request_too_large`    | `413` | Keep the body under 4 MB.                                                    |
| `insufficient_balance` | `402` | [Top up](https://peak.fo/dashboard/topup).                                   |
| `package_exhausted`    | `402` | Renew the package, or use a pay-per-solve key.                               |
| `task_not_authorized`  | `402` | This package key can't solve this task. Check `allowed_tasks`.               |
| `task_blocked`         | `403` | The target is blocked. If `error` says "for trial credits", [top up](https://peak.fo/dashboard/topup) to unlock it. Otherwise [contact support](/docs/support) if that's a mistake. |
| `rate_limited`         | `429` | Wait for `Retry-After`, then retry. See [Rate limits](/docs/api#rate-limits). |
| `task_disabled`        | `503` | The task is turned off for now. Retry later.                                 |

Each task page lists its own solve failures. All codes are on [Error codes](/docs/api/errors).
