state array of ordered bookEvent objects). rgsFetcher is a thin, type-safe HTTP client that wraps all RGS communication. Response types are inferred automatically from an auto-generated OpenAPI schema, so endpoint calls are fully typed end-to-end.
rgsFetcher.post
POST request to https://{rgsUrl}{url}. The response type TResponse defaults to paths[T]['post']['responses'][200]['content']['application/json'], so you get full type inference from the schema with no manual annotation required.
Logs console.error if the HTTP status is not 200.
The RGS endpoint path. Must be one of the paths defined in
schema.ts. TypeScript will reject any string that is not a valid key.Available POST paths: '/wallet/authenticate', '/wallet/balance', '/wallet/play', '/wallet/end-round', '/bet/event', '/bet/action', '/session/start', '/game/search'.The RGS hostname (without protocol), for example
'rgs.example.com'. The full request URL is constructed as https://{rgsUrl}{url}.The request body. The type is inferred from the schema for the given
url, so TypeScript will tell you exactly which fields are required for each endpoint.rgsFetcher.get
GET request to https://{rgsUrl}{url}. Response type is inferred from the schema the same way as post.
Logs console.error if the HTTP status is not 200.
The RGS endpoint path.
The RGS hostname (without protocol).
Schema and type inference
schema.ts is auto-generated by openapi-typescript and should not be edited by hand. It exports a paths interface that maps every endpoint to its request and response shapes.
RGS endpoints
The following endpoints are defined inschema.ts.
POST /wallet/authenticate
Validates asessionID with the operator. Must be called at game start before any other wallet action.
Request body (req_authenticate):
The session ID passed to the game iframe via URL parameters.
RGS game language.
res_authenticate): includes status, balance, round (the active bet, if any), and config (bet levels, modes, and jurisdiction settings).
POST /wallet/balance
Fetches the current player balance. Most other wallet responses already include the balance, so this endpoint is typically used only for periodic polling. Request body (req_Balance): { sessionID }
Response (res_Balance): { balance, status, error }
POST /wallet/play
Triggers a play (debit). The player’s balance is reduced byamount and the RGS returns the game result in round.state.
Request body (req_play):
Active session ID.
Bet amount as an integer. Currency is an integer —
1000 represents $10.00. Multiply the player-facing bet by API_AMOUNT_MULTIPLIER before sending.Currency code (e.g.
'USD').Bet mode (e.g.
'BASE', 'SUPERSPIN'). Valid modes are defined per-game in the config returned by /wallet/authenticate.Optional metadata passed through to the game without RGS validation.
res_play): { status, balance, round, error }. The book of events is at round.state.
POST /wallet/end-round
Closes the active round. No further actions can be made for this round; the RGS sends a payout request to the operator. Request body (req_end_round): { sessionID }
Response (res_end_round): { balance, status, error }
POST /bet/event
Tracks progress through a bet. Sends an event string that is saved to the RGS database alongside the bet. Used byrecordBookEvent to checkpoint which book event the client has processed.
Request body (req_event):
Active session ID.
An arbitrary event string. In practice this is the
bookEvent.index cast to a string.res_event): { event, status, error }
POST /bet/action
Triggers an additional in-round action for games that support them (e.g. a “gamble” or “hold” decision). Theaction field determines whether the RGS sends an additional bet to the operator (BET) or routes the request directly to the game (DECISION).
Request body (req_action):
Active session ID.
Action type:
'BET' or 'DECISION'.Optional metadata.
res_action): { status, balance, action, error }
POST /session/start
Operator-facing endpoint. An operator calls this to start a session and receive a game iframe URL. Send this request to the mock-casino endpoint of the environment, not the RGS directly. Request body (req_sess_start):
Currency the player is playing in.
A session token from the casino side.
Starting balance. Defaults to
100000 (= $1000.00).When
true, sets the player’s balance to the value in balance. Defaults to false.res_sess_start): { url, error } — the url is passed into the game iframe.
POST /game/search
Searches for game books matching criteria. Used internally for development tooling. Request body (req_search): { mode, search } where search accepts bookID, kind, symbol, hasWild, wildMult, gameType.
Response (res_search): { balance, round, error }
Error handling
When the RGS returns a non-200 HTTP status,rgsFetcher logs the error to the console:
response.status?.statusCode in the returned data for application-level errors. The StatusCode enum covers the following values:
| Code | Meaning |
|---|---|
SUCCESS | Operation completed successfully |
ERR_SCR | Invalid secret |
ERR_OPT | Invalid operator ID |
ERR_IPB | Insufficient player balance |
ERR_IS | Invalid session token / session timeout |
ERR_ATE | Failed user authentication / authentication token expired |
ERR_GLE | Gambling limits exceeded |
ERR_BNF | Bet not found |
ERR_BE | Player already has an active bet |
ERR_UE | General server error (with rollback) |
ERR_GE | General server error (without rollback) |
Usage example
The higher-levelrgs-requests package wraps rgsFetcher into named functions. Prefer these over calling rgsFetcher directly.
Calling rgsFetcher directly
If you need to call an endpoint not covered byrgs-requests, use rgsFetcher directly:
BetType utility
Thergs-requests package also exports a BetType<TBookEvent> utility for typing the round field of a bet response with your game’s specific BookEvent union:
