Skip to main content

Documentation Index

Fetch the complete documentation index at: https://toncenter.ness.su/llms.txt

Use this file to discover all available pages before exploring further.

Client

Pass these parameters when creating ToncenterRestClient:
ParameterDefaultDescription
api_keyOptionalAPI key or list of keys for rotation.
networkMainnetMainnet or Testnet.
base_urlOptionalCustom base URL (overrides network selection).
timeout10 secondsRequest timeout.
sessionOptionalExternal HTTP session to share across clients.
headersOptionalExtra HTTP headers sent with every request.
cookiesOptionalExtra cookies sent with every request.
rps_limitOptionalClient-side rate limit (requests per second).
rps_periodOptionalRate-limiter window in seconds.
retry_policyEnabledRetry policy. Disable by passing None.
Without an API key the SDK auto-limits to 1 RPS / 1.2 s on the client side to match the server-side throttle. With a key, client-side limiting is off unless set explicitly.

Session

from toncenter.rest import ToncenterRestClient
from toncenter.types import Network

async with ToncenterRestClient(network=Network.MAINNET) as client:
    balance = await client.v2.accounts.get_address_balance("EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2")

Retries

Rate-limited (429) and server-error responses are retried automatically with exponential backoff.
Status codesMax retriesBase delayMax delayBackoff
42950.3 s3 s2x
500, 502, 503, 50430.5 s5 s2x
Custom policy:
from toncenter.types import RetryPolicy, RetryRule

client = ToncenterRestClient(
    network=Network.MAINNET,
    retry_policy=RetryPolicy(rules=(
        RetryRule(
            statuses=frozenset({429}),
            max_retries=10,
            base_delay=0.5,
            max_delay=10.0,
            backoff_factor=2.0,
        ),
    )),
)
FieldDefaultDescription
statusesRequiredHTTP status codes that trigger retry.
max_retries3Maximum retry attempts.
base_delay1 secondInitial delay.
max_delay30 secondsUpper bound after backoff.
backoff_factor2.0Multiplier per attempt.
The defaults above apply when creating a custom RetryRule. The SDK’s built-in policy uses tuned values shown in the table above.
Pass retry_policy=None to disable retries entirely.

Key Rotation

Pass a list of ApiKey objects to rotate between keys on rate-limit errors (429). Each key carries its own client-side rate limit.
from toncenter.types import ApiKey

client = ToncenterRestClient(
    api_key=[
        ApiKey("free-key", rps_limit=10),
        ApiKey("plus-key", rps_limit=25),
    ],
    network=Network.MAINNET,
)
A single ApiKey also works — rate limit is taken from the object instead of the constructor rps_limit parameter:
client = ToncenterRestClient(api_key=ApiKey("my-key", rps_limit=10))
On 429, the SDK exhausts all retry attempts for the current key (with backoff), then rotates to the next key and retries with a fresh cycle. Each key uses its own RateLimiter.