Documentation

Configuration

Customize client behavior with configuration options

Client Initialization

All available configuration parameters

python
from scopix import Scopix
client = Scopix(
api_key="scopix_...", # Required: Your API key
base_url="https://api.scopix.ai/api/v2", # API base URL
timeout=300.0, # Request timeout (seconds)
max_retries=3, # Retry attempts for transient failures
retry_delay=1.0, # Initial retry delay (exponential backoff)
polling_interval=2.0, # Status check interval (seconds)
polling_timeout=360.0, # Max wait for async operations
tenant_id=None, # Tenant ID for multi-tenant deployments
proxy_url=None, # Proxy URL (http or https)
enable_tracing=False, # OpenTelemetry tracing
)

Configuration Options

ParameterTypeDefaultDescription
api_keystrRequiredYour Scopix API key
base_urlstrProduction APIAPI base URL
timeoutfloat300.0Request timeout in seconds
max_retriesint3Max retry attempts
retry_delayfloat1.0Initial retry delay (seconds)
polling_intervalfloat2.0Status poll interval
polling_timeoutfloat360.0Max polling wait time
tenant_idOptional[str]NoneTenant ID for multi-tenant deployments
proxy_urlOptional[str]NoneProxy URL (http or https)
enable_tracingboolFalseOpenTelemetry tracing

Environment Variables

Use from_env() to load configuration from environment variables

python
from scopix import Scopix
# Load all configuration from environment variables
async with Scopix.from_env() as client:
result = await client.files.upload("photo.jpg")
# Override specific values while using env vars for the rest
async with Scopix.from_env(timeout=60.0) as client:
result = await client.files.upload("photo.jpg")

See the Environment Variables Reference for a complete list of supported environment variables and .env file usage.

Timeout Configuration

Adjust timeouts for different scenarios

python
# For fast operations
async with Scopix(
api_key=api_key,
timeout=30.0, # 30 second request timeout
polling_timeout=60.0, # 1 minute max wait for async ops
) as client:
result = await client.files.upload("photo.jpg")
# For large batch operations
async with Scopix(
api_key=api_key,
timeout=600.0, # 10 minute request timeout
polling_timeout=3600.0, # 1 hour max wait for batch completion
polling_interval=10.0, # Check every 10 seconds
) as client:
results = await client.files.upload_batch("/path/to/photos")

Retry Configuration

Configure automatic retry behavior

python
# Aggressive retries for unreliable networks
async with Scopix(
api_key=api_key,
max_retries=5, # More retry attempts
retry_delay=0.5, # Start with 0.5s delay
) as client:
result = await client.files.upload("photo.jpg")
# No retries (fail fast)
async with Scopix(
api_key=api_key,
max_retries=0, # No automatic retries
) as client:
result = await client.files.upload("photo.jpg")

The SDK uses exponential backoff: delays double with each retry, starting from retry_delay (default 1s).

Retryable Errors

These errors trigger automatic retries

  • RateLimitError - API rate limit exceeded
  • ServerError - 5xx server errors
  • ScopixConnectionError - Network failures
  • asyncio.TimeoutError - Request timeouts

Post-Upload Description Polling

client.files.upload() returns as soon as the bytes are in storage; AI descriptions complete asynchronously. Poll for completion:

python
result = await client.files.upload("large_image.jpg")
# Wait for description to finish (or fail)
status = await client.files.get_processing_status(result.file_id)
while not status.is_terminal:
await asyncio.sleep(2)
status = await client.files.get_processing_status(result.file_id)

API Key Validation

The SDK validates API key format on initialization

python
from scopix import Scopix
try:
client = Scopix(api_key="invalid_key")
except ValueError as e:
print(f"Invalid API key: {e}")
# API key must match format: scopix_...

ClientConfig Class

Configuration as a standalone object. ClientConfig supports advanced options not available via the Scopix() constructor. The constructor accepts only the 10 basic parameters (api_key, base_url, timeout, max_retries, retry_delay, polling_interval, polling_timeout, tenant_id, proxy_url, enable_tracing); advanced settings such as circuit breaker, logging, and tracing options must be configured by constructing a ClientConfig object directly.

python
from scopix import ClientConfig
config = ClientConfig(
api_key="scopix_...",
base_url="https://api.scopix.ai/api/v2",
timeout=300.0,
max_retries=3,
retry_delay=1.0,
polling_interval=2.0,
polling_timeout=360.0,
# Also available in Scopix() constructor:
tenant_id=None, # Tenant ID for multi-tenant deployments
proxy_url=None, # Proxy URL (http or https)
# Advanced options (only configurable via ClientConfig, not via Scopix() constructor)
enable_logging=True, # Structured logging for HTTP requests
)
# Access configuration values
print(f"Base URL: {config.base_url}")
print(f"Timeout: {config.timeout}s")
# Get the authorization header for custom HTTP requests
headers = config.auth_header # {"Authorization": "Bearer scopix_..."}

HTTPS Required

The SDK enforces HTTPS for all API communication. Non-HTTPS base_url values will raise a ValueError on initialization (localhost URLs are exempt for development).