Skip to main content
Version: Next

Timeouts

The Apify client uses a tiered timeout system to set appropriate time limits for different types of API requests. Each tier has a default value suited to its use case:

TierDefaultPurpose
short5 secondsFast CRUD operations (get, update, delete)
medium30 secondsBatch, list, and data transfer operations
long360 secondsLong-polling, streaming, and heavy operations
no_timeoutDisables the timeout entirely

Every client method has a pre-assigned tier that matches the expected duration of the underlying API call. You generally don't need to change these unless you're working with unusually large payloads or slow network conditions.

Configuring default timeouts

You can override the default values for each tier in the ApifyClient or ApifyClientAsync constructor. The timeout_max parameter sets an upper cap on the timeout for any individual API request, limiting exponential growth during retries.

from datetime import timedelta

from apify_client import ApifyClientAsync

TOKEN = 'MY-APIFY-TOKEN'


async def main() -> None:
# Configure default timeout tiers globally.
apify_client = ApifyClientAsync(
token=TOKEN,
timeout_short=timedelta(seconds=10),
timeout_medium=timedelta(seconds=60),
timeout_long=timedelta(seconds=600),
timeout_max=timedelta(seconds=600),
)

dataset_client = apify_client.dataset('dataset-id')

# Override the timeout for a single call using a timedelta.
items = await dataset_client.list_items(timeout=timedelta(seconds=120))

# Or use a tier literal to select a predefined timeout.
items = await dataset_client.list_items(timeout='long')

Per-call overrides

Most client methods accept a timeout parameter that overrides the default tier for that specific call. You can pass either a timedelta for an exact duration or a tier literal ('short', 'medium', 'long', 'no_timeout') to switch tiers.

from datetime import timedelta

# Use an exact timeout for this call.
client.dataset('id').list_items(timeout=timedelta(seconds=120))

# Switch to a different tier.
client.dataset('id').list_items(timeout='long')

# Disable the timeout entirely.
client.dataset('id').list_items(timeout='no_timeout')

Interaction with retries

Timeouts work together with the retry system. When a request times out, it counts as a failed attempt and triggers a retry (up to max_retries). The timeout applies to each individual attempt, not the total time across all retries.