# Proxies

> The proxy format, which protocols work, and when you need a sticky session.

Source: https://docs.peak.fo/docs/proxies

## Format [#format]

Send the proxy as one URL in the `proxy` field:

```txt
protocol://user:pass@host:port
```

Any proxy protocol works, such as `http`, `https`, `socks4` or `socks5`:

```txt
http://user:pass@1.2.3.4:8080
socks5://user:pass@proxy.example.com:1080
```

Put the username and password in the URL. If they contain special characters such as `@`, `:` or `/`, URL-encode them first.

## Proxy parameters [#proxy-parameters]

If your proxy settings are stored in parts, send them as proxy parameters instead of `proxy`:

| Field            | Type               | Required | Description                                                                      |
| ---------------- | ------------------ | -------- | -------------------------------------------------------------------------------- |
| `proxy_type`     | `string`           | No       | The protocol, such as `http`, `https`, `socks4` or `socks5`. Defaults to `http`. |
| `proxy_address`  | `string`           | Yes      | The host name or IP, such as `1.2.3.4`. No protocol or port.                     |
| `proxy_port`     | `number`, `string` | Yes      | The port, from `1` to `65535`.                                                   |
| `proxy_login`    | `string`           | No       | The username, if the proxy has one.                                              |
| `proxy_password` | `string`           | No       | The password. Needs `proxy_login`.                                               |

```json title="POST https://api.peak.fo/solve"
{
  "task_type": "turnstiletask",
  "url": "https://example.com/login",
  "sitekey": "0x4AAAAAAA...",
  "proxy_type": "socks5",
  "proxy_address": "1.2.3.4",
  "proxy_port": 1080,
  "proxy_login": "user",
  "proxy_password": "pass"
}
```

This is the same as sending `"proxy": "socks5://user:pass@1.2.3.4:1080"`. You don't need to URL-encode the login or password here: Peak Solutions does it for you.

Send either `proxy` or the proxy parameters. If you send both, `proxy` is used.

If the proxy parameters can't make a proxy, the request is rejected with HTTP `400` before any solving, and isn't charged:

| `error_code`     | When                                                                                                                                                      |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `missing_fields` | `proxy_address` or `proxy_port` is missing.                                                                                                               |
| `invalid_proxy`  | The port isn't a number from 1 to 65535, the address has a protocol or port in it, the type isn't a protocol name, or there's a password without a login. |

## Which tasks need one [#which-tasks-need-one]

| Task                                                     | Proxy                                                         |
| -------------------------------------------------------- | ------------------------------------------------------------- |
| [Turnstile](/docs/tasks/turnstile)                       | Required. Peak Solutions solves through it.                   |
| [Turnstile (Proxyless)](/docs/tasks/turnstile-proxyless) | Optional. Peak Solutions uses its own if you don't send one.  |
| [5-Second Challenge (WAF)](/docs/tasks/cloudflare-5s)    | Required, and it must be sticky. The same one your code uses. |

## Sticky sessions [#sticky-sessions]

Many proxy providers give you a new IP on every request unless you ask for a sticky session. With a sticky session, the IP stays the same for a few minutes.

Cloudflare ties the 5-second challenge clearance to the IP that solved it. If your next request comes from a different IP, the cookies stop working and you see the challenge again. So for that task:

- Use a sticky session that lasts at least a few minutes.
- Send the same proxy to Peak Solutions and use it in your own code.


## Picking a proxy [#picking-a-proxy]

The proxy's IP matters more than anything else you send. If you see a lot of `challenge_flagged` or `ip_blocked`:

- Use residential or mobile IPs. Datacenter IPs are flagged far more often.
- Pick a location close to the site's audience.
- Avoid IPs that other people share heavily.

If you see `proxy_error`, check the format above and that the proxy works from your own machine:

```bash title="Terminal"
curl -x "http://user:pass@1.2.3.4:8080" https://example.com
```
