Exceptions

Complete reference for StakeAPI’s exception hierarchy.


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

Exception Hierarchy

Exception
└── StakeAPIError
    β”œβ”€β”€ AuthenticationError
    β”œβ”€β”€ RateLimitError
    β”œβ”€β”€ ValidationError
    β”œβ”€β”€ NetworkError
    β”œβ”€β”€ GameNotFoundError
    └── InsufficientFundsError

Import:

from stakeapi.exceptions import (
    StakeAPIError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    NetworkError,
    GameNotFoundError,
    InsufficientFundsError,
)

StakeAPIError

Base exception for all StakeAPI errors. Catch this to handle any API error.

try:
    result = await client.get_user_balance()
except StakeAPIError as e:
    print(f"Something went wrong: {e}")

AuthenticationError

Raised when authentication fails (HTTP 401).

Common Causes:

  • Invalid access token
  • Expired access token
  • Missing access token
  • Account session invalidated
try:
    result = await client.get_user_balance()
except AuthenticationError:
    print("Token invalid or expired. Get a new one from stake.com")

RateLimitError

Raised when API rate limits are exceeded (HTTP 429).

Handling Strategy: Exponential backoff

import asyncio

try:
    result = await client.get_user_balance()
except RateLimitError:
    await asyncio.sleep(5)  # Wait and retry
    result = await client.get_user_balance()

ValidationError

Raised when input data doesn’t meet requirements.

try:
    bet = await client.place_bet({"amount": -1})
except ValidationError as e:
    print(f"Invalid input: {e}")

NetworkError

Raised when the HTTP connection fails.

Common Causes:

  • No internet connection
  • DNS resolution failure
  • Connection timeout
  • Server unreachable
try:
    result = await client.get_user_balance()
except NetworkError:
    print("Network error β€” check your internet connection")

GameNotFoundError

Raised when requesting a game that doesn’t exist.

try:
    game = await client.get_game_details("nonexistent")
except GameNotFoundError:
    print("Game not found")

InsufficientFundsError

Raised when attempting to bet more than available balance.

try:
    bet = await client.place_bet({"amount": 999999})
except InsufficientFundsError:
    print("Not enough funds")

from stakeapi.exceptions import *

try:
    result = await client.get_user_balance()
    
except AuthenticationError:
    # Token issues β€” cannot retry
    handle_auth_failure()
    
except RateLimitError:
    # Retry after delay
    await asyncio.sleep(5)
    
except NetworkError:
    # Connection issues β€” retry with backoff
    await asyncio.sleep(2)
    
except ValidationError as e:
    # Bad input β€” fix and retry
    log_validation_error(e)
    
except StakeAPIError as e:
    # Catch-all for other API errors
    log_error(e)

🎰 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 β†’

Test error handling with real API responses. Sign up on Stake.com and build robust applications.