This guide outlines best practices to minimize infrastructure costs while maintaining performance.

Session Management

Reusing Sessions

To optimize your costs, consider reusing browser sessions since there is a one-minute minimum billing period for each session creation. For short tasks, reusing sessions helps avoid multiple minimum charges. For longer workflows, you can disconnect and reconnect to the same session as needed, maintaining efficiency while managing resource usage.

To reuse a session:

  • Store the session ID from your initial session creation

  • Use the sessionId query parameter when connecting to specify the existing session

  • Continue using the same session for similar workloads

Learn more about connecting to sessions here.

Proxy Optimization

Proxy usage can impacts costs. Implement these strategies to minimize proxy-related expenses:

Selective Proxy Usage

Proxies are a powerful tool if you need to access geo-restricted content, have load balancing requirements, or need anonymity, but if those aren’t necessary, avoiding proxies will save on costs.

You can also implement domain specific proxy routing

const proxyConfig = {
  targetDomains: ['example.com', 'target-site.com'],
  bypassDomains: ['static-assets.com', 'cdn.com']
};

Image Loading Optimization

When using proxies, control image loading to reduce bandwidth costs.

Ensure images are disabled for non-visual automation:

await page.setRequestInterception(true);
page.on('request', request => {
  if (request.resourceType() === 'image')
    request.abort();
  else
    request.continue();
});

Use domain filtering to load images selectively.

const shouldLoadImage = (domain) => {
  return proxyConfig.targetDomains.includes(domain);
};

If you’re scaling up and looking for bulk usage discounts, reach out to hello@browserbase.com