Configuration

Configure the SDK globally or per-instance.

Getting Started

Quick setup guide.

Error Handling

Retry policies and error types.

Zaby client

The Zaby constructor accepts:
api_key
str | () → str | () → Awaitable[str]
required
API key for x-zaby-api-key header. Can be a static string, sync callable, or async callable.
access_token
str | () → str | () → Awaitable[str]
JWT for Authorization: Bearer header. Optional for most provisioning endpoints.
transport
ZabyTransport
Custom transport. Use MockTransport for testing.
config
ZabyGlobalConfig
Per-instance configuration overrides.

Global configuration

Set defaults shared across all client instances:
from zaby import configure_zaby, ZabyGlobalConfig

configure_zaby(ZabyGlobalConfig(
    api_origin="https://custom.io",
    timeout_ms=60_000,
    retries=3,
    user_agent="my-app/1.0",
))
Override on a single instance:
zaby = Zaby(
    api_key="zaby_pk_...",
    config=ZabyGlobalConfig(timeout_ms=120_000),
)
Instance config merges over globals — only specify the fields you want to override.

Config fields

type
string
default:"https://genapi.zaby.io"
Base URL for all API requests. Override for local development or custom deployments.
ZabyGlobalConfig(api_origin="http://localhost:9080")
type
int
default:"30000"
Maximum time to wait for a response, in milliseconds.
ZabyGlobalConfig(timeout_ms=60_000)
Configure which requests are retried and how.
from zaby import RetryPolicy

ZabyGlobalConfig(retries=RetryPolicy(
    attempts=3,
    retry_methods=["GET", "HEAD", "OPTIONS"],
    retry_statuses=[408, 429, 500, 502, 503, 504],
    backoff_ms=lambda attempt: min(100 * 2 ** attempt, 1000),
))

# Integer shorthand
ZabyGlobalConfig(retries=3)
ZabyGlobalConfig(user_agent="my-app/1.0")
type
string
default:"production"
Sets a preset origin. “local”http://localhost:9080

Retry policy

attempts
int
default:"0"
Maximum retry attempts
retry_methods
string[]
default:"[\"GET\", \"HEAD\", \"OPTIONS\"]"
HTTP methods eligible for retry
retry_statuses
int[]
default:"[408, 429, 500, 502, 503, 504]"
Status codes that trigger a retry
backoff_ms
callable
default:"exponential 100ms–1s"
Delay function: lambda attempt: min(100 * 2**attempt, 1000)
Only idempotent methods (GET, HEAD, OPTIONS) are retried by default. POST and other mutating methods are not retried to prevent duplicate operations.

Authentication providers

Credentials can be static strings, lazy callables, or async callables:
# Static string
zaby = Zaby(api_key="zaby_pk_static_key")

# Lazy — called on every request
zaby = Zaby(api_key=lambda: get_current_key())

# Async
async def key_provider() -> str:
    return await fetch_key_from_vault()
zaby = Zaby(api_key=key_provider)

Environment variables

# .env or shell
export ZABY_API_ORIGIN=http://192.168.68.61:9080
export ZABY_ENVIRONMENT=local
Explicit api_origin always takes precedence over environment presets.

ZabyRuntime options

token
str | () → str | () → Awaitable[str]
required
JWT runtime token for Authorization: Bearer
transport
ZabyTransport
Custom transport for testing.
config
ZabyGlobalConfig
Runtime-specific config overrides.
from zaby import ZabyRuntime

runtime = ZabyRuntime(token="eyJhbGciOi...")