# Sessions & rotation

A "session" is a way to keep the same residential exit IP across multiple requests. helodata supports two modes; you pick per request via the username.

## Rotating mode (default)

Omit the `session` and `sesstime` segments. Every new TCP connection picks a fresh IP from the matching pool.

```
helo_s1a2b3c4d5e-type-res-region-us
```

When to use:

* One-off page fetches that don't need cookies
* Anti-bot evasion via IP diversity
* Maximum pool diversity for large parallel crawls

Caveat: connection reuse (keep-alive) within a single client may pin you to one IP until the connection closes. If you want literal-per-request rotation, force fresh connections (`Connection: close`).

## Sticky mode

Append both `session-{id}` and `sesstime-{minutes}`. Requests sharing the same combined username re-use the same exit IP for up to `sesstime` minutes.

```
helo_s1a2b3c4d5e-type-res-region-us-session-job1-sesstime-30
```

| Constraint                   | Value                                                            |
| ---------------------------- | ---------------------------------------------------------------- |
| Max `sesstime` (residential) | 30 minutes                                                       |
| Session ID character set     | `[a-z0-9]`, max 32 chars                                         |
| IP guarantee                 | best-effort — sessions can be re-pinned if the upstream IP drops |
| Session expiry               | first request starts the timer                                   |

When to use:

* Multi-step flows (login → search → checkout)
* Sites that bind anti-bot signals to IP across a few minutes
* Tests where you need response reproducibility

## Concurrency under sticky

Two requests with the same `session_id` but **different** other parameters (different geo, different sub-user) are treated as **separate sessions**. The whole username string is the session key, not just the ID.

So this:

```
helo_s1a2b3c4d5e-type-res-region-us-session-abc-sesstime-30
helo_s1a2b3c4d5e-type-res-region-de-session-abc-sesstime-30
```

…opens two unrelated sessions, one in the US and one in DE.

## Recovering from a dropped session

If your session's upstream IP drops mid-flight, the next request with the same username returns a fresh IP and the timer restarts. You'll see this in the response header:

```
X-Helodata-Session-Repinned: true
```

Watch for this header in long-running flows and consider re-establishing client state (cookies, fingerprint) when it appears.

## Patterns

### Pool of N concurrent sessions

```python
import requests, itertools, random, string

BASE = "helo_s1a2b3c4d5e-type-res-region-us"

def session_user(n):
    sid = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
    return f"{BASE}-session-{sid}-sesstime-10"

users = [session_user(i) for i in range(20)]      # 20 sticky sessions

def get(url, user):
    proxy = f"http://{user}:PASSWORD@gate.helodata.io:7777"
    return requests.get(url, proxies={"http": proxy, "https": proxy}, timeout=30)
```

Rotate `users` round-robin across your workers.

### Burn-and-replace

Track failed requests per session ID. When error rate per session crosses a threshold (e.g. 3 failures in 60s), discard that session ID and mint a new one.

## What sessions do **not** do

* They don't extend traffic credits — bandwidth is still billed per byte.
* They don't carry cookies, headers, or TLS fingerprints — that's your client's job.
* They don't guarantee a specific IP — only IP **stability** for the session window.

## Related

* [ASN targeting](/products/overview/asn-targeting.md) — combine with sessions to keep the same ISP throughout
* [Locations](/products/overview/locations.md) — geo segments must match across requests to share a session
* [407 errors](/troubleshooting/407.md) — common if session syntax is malformed


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.helodata.com/products/overview/sessions-and-rotation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
