---
site: steel.dev
collection: docs
canonical_url: https://steel.dev/docs/sessions/bandwidth
markdown_url: https://steel.dev/docs/sessions/bandwidth.md
content_signal: ai-input=yes, ai-train=yes, search=yes
title: Reduce bandwidth
description: Block ads, images, media, stylesheets, or chosen hosts in a session to load pages faster and use less proxy bandwidth.
summary: Block ads, images, media, stylesheets, or chosen hosts in a session to load pages faster and use less proxy bandwidth.
type: how-to
reviewed: 2026-11-12
prerequisites:
  - https://steel.dev/docs/sessions/lifecycle.md
related:
  - https://steel.dev/docs/sessions/timeouts.md
  - https://steel.dev/docs/sessions/devices.md
  - https://steel.dev/docs/sessions/metadata.md
  - https://steel.dev/docs/sessions/files.md
  - https://steel.dev/docs/sessions/extensions.md
agent_setup: https://setup.steel.dev/install.md
docs_index: https://steel.dev/docs/sitemap.md
---

# Reduce bandwidth

A session can block the parts of a page that your task does not need, such as ads, images and videos, so that pages load faster and less data goes through the proxy. This matters most with [Steel proxies](https://steel.dev/docs/stealth/proxies), because Steel bills them by the bytes that they carry.

## Before you begin

Put your Steel API key in the `STEEL_API_KEY` environment variable, and install the Steel SDK for your language: [TypeScript](https://steel.dev/docs/reference/sdks/typescript#install), [Python](https://steel.dev/docs/reference/sdks/python#install), [Go](https://steel.dev/docs/reference/sdks/go#install) or [Rust](https://steel.dev/docs/reference/sdks/rust#install).

## Block ads

A session blocks ads by default. When the request leaves out `blockAds`, Steel sets it to `true`, and the browser refuses requests to a list of known ad and tracking hosts and their subdomains.

If the task needs those requests, set `blockAds` to `false`:

**TypeScript**

```ts
const session = await client.sessions.create({ blockAds: false });
```

**Python**

```python
session = client.sessions.create(block_ads=False)
```

**Go**

```go
session, err := client.Sessions.New(ctx, steel.SessionNewParams{
	BlockAds: steel.F(false),
})
if err != nil {
	return err
}
```

**Rust**

```rust
let session = client
    .sessions()
    .create(steel_rs::SessionCreateParams {
        block_ads: Some(false),
        ..Default::default()
    })
    .await?;
```

## Turn on bandwidth optimization

Set `optimizeBandwidth` to `true` to block images, media and stylesheets together.

This program creates a session with bandwidth optimization, prints what the session blocks, and releases it.

**TypeScript**

```ts file=bandwidth.mts
import Steel from "steel-sdk";

const client = new Steel();
const session = await client.sessions.create({ optimizeBandwidth: true });

try {
  console.log(JSON.stringify(session.optimizeBandwidth, null, 2));
} finally {
  await client.sessions.release(session.id);
}
```

**Python**

```python file=bandwidth.py
import json

from steel import Steel

client = Steel()
session = client.sessions.create(optimize_bandwidth=True)

try:
    print(json.dumps(session.optimize_bandwidth.to_dict(mode="json"), indent=2))
finally:
    client.sessions.release(session.id)
```

**Go**

```go file=main.go
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	"github.com/steel-dev/sdk/go"
	"github.com/steel-dev/sdk/go/shared"
)

func main() {
	if err := run(context.Background()); err != nil {
		log.Fatal(err)
	}
}

func run(ctx context.Context) error {
	client := steel.NewClient()
	session, err := client.Sessions.New(ctx, steel.SessionNewParams{
		OptimizeBandwidth: steel.F[steel.SessionNewParamsOptimizeBandwidthUnion](shared.UnionBool(true)),
	})
	if err != nil {
		return err
	}
	defer func() {
		if _, err := client.Sessions.Release(ctx, session.ID); err != nil {
			log.Print(err)
		}
	}()

	out, err := json.MarshalIndent(session.OptimizeBandwidth, "", "  ")
	if err != nil {
		return err
	}
	fmt.Println(string(out))
	return nil
}
```

**Rust**

```rust file=src/main.rs
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = steel_rs::Client::new();
    let session = client
        .sessions()
        .create(steel_rs::SessionCreateParams {
            optimize_bandwidth: Some(steel_rs::SessionCreateParamsOptimizeBandwidth::Bool(true)),
            ..Default::default()
        })
        .await?;

    let result: Result<(), Box<dyn std::error::Error>> = async {
        println!(
            "{}",
            serde_json::to_string_pretty(&session.optimize_bandwidth)?
        );
        Ok(())
    }
    .await;

    client.sessions().release(&session.id).await?;
    result
}
```

In Rust, the program also needs `cargo add serde_json`. Run the program:

**TypeScript**

```sh
npx tsx bandwidth.mts
```

**Python**

```sh
python bandwidth.py
```

**Go**

```sh
go run .
```

**Rust**

```sh
cargo run
```

**TypeScript**

```json nocopy
{
  "blockImages": true,
  "blockMedia": true,
  "blockStylesheets": true
}
```

**Python**

```json nocopy
{
  "blockImages": true,
  "blockMedia": true,
  "blockStylesheets": true
}
```

**Go**

```json nocopy
{
  "blockHosts": null,
  "blockImages": true,
  "blockMedia": true,
  "blockStylesheets": true,
  "blockUrlPatterns": null
}
```

**Rust**

```json nocopy
{
  "blockImages": true,
  "blockMedia": true,
  "blockStylesheets": true
}
```

`true` does not block any host or URL pattern. To block those, pass an object, as the next section shows.

## Choose what to block

Pass an object in `optimizeBandwidth` to choose each kind of resource:

| Field | What the session blocks |
| - | - |
| `blockImages` | Images. |
| `blockMedia` | Video and audio. |
| `blockStylesheets` | Stylesheets. |
| `blockHosts` | Every request to a host in the list, and to its subdomains. |
| `blockUrlPatterns` | Every request whose URL matches a pattern in the list. A pattern must match the whole URL, including the query string. `*` matches any characters, and the match ignores case. |

This session keeps stylesheets, and blocks images, media, one analytics host and every `.woff2` font:

**TypeScript**

```ts
const session = await client.sessions.create({
  optimizeBandwidth: {
    blockImages: true,
    blockMedia: true,
    blockHosts: ["analytics.example.com"],
    blockUrlPatterns: ["*.woff2*"],
  },
});
```

**Python**

```python
session = client.sessions.create(
    optimize_bandwidth={
        "block_images": True,
        "block_media": True,
        "block_hosts": ["analytics.example.com"],
        "block_url_patterns": ["*.woff2*"],
    },
)
```

**Go**

```go
session, err := client.Sessions.New(ctx, steel.SessionNewParams{
	OptimizeBandwidth: steel.F[steel.SessionNewParamsOptimizeBandwidthUnion](steel.SessionNewParamsOptimizeBandwidthUnionMember1{
		BlockImages:      steel.F(true),
		BlockMedia:       steel.F(true),
		BlockHosts:       steel.F([]string{"analytics.example.com"}),
		BlockURLPatterns: steel.F([]string{"*.woff2*"}),
	}),
})
if err != nil {
	return err
}
```

**Rust**

```rust
let session = client
    .sessions()
    .create(steel_rs::SessionCreateParams {
        optimize_bandwidth: Some(
            steel_rs::SessionCreateParamsOptimizeBandwidth::UnionMember1(
                steel_rs::SessionCreateParamsOptimizeBandwidthUnionMember1 {
                    block_images: Some(true),
                    block_media: Some(true),
                    block_hosts: Some(vec!["analytics.example.com".to_owned()]),
                    block_url_patterns: Some(vec!["*.woff2*".to_owned()]),
                    ..Default::default()
                },
            ),
        ),
        ..Default::default()
    })
    .await?;
```

The `*` at the end of `*.woff2*` lets the pattern match a font URL with a query string, such as `https://example.com/inter.woff2?v=3`.

Block only what the task does not use:

- If the task takes screenshots, or a model reads the page as an image, keep images.
- If the task depends on the layout, or on whether an element is visible, keep stylesheets.

A session's `proxyBytesUsed` shows how many bytes went through its proxy, and [Session cost](https://steel.dev/docs/production/session-cost) shows the bytes that Steel billed.

## Check that it worked

Run the same task twice on a Steel proxy: once in a session with `optimizeBandwidth` set to `true`, and once in a session without it. After you release both sessions, read their costs with `sessions.cost`, as [Session cost](https://steel.dev/docs/production/session-cost#get-a-session-s-cost) shows. On a page with images or video, the session that blocks them has the smaller `usage.proxy.bytes`.

## Next steps

- [Session cost](https://steel.dev/docs/production/session-cost): Read how much proxy bandwidth a session used, and what it cost.
- [Proxies](https://steel.dev/docs/stealth/proxies): Choose a proxy for the sessions that need one.
