cs2-api 1.0.0

CS2 API client for Rust: Counter-Strike 2 live scores, match results, player stats, teams, rankings (world + VRS), events and skin prices
Documentation
  • Coverage
  • 100%
    61 out of 61 items documented1 out of 51 items with examples
  • Size
  • Source code size: 53.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 911.4 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • achillesscriptsvip

CS2 API for Rust

crates.io docs.rs license

cs2-api is the official Rust client for the CS2 API at cs2-api.org. One blocking client, two small dependencies (ureq with rustls, serde_json), and every Counter-Strike 2 endpoint you need:

  • live CS2 match scores and round-level scoreboards
  • match results, schedules and streams
  • player stats (rating, ADR, KAST, K/D) and leaderboards
  • teams, rosters and head-to-head records
  • the world ranking and Valve Regional Standings (VRS)
  • events, standings and brackets
  • roster transfers
  • CS2 skin prices across 25+ marketplaces, with price history and trending movers

You need a free API key (500 requests/month, no card): Get a free API key

Install

cargo add cs2-api

Or in Cargo.toml:

[dependencies]
cs2-api = "1"

Quickstart

use cs2_api::Client;

fn main() -> Result<(), cs2_api::Error> {
    let cs2 = Client::from_env()?; // reads CITO_API_KEY

    // Every CS2 match being played right now
    for m in cs2.live()?.as_array().into_iter().flatten() {
        println!(
            "{} {}-{} {} on {}",
            m["team1Name"], m["team1Score"], m["team2Score"], m["team2Name"], m["currentMap"]
        );
    }

    let ranking = cs2.world_ranking(10)?;
    let vitality = cs2.team("vitality")?; // roster + recent results
    let donk = cs2.player("donk")?;
    let prices = cs2.skin_prices("ak-47-redline-field-tested-1ab1a2dc")?;
    println!("{ranking}\n{vitality}\n{donk}\n{prices}");
    Ok(())
}

Pass the key directly with Client::new("your-key")?, or set a base URL and timeout:

use std::time::Duration;

let cs2 = cs2_api::Client::builder()
    .api_key("your-key")
    .timeout(Duration::from_secs(10))
    .build()?;
# Ok::<(), cs2_api::Error>(())

Every method returns the data field of the response as a serde_json::Value. get_raw(path, query) returns the whole envelope (success, data, meta) for pagination.

Endpoints

Teams, players and events accept an id or a slug (vitality, donk). Path segments are percent-encoded for you.

Area Methods
Live live(), live_scoreboard(match_id): sides, round, player K/D/ADR, money
Matches upcoming(limit), results(limit), today(), match_by_id(id), match_maps(id), match_player_stats(id), match_streams(id)
Teams team(slug), team_matches(slug, limit), team_stats(slug), team_map_stats(slug), head_to_head(a, b)
Players player(slug), search_players(q, limit), player_stats(slug), player_matches(slug, limit)
Events events(status, limit) ("upcoming", "live", "recent"), event(slug), event_matches(slug), event_standings(slug), event_bracket(slug)
Rankings & stats world_ranking(limit), vrs_ranking(limit), leaderboard(metric, limit), transfers(limit), search(q)
Skins search_skins(q, filters), skin(slug), skin_prices(slug), skin_history(slug, range), trending_skins(timeframe, limit, min_price)
Anything else get(path, query) / get_raw(path, query): any of the 140+ endpoints

Errors

Every call returns Result<Value, cs2_api::Error>:

  • Error::Http { status, code, message }: the API answered with an error (bad key, not found, rate limit)
  • Error::Transport(_): no response (DNS, connection, TLS, timeout)
  • Error::Decode(_): the body was not JSON
  • Error::MissingKey: no key passed and CITO_API_KEY not set

Error implements std::error::Error, so ? works with anyhow, Box<dyn Error> and friends.

Use cases

Keep your key safe

Keep it in an environment variable or a git-ignored .env. If a key leaks, revoke it in your dashboard and create a new one.

Links

Also available for JavaScript (npm) and Python (PyPI).

Not affiliated with Valve, HLTV, ESL, BLAST or PGL. MIT licensed.