StakeAPI Client

Complete reference for the main StakeAPI client class.


πŸ’‘ Don't have a Stake.com account yet? Sign up here to get started and unlock all API features.

Class: StakeAPI

The main client for interacting with the Stake.com API. Supports both REST and GraphQL requests with async/await.

Import:

from stakeapi import StakeAPI

Constructor

StakeAPI(
    access_token: Optional[str] = None,
    session_cookie: Optional[str] = None,
    base_url: str = "https://stake.com",
    timeout: int = 30,
    rate_limit: int = 10,
)

Parameters

Parameter Type Default Description
access_token Optional[str] None Your Stake.com access token (x-access-token header)
session_cookie Optional[str] None Session cookie for authentication
base_url str "https://stake.com" Base URL for the API
timeout int 30 Request timeout in seconds
rate_limit int 10 Maximum requests per second

Example

# Basic usage
client = StakeAPI(access_token="your_token")

# Full configuration
client = StakeAPI(
    access_token="your_token",
    session_cookie="your_session",
    timeout=60,
    rate_limit=5,
)

Context Manager

StakeAPI implements the async context manager protocol for automatic session management.

async with StakeAPI(access_token="token") as client:
    # Session is created automatically
    balance = await client.get_user_balance()
# Session is closed automatically

__aenter__(self)

Creates the HTTP session and returns the client instance.

__aexit__(self, exc_type, exc_val, exc_tb)

Closes the HTTP session.


Casino Methods

get_casino_games(category=None)

Get available casino games.

async def get_casino_games(
    self, 
    category: Optional[str] = None
) -> List[Game]
Parameter Type Default Description
category Optional[str] None Filter by game category

Returns: List[Game] β€” List of casino game objects

Example:

# All games
games = await client.get_casino_games()

# Only slots
slots = await client.get_casino_games(category="slots")

get_game_details(game_id)

Get details for a specific game.

async def get_game_details(self, game_id: str) -> Game
Parameter Type Description
game_id str The game identifier

Returns: Game β€” Game details object

Example:

game = await client.get_game_details("game_123")
print(f"{game.name} β€” RTP: {game.rtp}%")

Sports Methods

get_sports_events(sport=None)

Get available sports events.

async def get_sports_events(
    self, 
    sport: Optional[str] = None
) -> List[SportEvent]
Parameter Type Default Description
sport Optional[str] None Filter by sport type

Returns: List[SportEvent] β€” List of sports event objects

Example:

# All events
events = await client.get_sports_events()

# Football only
football = await client.get_sports_events(sport="football")

User Methods

get_user_profile()

Get the current user’s profile information.

async def get_user_profile(self) -> User

Returns: User β€” User profile object

Example:

user = await client.get_user_profile()
print(f"Username: {user.username}")
print(f"Verified: {user.verified}")

get_user_balance()

Get the user’s account balance across all currencies using GraphQL.

async def get_user_balance(self) -> Dict[str, Dict[str, float]]

Returns: Dictionary with available and vault balances

Response Format:

{
    "available": {
        "btc": 0.001,
        "eth": 0.05,
        "usd": 100.0,
    },
    "vault": {
        "btc": 0.01,
        "eth": 0.0,
    }
}

Example:

balance = await client.get_user_balance()

for currency, amount in balance["available"].items():
    if amount > 0:
        print(f"{currency.upper()}: {amount}")

Betting Methods

place_bet(bet_data)

Place a bet.

async def place_bet(self, bet_data: Dict[str, Any]) -> Bet
Parameter Type Description
bet_data Dict[str, Any] Bet information dictionary

Returns: Bet β€” Bet confirmation object

Example:

bet = await client.place_bet({
    "game_id": "game_123",
    "amount": 0.001,
    "currency": "btc",
})
print(f"Bet ID: {bet.id} β€” Status: {bet.status}")

get_bet_history(limit=50)

Get the user’s bet history.

async def get_bet_history(self, limit: int = 50) -> List[Bet]
Parameter Type Default Description
limit int 50 Maximum number of bets to return

Returns: List[Bet] β€” List of bet objects

Example:

bets = await client.get_bet_history(limit=20)
for bet in bets:
    print(f"{bet.id}: {bet.amount} β†’ {bet.status}")

Internal Methods

_graphql_request(query, variables=None, operation_name=None)

Make a raw GraphQL request to the Stake.com API.

async def _graphql_request(
    self,
    query: str,
    variables: Optional[Dict[str, Any]] = None,
    operation_name: Optional[str] = None
) -> Dict[Any, Any]
Parameter Type Default Description
query str β€” GraphQL query string
variables Optional[Dict] None Query variables
operation_name Optional[str] None Operation name

Returns: GraphQL response data

Raises: StakeAPIError for GraphQL errors


_request(method, endpoint, params=None, data=None)

Make an authenticated HTTP request.

async def _request(
    self,
    method: str,
    endpoint: str,
    params: Optional[Dict] = None,
    data: Optional[Dict] = None
) -> Dict[Any, Any]

Raises:

  • AuthenticationError for 401 responses
  • RateLimitError for 429 responses
  • StakeAPIError for other errors

close()

Close the HTTP session.

await client.close()

🎰 Ready to experience Stake.com?

Create your account and start using StakeAPI with real data today.

Sign Up on Stake.com β†’

πŸ’¬ Join the StakeAPI Community on Discord

Get help, share your projects, discuss strategies, and stay up to date with the latest StakeAPI news.

Join Our Discord Server β†’

All methods require a valid Stake.com account. Get started in minutes!