# Residential Proxies Proxy Sessions

Source: https://docs.evomi.com/proxy-instructions/residential-proxies/proxy-sessions/

By default, each request to our proxy server generates a new IP address. However, you can use session parameters to maintain the same IP address for multiple requests. This feature is useful for tasks that require a stable connection, such as web resources with session-based authentication.

![Sticky Session Demo](/images/session-demo.gif)

## Session Parameters

We offer two types of session parameters: `session` and `hardsession`. Both ensure you keep the same IP for all following requests, but they have different behaviors and use cases.

### The `session` parameter

- A unique alphanumeric string, 6 to 10 characters long.
- Optimized for the highest overall success rate.
- May change IP address in favor of stability.
- Works with the `lifetime` parameter.

### The `hardsession` parameter

- Also a unique alphanumeric string, 6 to 10 characters long.
- Prioritizes IP address longevity.
- Keeps the same IP for as long as possible.
- Does not work with the `lifetime` parameter.

When specifying any geo or ISP targeting parameters, the first request will use the specified parameters, and all subsequent requests will use the same IP address. If you change the targeting while maintaining the same session, the IP address will remain the same.

### The `lifetime` parameter

- Specifies the duration for the `session` in minutes.
- If not specified, the session will last for 30 minutes by default.
- Maximum value is 1440 minutes, which is 24 hours.
- After the specified time, the IP address will change.
- Does not apply to `hardsession`.

If you specify a higher `lifetime` value than the maximum allowed, the request will return a 412 error code.

## Examples

Below are examples of using Sticky sessions in different programming languages: CURL, Python, and JavaScript.

#### CURL

  ```bash
curl -x http://rp.evomi.com:1000 -U testuser:testpassword_country-US_session-sgn34f3e_lifetime-10 https://ip.evomi.com/s
curl -x http://rp.evomi.com:1000 -U testuser:testpassword_country-US_hardsession-JS9nsq2n https://ip.evomi.com/s
```

#### Python

  ```Python

import requests

proxy_pass = "testpassword_country-US_session-sgn34f3e_lifetime-10"
proxy_url = f"http://testuser:{proxy_pass}@rp.evomi.com:1000"

proxies = {
  "http": proxy_url,
  "https": proxy_url,
}
response = requests.get("https://ip.evomi.com/s", proxies=proxies)
print(response.text)

proxy_pass = "testpassword_country-US_hardsession-JS9nsq2n"
proxy_url = f"http://testuser:{proxy_pass}@rp.evomi.com:1000"

proxies = {
  "http": proxy_url,
  "https": proxy_url,
}
response = requests.get("https://ip.evomi.com/s", proxies=proxies)
print(response.text)
```

#### JavaScript

```JavaScript

const fetch = require('node-fetch');

const proxyPass = 'testpassword_country-US_session-sgn34f3e_lifetime-10';
const proxyUrl = `http://testuser:${proxyPass}@rp.evomi.com:1000`;
const url = 'https://ip.evomi.com/s';

fetch(url, { proxy: proxyUrl })
  .then(res => res.text())
  .then(body => console.log(body));

const proxyPass2 = 'testpassword_country-US_hardsession-JS9nsq2n';
const proxyUrl2 = `http://testuser:${proxyPass2}@rp.evomi.com:1000`;
fetch(url, { proxy: proxyUrl2 })
  .then(res => res.text())
  .then(body => console.log(body));
```

Note our easy to use Proxy Generator can generate all this for you.
