Skip to content

Reduce bandwidth

Set up your agent

Give your coding agent a Steel browser and the Steel skills, so that it browses and writes Steel code the right way. Learn more

Install the Steel CLI. It signs you in and installs the skills for your coding agents.

curl -fsS https://setup.steel.dev | sh

Or send this prompt to your coding agent, and it does the same:

Read https://setup.steel.dev/install.md and follow it to set up Steel for this coding client.
Then continue my requested task using the installed Steel skill.

Set up your agent →

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, 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, Python, Go or Rust.

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:

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

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.

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);
}

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

npx tsx bandwidth.mts
{
  "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:

FieldWhat the session blocks
blockImagesImages.
blockMediaVideo and audio.
blockStylesheetsStylesheets.
blockHostsEvery request to a host in the list, and to its subdomains.
blockUrlPatternsEvery 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:

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

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 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 shows. On a page with images or video, the session that blocks them has the smaller usage.proxy.bytes.

Next steps