The SDK uses a structured exception hierarchy. All exceptions inherit from InfiniumError.

Exception Hierarchy

InfiniumError
├── AuthenticationError      (401)
├── ValidationError          (422)
├── RateLimitError           (429)
├── NetworkError             (connection failures)
├── InfiniumTimeoutError     (request timeouts)
├── ServerError              (500+)
├── NotFoundError            (404)
├── BatchError               (batch operation failures)
└── ConfigurationError       (invalid client config)

Catching Errors

from infinium.exceptions import (
    InfiniumError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    NetworkError,
    ServerError,
    InfiniumTimeoutError,
    NotFoundError,
)

try:
    client.send_task_data(task_data)
except AuthenticationError:
    # Bad agent_id or agent_secret
    print("Check your credentials")
except ValidationError as e:
    # Invalid input data
    print(f"Field '{e.field}': {e.message}")
except RateLimitError as e:
    # Too many requests
    print(f"Retry after {e.retry_after} seconds")
except NotFoundError as e:
    # Agent or resource not found
    print(f"{e.resource_type} '{e.resource_id}' not found")
except NetworkError as e:
    # Cannot reach the API
    print(f"Network error: {e.original_error}")
except InfiniumTimeoutError as e:
    # Request timed out
    print(f"Timed out after {e.timeout_duration}s")
except ServerError:
    # 5xx from the API (after retries exhausted)
    print("Server error -- try again later")
except InfiniumError:
    # Catch-all for any SDK error
    print("Something went wrong")

Exception Details

All exceptions have these base attributes:

AttributeTypeDescription
messagestrHuman-readable error message
status_codeint or NoneHTTP status code (if applicable)
detailsdict or NoneAdditional context

AuthenticationError

Raised on HTTP 401. Default message: "Authentication failed".

ValidationError

Raised for invalid input data (client-side validation or HTTP 422).

AttributeTypeDescription
fieldstr or NoneWhich field failed validation

RateLimitError

Raised on HTTP 429.

AttributeTypeDescription
retry_afterint or NoneSeconds to wait before retrying

NetworkError

Raised when the API is unreachable (DNS failure, connection refused, etc.).

AttributeTypeDescription
original_errorException or NoneThe underlying network exception

InfiniumTimeoutError

Raised when a request exceeds the configured timeout.

AttributeTypeDescription
timeout_durationfloat or NoneThe timeout threshold in seconds

Also available as TimeoutError (alias) for convenience.

ServerError

Raised on HTTP 5xx after all retries are exhausted. Default status code: 500.

NotFoundError

Raised on HTTP 404.

AttributeTypeDescription
resource_typestr or NoneType of resource (e.g., "agent", "trace")
resource_idstr or NoneID of the missing resource

BatchError

Raised when a batch operation fails.

AttributeTypeDescription
successful_countintNumber of successful sends
failed_countintNumber of failed sends
errorslistError messages

ConfigurationError

Raised for invalid client configuration.

AttributeTypeDescription
config_keystr or NoneWhich config key is invalid

Retry Behavior

The SDK automatically retries certain errors with exponential backoff:

Error TypeAuto-Retried?
ServerError (5xx)Yes
NetworkErrorYes
InfiniumTimeoutErrorYes
AuthenticationError (401)No
ValidationError (422)No
RateLimitError (429)No
NotFoundError (404)No

Retry Configuration

client = InfiniumClient(
    agent_id="...",
    agent_secret="...",
    max_retries=3,   # Number of retry attempts (default: 3)
    timeout=30.0,    # Per-request timeout in seconds (default: 30)
)

Backoff is exponential with jitter: min(base_delay * 2^attempt + random_jitter, max_delay).


Rate Limiting

The SDK includes a built-in token bucket rate limiter:

client = InfiniumClient(
    agent_id="...",
    agent_secret="...",
    enable_rate_limiting=True,   # Enabled by default
    requests_per_second=10.0,    # Default: 10 req/s
)

When enabled, the client automatically throttles requests to stay within the limit. This is both thread-safe (sync) and async-safe.

If the server returns a 429, a RateLimitError is raised with the retry_after hint — this is not auto-retried.


Validation

The SDK validates data before sending to catch errors early:

ValidationLimit
name lengthMax 500 characters
description lengthMax 10,000 characters
String fieldsMax 2,000 characters
Payload sizeMax 1 MB
Duration0 to 86,400 seconds (24 hours)
Path IDs (agent_id, etc.)Must be valid UUID format

Validation failures raise ValidationError with the offending field name.