logo

How to get the value of a CS2 inventory

To get the value of a CS2 inventory, load every page of the inventory, take the Steam Community Market price of each item, multiply it by the item's amount and add everything up. With the inventory endpoint of Steam API Hub the prices already come with the items, so the whole calculation is one loop over one endpoint. This guide shows it in curl, JavaScript and Python.

What you need

  • An API key from the dashboard with the inventory endpoint activated.
  • The SteamID64 of the account: the 17-digit number that starts with 765611. Custom profile URLs are not resolved, so convert them first.
  • A public inventory. The API can only read inventories that are set to public.

One request first

CS2 has the app id 730. This request returns the first 2000 items with prices in US dollars:

1curl "https://api.steamapihub.com/inventory?appId=730&steamId=76561198000000000&count=2000&currency=USD&apiKey=YOUR_API_KEY"

A shortened response:

1{
2 "status": "OK",
3 "hasMoreItems": false,
4 "lastAssetId": null,
5 "totalInventoryCount": 412,
6 "hiddenItemsOnPage": 3,
7 "visibleItemsOnPage": 409,
8 "data": [
9 {
10 "assetId": "41234567890",
11 "marketHashName": "AK-47 | Redline (Field-Tested)",
12 "amount": 1,
13 "isTradable": true,
14 "isMarketable": true,
15 "lowestSellOrder": 38.52,
16 "highestBuyOrder": 37.9
17 }
18 ]
19}

The fields that matter for the value:

  • lowestSellOrder: the cheapest listing on the Steam Community Market at our last price update, in the requested currency. This is what a buyer pays.
  • highestBuyOrder: the highest buy order on the market. This is what buyers are currently offering, so it is closer to what an instant sale brings.
  • amount: the stack size. It is greater than 1 only for stackable items, but always multiply by it.
  • hasMoreItems and lastAssetId: pagination. Pass lastAssetId as startAssetId to get the next page, until hasMoreItems is false.

Both prices are left out of an item when we have no price for it, for example for items that cannot be sold on the market. Count those separately instead of treating them as zero.

Page size

The count parameter sets how many items one request asks for: at least 75, at most 2000, 75 by default. Use 2000. Each page is one request against your plan's limits, so an inventory of 5000 items costs three requests instead of 67.

JavaScript (Node 18 or newer)

Node 18 ships fetch, so there are no dependencies. Prices are summed in cents to avoid floating point drift.

1const API_URL = "https://api.steamapihub.com/inventory";
2const API_KEY = process.env.STEAMAPIHUB_API_KEY;
3async function getInventoryValue(steamId, currency = "USD") {
4 const params = new URLSearchParams({
5 appId: "730",
6 steamId,
7 count: "2000",
8 currency,
9 apiKey: API_KEY,
10 });
11 let sellCents = 0;
12 let buyCents = 0;
13 let items = 0;
14 let unpriced = 0;
15 let hasMoreItems = true;
16 while (hasMoreItems) {
17 const res = await fetch(`${API_URL}?${params}`);
18 const body = await res.json();
19 if (!res.ok) {
20 throw new Error(`${res.status} ${body.status}: ${body.error}`);
21 }
22 for (const item of body.data) {
23 items += item.amount;
24 if (item.lowestSellOrder === undefined) {
25 unpriced += item.amount;
26 continue;
27 }
28 sellCents += Math.round(item.lowestSellOrder * 100) * item.amount;
29 buyCents += Math.round((item.highestBuyOrder ?? 0) * 100) * item.amount;
30 }
31 hasMoreItems = body.hasMoreItems;
32 if (hasMoreItems) params.set("startAssetId", body.lastAssetId);
33 }
34 return {
35 items,
36 unpriced,
37 sellValue: sellCents / 100,
38 instantSellValue: buyCents / 100,
39 };
40}
41getInventoryValue("76561198000000000").then(console.log);

Python

The same logic with the requests library.

1import os
2import requests
3API_URL = "https://api.steamapihub.com/inventory"
4API_KEY = os.environ["STEAMAPIHUB_API_KEY"]
5def get_inventory_value(steam_id, currency="USD"):
6 params = {
7 "appId": "730",
8 "steamId": steam_id,
9 "count": 2000,
10 "currency": currency,
11 "apiKey": API_KEY,
12 }
13 sell_cents = buy_cents = items = unpriced = 0
14 while True:
15 res = requests.get(API_URL, params=params, timeout=60)
16 body = res.json()
17 if not res.ok:
18 raise RuntimeError(f"{res.status_code} {body.get('status')}: {body.get('error')}")
19 for item in body["data"]:
20 items += item["amount"]
21 sell = item.get("lowestSellOrder")
22 if sell is None:
23 unpriced += item["amount"]
24 continue
25 sell_cents += round(sell * 100) * item["amount"]
26 buy_cents += round(item.get("highestBuyOrder", 0) * 100) * item["amount"]
27 if not body["hasMoreItems"]:
28 break
29 params["startAssetId"] = body["lastAssetId"]
30 return {
31 "items": items,
32 "unpriced": unpriced,
33 "sell_value": sell_cents / 100,
34 "instant_sell_value": buy_cents / 100,
35 }
36print(get_inventory_value("76561198000000000"))

Which number is the value?

There is no single correct value, so the code returns two:

  • sellValue adds up the lowest listings. It answers "what would it cost to buy this inventory on the Steam Market today".
  • instantSellValue adds up the highest buy orders. It is lower, and closer to the money the owner could get right now.

If the inventory has items without a price, report the unpriced count next to the total so nobody reads a partial sum as the full value.

Errors you should handle

  • 403 with "Inventory is private": the owner has hidden the inventory.
  • 404 with "Steam ID not found": the SteamID64 does not exist.
  • 400 with "Invalid steamId" or "Invalid count": the steamId is not 17 characters long, or count is outside 75 to 2000.
  • 403 with "Invalid API key", "No balance" or "Endpoint not activated": a problem with your key or account, see the dashboard.
  • 429 with status TOO_MANY_REQUESTS: you hit the per-minute or per-day limit of your plan.

Every error response has a status and an error field. The examples above throw on every non-2xx answer, which is fine for a script. For handling 429 with retries, see Steam inventory rate limits and HTTP 429 errors.

FAQ

Why is the item count lower than the inventory count?

Steam hides some items from other users, and they are not returned. The response tells you how many: hiddenItemsOnPage per page, and totalInventoryCount for the whole inventory including hidden items.

Can I get the value in euros or another currency?

Yes. Set the currency parameter, for example currency=EUR. The API supports 41 currencies; without the parameter prices are in USD.

Does this work for other games?

Yes. The endpoint works for any Steam game with an inventory: change appId, for example 570 for Dota 2 or 440 for Team Fortress 2. The value logic stays the same.

How many requests does one valuation cost?

One per page. With count=2000 an inventory of up to 2000 items needs a single request.

Further reading