Skip to content

Session cost

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 →

After a session ends, Steel computes its cost in US dollars, along with the usage behind the cost. Use the cost to bill your own customers for their sessions, or to find the jobs that cost the most. On Launch and Scale, the cost counts browser time by the second, as your invoice does. Pricing has the rates.

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.

Get a session's cost

Call sessions.cost with the session ID, after you release the session. While the session is live, the call fails with 409:

Session cost is available after the session has been released. Release this session first, then retry once final usage has been written.

For a few seconds after the release, until Steel writes the final usage, the call returns a totalCost of 0. This program creates a session and releases it. Then it reads the cost every 2 seconds until the cost is final: the call no longer fails with 409, and totalCost is more than 0. It stops with an error after 30 seconds, and it prints the cost and usage.

cost.mts
import Steel from "steel-sdk";

const client = new Steel();

async function finalCost(sessionId: string) {
  const deadline = Date.now() + 30_000;
  for (;;) {
    try {
      const cost = await client.sessions.cost(sessionId);
      if (cost.totalCost > 0) return cost;
    } catch (error) {
      if (!(error instanceof Steel.ConflictError)) throw error;
    }
    if (Date.now() > deadline) throw new Error(`The cost of session ${sessionId} is not final after 30 seconds.`);
    await new Promise((resolve) => setTimeout(resolve, 2000));
  }
}

const session = await client.sessions.create();

try {
  console.log(`Created session ${session.id}`);
} finally {
  await client.sessions.release(session.id);
}

const cost = await finalCost(session.id);
console.log("Total cost:", cost.totalCost.toFixed(6));
console.log(JSON.stringify(cost.usage, null, 2));

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

npx tsx cost.mts

The session ran for less than a second, which counts as one second, with no proxy and no CAPTCHA:

Created session ddec3ee7-769e-4b1d-b69b-f19d03d55e44
Total cost: 0.000022
{
  "browser": {
    "value": 1,
    "unit": "second"
  },
  "proxy": {
    "bytes": 0
  },
  "captcha": {
    "solves": 0
  }
}

The response has these fields:

FieldWhat it holds
totalCostThe session's cost in US dollars, exact to the millionth of a dollar. Steel does not round it to whole cents.
currency, unitAlways usd and dollar.
usage.browserThe browser time, in value and unit. On Launch and Scale, the unit is second, and Steel rounds each session's time up to a whole second, as your invoice does. Some older plans use minute. Steel counts no more time than the session's timeout.
usage.proxy.bytesThe bytes that the session sent and received through a Steel proxy. Steel does not count the bytes through your own proxy.
usage.captcha.solvesThe CAPTCHAs that Steel solved in the session.

Steel computes totalCost from the usage in the response: the browser time, proxy bytes and CAPTCHA solves, each at your plan's rate.

To lower a session's cost:

  • Release the session as soon as the work is done, and set inactivityTimeout. See Set timeouts.
  • Block what the task does not need, so that less data goes through the proxy. See Reduce bandwidth.
  • Use a Steel proxy and CAPTCHA solving only in the sessions that need them.

Add up costs across sessions

To add up the cost of one customer or job, tag its sessions with metadata, list them with a metadata filter, and add up their totalCost values. Track cost per customer shows the whole task.

For your whole organization's usage and bill, see Billing and usage.

Check that it worked

Check totalCost against the usage. Multiply each usage value by your plan's rate in Pricing, and add the results. The sum, to the millionth of a dollar, is totalCost. For the program's session, 1 second at Scale's $0.08 per hour gives the 0.000022 that the program prints.

Next steps