# Proxy Integration

**Browser Swarm** provides flexible proxy integration options, allowing you to route your automation traffic through various proxy types to enhance anonymity, control geolocation, and improve reliability.

***

### 🧰 Proxy Configuration Options

With **Browser Swarm**, you can:

* **Use Built-in Proxies**: Effortlessly route traffic through our managed residential proxies.
* **Bring Your Own Proxies**: Utilize custom HTTP/HTTPS proxies for greater control over network routing.
* **Combine Multiple Proxies**: Set custom routing rules to direct traffic through different proxies based on domain or location.

Proxies are configured when creating a session through the API or SDK.

***

### Example

{% tabs %}
{% tab title="Node.js" %}

```javascript
import { BrowserSwarm } from 'browser-swarm-sdk';

const bs = new BrowserSwarm({ apiKey: process.env.BROWSER_SWARM_API_KEY });

const session = await bs.sessions.create({
  projectId: process.env.BROWSER_SWARM_PROJECT_ID,
  proxies: [
    {
      type: 'custom',
      url: 'http://username:password@proxy.example.com:8080'
    }
  ]
});
```

{% endtab %}

{% tab title="Python" %}

```python
from browser_swarm import BrowserSwarm
import os

bs = BrowserSwarm(api_key=os.environ["BROWSER_SWARM_API_KEY"])

session = bs.sessions.create(
    project_id=os.environ["BROWSER_SWARM_PROJECT_ID"],
    proxies=[
        {
            "type": "custom",
            "url": "http://username:password@proxy.example.com:8080"
        }
    ]
)
```

{% endtab %}
{% endtabs %}

***

### 🌍 Geolocation Control

To simulate browsing from specific locations, you can configure proxies with geolocation settings:

```javascript
proxies: [
  {
    type: 'browserbase',
    geolocation: {
      city: 'New York',
      state: 'NY',
      country: 'US'
    }
  }
]
```

This setup is particularly useful for testing localized content or accessing region-restricted websites.

***

### ⚙️ Advanced Proxy Routing

For more granular control, **Browser Swarm** allows domain-specific proxy routing:

```javascript
proxies: [
  {
    type: 'custom',
    url: 'http://proxy1.example.com:8080',
    domains: ['example.com', 'testsite.com']
  },
  {
    type: 'custom',
    url: 'http://proxy2.example.com:8080',
    domains: ['anothersite.com']
  }
]
```

This configuration directs traffic to specified domains through designated proxies, optimizing performance and reliability.

***

### 📊 Monitoring Proxy Usage

Track your proxy data consumption via the **Browser Swarm Dashboard**, which provides real-time insights into:

* **Data Usage**: Monitor the amount of data transmitted through proxies.
* **Session Metrics**: Analyze session durations, statuses, and resource consumption.
* **Geolocation Distribution**: Visualize traffic distribution across different regions.

Regular monitoring helps in optimizing proxy usage and managing associated costs.

***

### 💡 Best Practices

* **Rotate Proxies**: Regularly change proxies to avoid IP bans and maintain anonymity.
* **Use Residential Proxies**: For higher success rates, especially when dealing with sophisticated anti-bot systems.
* **Monitor Performance**: Keep an eye on proxy response times and success rates to ensure optimal performance.

By effectively integrating proxies into your browser automation workflows, **Browser Swarm** empowers you to navigate the web with enhanced control and reliability.
