Introduction
pygsi is a Python library to interface with CS2’s Game State Integration.
Game State Integration (GSI) is built into Counter-Strike 2. You give CS2 a config file with a URL, and while you play, it sends that URL HTTP POST requests with JSON about the current map, round, and player. pygsi runs the server that receives them. It parses each payload into typed Pydantic models, keeps the latest state for each player it tracks, and compares each payload with the one before to work out what happened, such as a round starting, the bomb going down, or a kill. Then it calls the async handlers you’ve registered for those events.
pygsi is for players, not spectators or observers. CS2 sends observers much more, such as every player’s position and who carries the bomb, but none of it reaches a player’s own client, so pygsi only models what a player’s client sends. You can see what’s missing in Limitations. For the protocol itself, with every field CS2 sends, see the draft CS2 GSI spec.
Who This Book Is For
This book is for Python developers who want their code to react to CS2 games. We assume you’re comfortable with async def and await, but you don’t need to know anything about GSI. Start with Installation and CS2 Setup and the Quick Start, and then read the other chapters in whatever order you need them.
Installation and CS2 Setup
Installing pygsi
You’ll need Python 3.11 or newer. On PyPI the package is called pygsi-cs2, because the name pygsi was already taken, but you import it as pygsi:
pip install pygsi-cs2
# or
uv add pygsi-cs2
The Config File
CS2 looks for GSI config files in its cfg folder when it starts. Any file whose name starts with gamestate_integration_ and ends with .cfg counts. Create one called gamestate_integration_pygsi.cfg in the game/csgo/cfg/ folder of your CS2 install:
| OS | Folder |
|---|---|
| Windows | C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\game\csgo\cfg\ |
| macOS | ~/Library/Application Support/Steam/steamapps/common/Counter-Strike Global Offensive/game/csgo/cfg/ |
| Linux | ~/.steam/steam/steamapps/common/Counter-Strike Global Offensive/game/csgo/cfg/ |
Warning
CS:GO kept these files in
csgo/cfg/, and CS2 doesn’t read that folder anymore. If you installed CS2 in another Steam library folder, look under that folder’ssteamapps/common/instead.
Here’s what goes in the file:
"pygsi"
{
"uri" "http://127.0.0.1:4213"
"timeout" "5.0"
"buffer" "1.0"
"throttle" "1.0"
"heartbeat" "30.0"
"data"
{
"provider" "1"
"player_id" "1"
"player_state" "1"
"player_match_stats" "1"
"map" "1"
"map_round_wins" "1"
"round" "1"
}
}
The uri is where CS2 sends its payloads. Port 4213 is pygsi’s default, and 127.0.0.1 means the server runs on the same machine as the game. If it runs somewhere else, put that machine’s address here.
The four timing settings control how often CS2 sends updates, and they’re all in seconds:
| Setting | Meaning |
|---|---|
timeout | How long CS2 waits for the server to respond. |
buffer | How long CS2 collects changes before it sends them in one payload. |
throttle | The shortest time between two payloads. |
heartbeat | The longest time between two payloads, even when nothing changes. |
Lower buffer and throttle if events arrive too late for what you’re building.
The data block picks which parts of the game state CS2 sends:
| Component | What CS2 sends |
|---|---|
provider | The SteamID of the client that sent the payload |
player_id | The player’s name, SteamID, and team |
player_state | Health, armor, money, flashes, kills this round, and more |
player_match_stats | Kills, assists, deaths, MVPs, and score for the match |
map | The map’s name, mode, and phase, and each team’s score |
map_round_wins | How each round so far was won |
round | The round’s phase, the bomb’s status, and the winning team |
pygsi can’t work without provider, because that’s how it knows whose game a payload came from (see Multiple Players).
CS2 only reads these files when it starts, so restart it after you add or change one.
Your SteamID64
pygsi tracks players by their SteamID64, the 17-digit number that starts with 7656. To find yours, type status in the CS2 console, or look yourself up on steamid.io.
Quick Start
In this chapter, we’ll write a script that prints a line when a round starts or ends, when we get a kill, and when we die. We assume you’ve installed pygsi and added the config file from Installation and CS2 Setup.
from pygsi import GSIServer, PlayerMatchStats, PlayerState, RoundState
gsi = GSIServer(player_ids="76561198000000000") # your SteamID64
@gsi.on_round_start
async def round_start(player_id: str, old: RoundState | None, new: RoundState) -> None:
state = gsi.state
if state is not None and state.map is not None:
print(f"Round {state.map.round} started on {state.map.name}")
@gsi.on_round_end
async def round_end(player_id: str, old: RoundState | None, new: RoundState) -> None:
print(f"Round over, {new.winning_team} won")
@gsi.on_local_player_kill
async def kill(
player_id: str, old: PlayerMatchStats | None, new: PlayerMatchStats
) -> None:
print(f"Kill! That's {new.kills} this match")
@gsi.on_local_player_death
async def death(player_id: str, old: PlayerState | None, new: PlayerState) -> None:
print("We died")
gsi.run()
The script starts by creating a GSIServer, which receives the payloads from CS2, and player_ids tells it whose game to follow. It listens on port 4213 unless we pass port=, and the port has to match the uri in the config file.
Each decorator registers an async handler for one event. Every handler gets the SteamID64 of the player the event is about, then old and new, one slice of the game state before and after the payload. Kill handlers get PlayerMatchStats, round handlers get RoundState, and so on. For a few events, like the round start, old is None when pygsi has nothing to compare with yet. Events has the full list.
In round_start, we read gsi.state, the latest full GameState for the player, which we can do anywhere, not only in a handler (see Game State). The last line, gsi.run(), starts the server and blocks until we stop it with Ctrl+C.
Let’s save it as main.py and run it:
python main.py
Now we start CS2 and join a match. Any mode works, including a practice match with bots. pygsi skips warmup, so nothing prints until the match goes live. If nothing shows up after that, check that CS2 was started after the config file was in place, and that the SteamID64 in the script is yours.
The repository’s example/ folder has a longer script that logs every event.
Events
CS2 doesn’t send events. Each payload is a snapshot of the game as it is right now, so pygsi works out the events itself by comparing each payload with the last one it stored for that player. When the round’s phase was freezetime before and is live now, a round has started.
Every event has a decorator on GSIServer, and every handler takes the same three arguments: the player_id the event is about, then old and new, the slice of state before and after the payload. This table lists each event, when it fires, and the type of that slice:
| Event | Fires when | old and new |
|---|---|---|
on_round_start | The round’s phase becomes live | RoundState |
on_round_end | The round’s phase goes from live to over | RoundState |
on_bomb_planted | The bomb becomes planted | RoundState |
on_bomb_defused | The bomb goes from planted to defused | RoundState |
on_bomb_exploded | The bomb goes from planted to exploded | RoundState |
on_map_start | The first live payload of a new map | MapState |
on_map_end | The map’s phase goes from live to gameover | MapState |
on_local_player_kill | The player’s match kills go up | PlayerMatchStats |
on_local_player_assist | The player’s match assists go up | PlayerMatchStats |
on_local_player_mvp | The player’s MVPs go up | PlayerMatchStats |
on_local_player_death | The player’s health drops to 0 | PlayerState |
on_state_update | Every payload pygsi stores | GameState |
The type of old also allows None, but only four events ever pass it: on_round_start, on_bomb_planted, on_map_start, and on_state_update, when pygsi has no earlier state to compare with. The others only fire after a comparison, so their old is always set.
Handlers
A handler is an async def function, and we can register as many of them for one event as we like. Because each decorator hands back the function it was given, we can also stack decorators to have one function handle several events:
from pygsi import GSIServer, RoundState
gsi = GSIServer(player_ids="76561198000000000")
@gsi.on_bomb_defused
@gsi.on_bomb_exploded
async def bomb_done(player_id: str, old: RoundState | None, new: RoundState) -> None:
print(f"The bomb is {new.bomb}")
Here, bomb_done runs when a planted bomb is either defused or explodes, and new.bomb tells us which.
Rounds
A round starts when its phase becomes live, and that’s when on_round_start fires. Usually it’s the end of freeze time, but if we start the script in the middle of a round, the first payload pygsi sees is already live, so the event fires then, with old set to None.
When the phase goes from live to over, on_round_end fires, and new.winning_team tells us who won.
The Bomb
The bomb events fire for every bomb in the player’s match, not only the ones the player plants or defuses. on_bomb_planted fires as soon as round.bomb becomes planted, even on the first payload pygsi sees. The other two are stricter, because they only fire when the payload before had a planted bomb. If pygsi starts after a plant, we won’t hear how that bomb ends.
Maps
pygsi ignores warmup, so on_map_start fires when warmup ends rather than when the map loads. More exactly, it fires on the first live payload pygsi sees for the player, with old set to None, and again on the first live payload of each new map after that, with old set to the map before. A new map is one that comes after a gameover payload, or has a different name, or has fewer rounds played than the last map pygsi stored. That last check catches a player who leaves a match early and joins another, since they never send a gameover payload. If the new match is on the same map and has played at least as many rounds as the old one, pygsi can’t tell them apart.
On a new map, pygsi compares nothing with the old one, so the round and bomb events treat its first payload like the first payload pygsi sees.
At the end of the map, the phase goes from live to gameover, which fires on_map_end with the final score in new. A gameover payload fires nothing else except on_state_update, which runs first, even when other things changed in it.
The Local Player
The kill, assist, and MVP events watch the player’s match totals in PlayerMatchStats, and they fire when one of those goes up. If two kills land in the same payload, we get one event, and new.kills is 2 higher than old.kills. These events compare with the last payload that had the player’s own data in the current map. They never fire on the first one pygsi sees, but they do catch what happened while the player was dead and spectating: an assist or MVP earned then fires as soon as the player’s data comes back, with old set to their stats from before they died.
A death is when health goes from above 0 to exactly 0. on_local_player_death fires once for it and stays quiet while the player is dead.
State Updates
When nothing else fits, we can use on_state_update, which fires for every payload pygsi stores and gets the whole GameState before and after. For example, here’s a handler that prints the player’s money:
from pygsi import GameState
@gsi.on_state_update
async def money(player_id: str, old: GameState | None, new: GameState) -> None:
if new.player is not None:
print(f"${new.player.state.money}")
Game State explains which payloads pygsi stores and which it skips.
Order
One payload can set off several events, like the last kill of a round that also ends the round. In that case, pygsi runs them in this order:
on_state_updateon_map_starton_round_startoron_round_end- The bomb events
- The local player events
Each event finishes before the next one starts. If an event has more than one handler, though, pygsi runs those handlers at the same time with asyncio.gather and waits for all of them. By the time a handler runs, gsi.states already holds the new state.
Game State
A handler only gets one slice of the state, but it often needs more, like a kill handler that wants to know the map. For that, pygsi keeps the latest full state for each player it tracks, and we can read it whenever we like.
Reading State
With one tracked player, we read it from gsi.state, which is None until pygsi stores its first payload:
from pygsi import GSIServer, PlayerMatchStats
gsi = GSIServer(player_ids="76561198000000000")
@gsi.on_local_player_kill
async def kill(
player_id: str, old: PlayerMatchStats | None, new: PlayerMatchStats
) -> None:
state = gsi.state
if state is not None and state.map is not None:
print(f"Kill on {state.map.name}, round {state.map.round}")
A GameState has a map, a round, and a player, and any of them can be None, which is why the handler checks state.map before using it. Types lists every field. When we track more than one player, we use gsi.states instead, which Multiple Players covers.
Which Payloads Count
CS2 sends payloads all the time, including in menus and during warmup. pygsi stores a payload, and runs handlers for it, only when all of these hold:
- It has a
mapblock, so the player is on a map. - Its
provideris one of the players we track. - The map’s phase is
liveorgameover.
Everything else is dropped, and the stored state stays as it was. That includes warmup, the menus, and intermission, the break at halftime. During halftime, gsi.state still shows the last payload from before it.
Note
CS2 counts the rounds already finished in
map.round, and pygsi adds one, so during a round it’s that round’s number, starting at 1. CS2 updates its count as soon as a round is over, though, so once the round’s phase isover, and after the map ends,map.roundis already the number of the round after it.
Spectating After Death
When the tracked player dies, CS2 moves their camera to a teammate, and its payloads start carrying that teammate’s data in the player block. pygsi catches this by comparing the player block’s SteamID with the provider’s, and when they differ, it sets player to None. While the player is dead and spectating, then, state.player is None and the local player events don’t fire, but the map and round keep updating. The same check applies to the gameover payload.
Multiple Players
One server can follow several players at once, with each player running CS2 on their own machine and the same config file pointing them all at that server.
Tracking Several Players
To track more than one player, we pass a list of SteamID64s:
from pygsi import GSIServer, RoundState
gsi = GSIServer(player_ids=["76561198000000001", "76561198000000002"])
@gsi.on_round_end
async def round_end(player_id: str, old: RoundState | None, new: RoundState) -> None:
print(f"{player_id}: round over, {new.winning_team} won")
Warning
Each player’s
urihas to reach the server from their machine.127.0.0.1only works for the player on the machine running the server. Everyone else needs that machine’s address, and the server has to listen on it, which it does by default (seeGSIServer).
Per-Player State
pygsi keeps each player’s state apart from everyone else’s. We get at it through gsi.states, a dictionary from each SteamID64 to that player’s GameState, or to None before their first payload:
for steamid, state in gsi.states.items():
if state is not None and state.player is not None:
print(steamid, state.player.match_stats.kills)
The shortcut gsi.state raises RuntimeError when there’s more than one player, since it can’t know whose state we want.
Routing
To decide whose payload it got, pygsi reads the provider block, which always names the CS2 client that sent it. It doesn’t use the player block, because that switches to someone else when the player dies and spectates (see Spectating After Death). Two tracked players in the same match never mix up their states, then, even when one is watching the other.
Logging and Errors
CS2 stops sending updates to a server that answers with an error, so pygsi always answers with 200 OK, whatever goes wrong. It logs the problem instead, which means the log is where to look when something doesn’t work.
Logs
pygsi logs through Python’s logging module, under the logger name pygsi.server. At the DEBUG level, it also logs every raw payload as indented JSON, which helps when you want to see exactly what CS2 sent:
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("pygsi.server").setLevel(logging.DEBUG)
The payloads are long and arrive often, so the example sends them to their own file.
Errors in Handlers
When a handler raises an exception, pygsi logs it with its traceback and carries on, so the other handlers and events for that payload still run. A payload that isn’t valid JSON, or doesn’t match the models, gets logged and dropped, and the stored state stays as it was.
Slow Handlers
pygsi runs the handlers for a payload before it answers CS2, and CS2 doesn’t send its next payload until it has that answer, which means no new updates arrive while a handler is busy. If the handlers take longer than the timeout in the config file (5 seconds in ours), CS2 counts the request as failed and sends the full state again next time.
Handlers should finish quickly for that reason. When one has slow work to do, like a request to a web API, it can start a task and return right away:
import asyncio
from pygsi import GSIServer, PlayerMatchStats
gsi = GSIServer(player_ids="76561198000000000")
background: set[asyncio.Task[None]] = set()
async def post_kill(kills: int) -> None:
await asyncio.sleep(3) # stands in for a slow request
print(f"Posted {kills} kills")
@gsi.on_local_player_kill
async def kill(
player_id: str, old: PlayerMatchStats | None, new: PlayerMatchStats
) -> None:
task = asyncio.create_task(post_kill(new.kills))
background.add(task)
task.add_done_callback(background.discard)
The background set keeps a reference to each task until it’s done, because asyncio only keeps a weak one, and a task with no other reference can disappear before it finishes.
GSIServer
GSIServer receives payloads from CS2, keeps the state of each tracked player, and runs event handlers. It’s a small FastAPI app with one route, POST /, run by uvicorn.
class GSIServer:
def __init__(
self,
player_ids: str | Sequence[str],
port: int = 4213,
host: str = "0.0.0.0",
) -> None: ...
| Parameter | Default | Meaning |
|---|---|---|
player_ids | The SteamID64 of each player to track, as one string or a sequence of strings. Payloads from other players are dropped. | |
port | 4213 | The port to listen on. It has to match the uri in the CS2 config file. |
host | "0.0.0.0" | The address to listen on. The default listens on every network interface. |
Warning
With the default
host, other machines on your network can send the server payloads too. If CS2 and pygsi run on the same machine, passhost="127.0.0.1".
Properties
player_ids is the frozenset[str] of tracked SteamID64s.
states is a dict[str, GameState | None] from each tracked SteamID64 to that player’s latest state. A player’s value is None until their first stored payload.
state is the latest GameState | None of the only tracked player. It raises RuntimeError when more than one player is tracked.
Methods
run() starts the server with uvicorn.run and blocks until the process is interrupted. uvicorn creates and runs its own event loop, so run() can’t be called from code that’s already inside one.
Event Decorators
Each event has a decorator, such as on_round_start, which registers an async handler and returns it unchanged. A handler takes (player_id: str, old: T | None, new: T) and returns None, where T depends on the event. Events lists every event with its T.
Types
Every type here can be imported from pygsi. The models are Pydantic models, and the enums are StrEnums, so each member equals its string value: RoundPhase.LIVE == "live".
GameState
The full state of one player’s game.
| Field | Type | Meaning |
|---|---|---|
map | MapState | None | The map and the score |
round | RoundState | None | The current round |
player | Player | None | The tracked player, or None when the payload has no data for them, such as while they’re dead and spectating |
MapState
| Field | Type | Meaning |
|---|---|---|
name | str | The map’s name, such as "de_dust2" |
mode | str | The game mode, such as "competitive" |
phase | MapPhase | The map’s phase |
round | int | The number of rounds finished, plus one. During a round, that’s the round’s number. |
team_ct_score | int | Rounds won by CT |
team_t_score | int | Rounds won by T |
round_wins | dict[str, str] | How each round was won, by round number, such as {"1": "ct_win_elimination"}. Empty unless the config has map_round_wins. |
RoundState
| Field | Type | Meaning |
|---|---|---|
phase | RoundPhase | The round’s phase |
bomb | BombStatus | None | The bomb’s status, or None if it isn’t planted |
winning_team | Team | None | The team that won the round, set once the phase is over |
Player
| Field | Type | Meaning |
|---|---|---|
steamid | str | The player’s SteamID64 |
name | str | The player’s name |
team | Team | The player’s team |
activity | Activity | None | What the player is doing in the game client |
state | PlayerState | Health, money, and so on |
match_stats | PlayerMatchStats | Totals for the match |
PlayerState
| Field | Type | Meaning |
|---|---|---|
health | int | Health, from 0 to 100 |
armor | int | Armor, from 0 to 100 |
helmet | bool | Whether the player has a helmet |
flashed | int | How flashed the player is, from 0 to 255 |
smoked | int | How far inside a smoke the player is, from 0 to 255 |
burning | int | How much the player is burning, from 0 to 255 |
money | int | Money |
round_kills | int | Kills this round |
round_killhs | int | Headshot kills this round |
equip_value | int | The total value of the player’s equipment |
PlayerMatchStats
| Field | Type | Meaning |
|---|---|---|
kills | int | Kills this match |
assists | int | Assists this match |
deaths | int | Deaths this match |
mvps | int | MVPs this match |
score | int | Score this match |
Enums
| Enum | Members |
|---|---|
MapPhase | WARMUP ("warmup"), LIVE ("live"), INTERMISSION ("intermission"), GAMEOVER ("gameover") |
RoundPhase | FREEZETIME ("freezetime"), LIVE ("live"), OVER ("over") |
BombStatus | PLANTED ("planted"), DEFUSED ("defused"), EXPLODED ("exploded") |
Team | T ("T"), CT ("CT") |
Activity | PLAYING ("playing"), MENU ("menu"), TEXT_INPUT ("textinput") |
pygsi only stores payloads from live and finished maps (see Game State), so a stored MapState has the phase LIVE or GAMEOVER.
Limitations
This page lists what pygsi doesn’t do. Some of it is CS2’s limit, because the game sends a player less than it sends an observer, and some is pygsi’s own.
What CS2 Doesn’t Send Players
Some GSI components only carry data for spectators and observers, such as casters and tournament tools:
allplayers,allplayers_state,allplayers_match_stats,allplayers_weapons, andallplayers_position, with data on every player in the matchbomb, with the bomb’s position and carrierallgrenades, with every grenade in the airphase_countdowns, with the timers for each phaseplayer_position, with the player’s position
During a match, a player’s own client sends nothing for these, so pygsi doesn’t model them. That also means pygsi can’t say who the player killed, who killed them, or who planted the bomb. The draft CS2 GSI spec lists every component and what CS2 sends for each.
What pygsi Doesn’t Do
- Handlers must be async. There’s no support for plain
defhandlers. run()owns the event loop. It callsuvicorn.run, which creates its own loop and blocks. To share a process with other async code, such as a Discord bot, you have to run pygsi in its own thread.- The config file’s
authblock is ignored. CS2 can send a token with each payload, but pygsi doesn’t check it. Anyone who can reach the server can send it payloads, which is one more reason to bind to127.0.0.1when you can. - Handler signatures aren’t type-checked. The decorators accept any async function, so a handler with the wrong signature only shows up at runtime, as an error in the log.
- Weapons aren’t modeled. CS2 sends a player’s weapons in the
player_weaponscomponent, but pygsi doesn’t read it. - Nothing is saved. State lives in memory and is gone when the process stops.
CS2 Game State Integration Spec
Note
This spec is a draft. It will change as more CS2 payloads are captured and the open items get settled.
Valve has never published a spec for CS2. The only official document is Valve’s CS:GO page, and CS2 kept the same mechanism and config format. This spec takes that page and checks it against payloads CS2 actually sent.
Each fact is tagged with its evidence:
- [V] Valve’s page. It’s written for CS:GO, and the live page blocks automated clients, so it was read through the Internet Archive.
- [C] Payloads captured from CS2, in pygsi’s
tests/fixtures.json. They come from a practice match against bots onde_dust2(provider.version14141), plus one payload from a community server. Thepreviouslyandaddedblocks were stripped before they were saved. [C] also covers what pygsi’s git history records about earlier runs against CS2, cited by commit. - [B] u/Bkid’s Game State Integration: A Very Large and In-Depth Explanation (2019), a detailed write-up built from payloads captured in CS:GO. Much of CS:GO’s GSI carried over unchanged, so it’s the guide where CS2 data is missing, but each [B] fact still needs a CS2 payload to confirm it.
When sources disagree, the captured payloads and pygsi’s tested behavior win, then Valve, then [B]. Anything not confirmed in CS2 is marked open and listed under Open Items. Where [B] covers an open item, it’s the expected answer. Anything that only other GSI implementations suggest is listed as a lead to check, not as a fact.
Structure
These are the keys a payload can have. Fields marked [C] have been seen in a CS2 payload. The others come from Valve’s descriptions of the components.
payload
+-- auth [V] only with an "auth" block in the config
+-- provider [C]
| +-- name, appid, version, steamid, timestamp
+-- map [C]
| +-- mode, name, phase, round, num_matches_to_win_series
| +-- team_ct, team_t
| | +-- score, name, flag, consecutive_round_losses,
| | timeouts_remaining, matches_won_this_series
| +-- round_wins [C] with map_round_wins
| +-- "1", "2", ...
+-- round [C]
| +-- phase, bomb, win_team
+-- player [C]
| +-- steamid, name, observer_slot, team, activity
| +-- clan [V] open
| +-- state [C] with player_state
| | +-- health, armor, helmet, flashed, smoked, burning, money,
| | round_kills, round_killhs, equip_value
| +-- weapons [C] with player_weapons
| | +-- weapon_0, weapon_1, ...
| | +-- name, paintkit, type, state,
| | ammo_clip, ammo_clip_max, ammo_reserve
| +-- match_stats [C] with player_match_stats
| +-- kills, assists, deaths, mvps, score
+-- allplayers, bomb, phase_countdowns, grenades
| [V] observer-only, open
+-- previously [V] old values of what changed
+-- added [V] keys that weren't there before
1. The Config File
CS2 reads every file named gamestate_integration_<name>.cfg in game/csgo/cfg/ when it starts, and sends updates to each one [V][C]. A file saved with a UTF-8 BOM doesn’t load, and the console lists the files that did [V].
Valve’s sample for a player’s own client [V]:
"Console Sample v.1"
{
"uri" "http://127.0.0.1:3000"
"timeout" "5.0"
"buffer" "0.1"
"throttle" "0.5"
"heartbeat" "60.0"
"auth"
{
"token" "CCWJu64ZV3JHDT8hZc"
}
"output"
{
"precision_time" "3"
"precision_position" "1"
"precision_vector" "3"
}
"data"
{
"provider" "1"
"map" "1"
"round" "1"
"player_id" "1"
"player_state" "1"
"player_weapons" "1"
"player_match_stats" "1"
}
}
Endpoint Settings [V]
| Key | Default | Meaning |
|---|---|---|
uri | none | Where the game sends its POST requests. For an https URI, the Steam client uses TLS and validates the server’s certificate. |
timeout | 1.1 s | How long the game waits for a response. After a timeout, the request counts as failed, and the next one sends the full state with no deltas. |
buffer | 0.1 s | After a change, the game collects more changes for this long and reports them together. 0.0 turns buffering off. |
throttle | 1.0 s | The game sends nothing for at least this long after a 2xx response. |
heartbeat | not given | The game sends a request this long after the last 2xx response, even if nothing changed. |
The game expects a 2xx response, and it doesn’t send a new request while one is still in flight [V]. Valve doesn’t say what a non-2xx response does, beyond counting the request as failed. If an endpoint never sees a previously or added block, the game is probably treating every request as failed [V].
auth [V]
Optional. Each field in the config’s auth block is sent to the endpoint as a JSON string field, so the endpoint can check where the payload came from. Valve recommends https when you use it. Open.
output [V]
Optional. Sets how many digits after the decimal point the game sends: precision_time for durations such as countdowns and lifetimes, precision_position for positions, and precision_vector for vectors such as velocity and forward direction.
data Components
Each component turns on one part of the payload. Valve’s list [V]:
| Component | What it adds | Who gets it |
|---|---|---|
provider | The client sending the payload | Everyone |
map | Mode, map, phase, and score | Everyone |
map_round_wins | How each round so far was won | Everyone |
round | Round phase, bomb state, round winner | Everyone |
player_id | Name, SteamID, clan tag, observer slot, team | Everyone |
player_state | Health, armor, flashes, kills this round, and so on | Everyone |
player_weapons | Equipped weapons, ammo, and weapon state | Everyone |
player_match_stats | Kills, assists, deaths, MVPs, score | Everyone |
player_position | Position and forward direction of the spectated player | Observers only |
allplayers_id, allplayers_state, allplayers_match_stats, allplayers_weapons, allplayers_position | The player_* data for every player | Observers only |
bomb | Where the bomb is, who’s carrying it, whether it’s dropped | Observers only |
phase_countdowns | Time left in the current phase, and which phase | Observers only |
allgrenades | Every grenade’s owner, position, velocity, type, lifetime, and effect time | Observers only |
An observer is a client that’s spectating a match, watching GOTV, or watching a demo. A player in a match gets nothing from the observer-only components, which means no bomb timer and no data on other players [V].
2. The Payload
Each request is an HTTP POST with a JSON body. It holds the full current state of every component in the config, plus two blocks computed against the last payload that got a 2xx response [V]:
previouslyholds the old values of the data that changed.addedholds the root fields that are in the new state but weren’t in the old one.
A component with no data at the moment is left out [C]. In the main menu, for example, a payload has provider and a player with only steamid, name, and activity. During warmup, there’s a map but no round [C].
provider [C]
| Field | Type | Seen in CS2 |
|---|---|---|
name | string | "Counter-Strike: Global Offensive", unchanged in CS2 |
appid | int | 730 |
version | int | 14141 |
steamid | string | The SteamID64 of the client that sent the payload. It stays the same while the player spectates someone else. |
timestamp | int | Unix time in seconds |
map [C]
| Field | Type | Seen in CS2 |
|---|---|---|
mode | string | competitive. Other modes are open. |
name | string | de_dust2 |
phase | string | warmup, live, gameover. Valve also lists intermission, for halftime [V], which is open. |
round | int | The number of rounds already finished. It’s 0 in the first round and goes up as soon as a round’s phase becomes over. At gameover it equals the total rounds played. |
num_matches_to_win_series | int | 0 |
team_ct, team_t | object | See below |
round_wins | object | Only with map_round_wins. The keys are round numbers starting at "1". |
Each team object has these fields:
| Field | Type | Seen in CS2 |
|---|---|---|
score | int | Rounds won |
name | string | "CounterTerrorists", "Terrorists" |
flag | string | A country code, such as "us" or "de" |
consecutive_round_losses | int | |
timeouts_remaining | int | 1 |
matches_won_this_series | int | 0 |
name and flag are strings, and the other team fields are ints. The community-server payload has the same shape and types as the practice-match ones [C].
The round_wins values seen so far are ct_win_elimination, t_win_elimination, and t_win_bomb. Other win conditions, such as a defuse or the timer running out, are open.
round [C]
| Field | Type | Seen in CS2 |
|---|---|---|
phase | string | freezetime, live, over |
bomb | string | planted, exploded. Left out until the bomb is planted. Valve also lists defused [V], which is open. |
win_team | string | CT or T. Present once the phase is over. |
player [C]
After the player dies, CS2 fills player with the data of the teammate they’re spectating, while provider.steamid stays theirs. The only way to tell is to compare player.steamid with provider.steamid [C]. Bots have short IDs such as "503", not SteamID64s [C].
| Field | Type | Seen in CS2 |
|---|---|---|
steamid | string | |
name | string | |
observer_slot | int | Present for the local player as well as a spectated teammate, such as 5 and 9. |
team | string | T. CT hasn’t been captured in this field yet, though it appears in round.win_team. |
activity | string | playing, menu. [B] adds textinput, for the console, which is open. |
clan | string | The clan tag [V]. Open. |
player.state, with player_state:
| Field | Type | Seen in CS2 |
|---|---|---|
health | int | 0 to 100 |
armor | int | 0 seen |
helmet | bool | false seen |
flashed | int | 0 seen. How flashed the player is. |
smoked | int | 0 seen. How far inside a smoke the player is. |
burning | int | 0 seen. How much the player is burning. |
money | int | |
round_kills | int | Kills this round |
round_killhs | int | Headshot kills this round |
equip_value | int | The value of everything the player has |
Ranges for flashed, smoked, and burning aren’t in Valve’s page and haven’t been measured yet.
player.weapons, with player_weapons, is an object with the keys weapon_0, weapon_1, and so on. Each weapon has:
| Field | Type | Seen in CS2 |
|---|---|---|
name | string | weapon_ak47, weapon_deagle, weapon_glock, weapon_knife_t, weapon_c4, weapon_smokegrenade |
paintkit | string | The skin’s internal name, such as cu_desert_eagle_corroden, or default |
type | string | Rifle, Pistol, Knife, Grenade, C4 |
state | string | active, holstered, reloading |
ammo_clip | int | Rounds in the magazine. Left out for knives, grenades, and the C4. |
ammo_clip_max | int | Magazine size, left out in the same cases. |
ammo_reserve | int | Reserve ammo. A grenade has this field and nothing else about ammo. |
player.match_stats, with player_match_stats: kills, assists, deaths, mvps, score, all ints.
Observer-Only Blocks
Valve names these blocks and what they contain, but none of them has been captured from CS2, so their exact fields aren’t known yet [V]:
allplayers: theplayer_*data for every player.bomb: the bomb’s position, its carrier, and whether it’s dropped.phase_countdowns: the time left in the current phase and which phase it is.grenades, fromallgrenades: each grenade’s owner, position, velocity, type, lifetime, and effect time.
3. Behavior
- Snapshots, not events. Every payload is the full state, so events have to be worked out by comparing payloads, or from
previouslyandadded[V]. - One request at a time. The game waits for each response before it sends the next request, so a slow endpoint delays every update after it [V].
- Spectating after death. Once the player dies,
playerswitches to the teammate they’re watching, andproviderdoesn’t change [C]. - Round counter.
map.roundgoes up as soon as a round isover, not when the next round starts [C]. - No kill feed. No component says who killed whom, or with what [V].
4. Open Items
These need a captured payload, or a test against a real client, before the spec can state them. Where other GSI implementations expect something, it’s listed as a lead.
Protocol
- Non-2xx responses. Valve says a failed request makes the next one send the full state, but not whether the game slows down or stops after repeated failures. pygsi always answers
200to be safe. heartbeatdefault. Valve gives none. [B]: 30 s.- The shape of
previouslyandadded. Valve describes them in words only, and the captured payloads had them stripped. [B]:previouslymirrors the payload’s nesting with only the changed fields, such as{"player": {"state": {"flashed": 24}}}, andaddedmarks each new key withtrue, such as{"player": {"clan": true}}. authin the payload. [B]: the config’sauthfields arrive as strings, and the key doesn’t have to betoken.- A provider-only config. [B]: a change to
provider.timestampalone doesn’t trigger a request, so such a config only gets heartbeats.
Values Not Yet Seen
map.mode. Onlycompetitiveis captured. [B]:casual,deathmatch,gungameprogressive,scrimcomp2v2. Leads for CS2:wingmanin place ofscrimcomp2v2,custom,workshop,new_user_training,retakes,survival.map.phase. [V][B]:intermissionduring halftime.round.bomb. [V][B]:defused.round.phase. Onlyfreezetime,live, andoverare captured. [B]:freezetimealso covers team timeouts.round_wins. Onlyct_win_elimination,t_win_elimination, andt_win_bombare captured. [B]:ct_win_defuse,ct_win_time. Leads:ct_win_rescue,t_win_time.player.team. OnlyTis captured in this field. [B]:TorCT.player.activity. [B]:textinputwhile the console is open. It describes the client itself, even while spectating.- Weapon
type. [B]:SniperRifle,Submachine Gun. Leads:Shotgun, a machine gun type, and types for the Zeus, fists, melee weapons, and tablets. - Ranges. [B]:
flashed,smoked, andburningrun from0to255, andburningis255while on fire and then counts down after leaving it.moneyruns up to16000in competitive. player.observer_slot. [B] numbers the slots 1 to 9, then 0, and says the field only appears while spectating. The captured payloads have it for the local player too, so the second part doesn’t hold for CS2.
Fields Not Yet Seen
player.clan[V]. [B]: left out when the player has no clan tag.player.state. pygsi’s first version modeledround_totaldmganddefusekit, and removed both because CS2 never sent them in real runs (commitd72d174) [C]. Those runs may not have included a CT with a kit, sodefusekitcould still appear then. Lead:health_c4_preview.player.xpoverload. A lead only.map. [B]:current_spectatorsandsouvenirs_total.tournamentdraft. A lead only: a block with pick and ban details for tournaments.- Observer-only blocks. [B] has examples of these:
bombhasstate(carried,dropped,planting,planted,defusing,defused, and, per Valve’s round values,exploded),position,player(the SteamID64 of whoever carries, plants, or defuses it), andcountdown.countdownis the time to finish planting whileplanting, the time to explode whileplanted, and the time to finish defusing whiledefusing.phase_countdownshasphase(the round phases plusbomb,defuse, andwarmup) andphase_ends_in.player.spectarget,player.position, andplayer.forwardcome withplayer_position.- Positions and vectors are
"x, y, z"strings, and countdowns are strings such as"39.8". - Leads:
allplayerskeyed by SteamID64, each value shaped likeplayer, andgrenadeskeyed by ID, withowner,position,velocity,lifetime,type,effecttime, andflames.
Behavior
- Death and spectating. Is the first payload after a death always the player’s own data with
health0, or can it already show the teammate? pygsi’s death event depends on the first case. - The
gameoverpayload while spectating. The capturedgameoverpayload has noplayerblock, so it’s unclear whether one can show a teammate.
To close most of these, run a capture session with every component on and save each raw payload, previously and added included. It should cover a competitive match through halftime, a defuse, and a round lost on time. It should include a round as CT with a kit, armor, and a helmet, and a game in casual, deathmatch, and wingman. Finally, it should include spectating a demo, for the observer-only blocks.