Error Handling

The SDK raises typed exceptions for every failure mode — network errors, API errors, timeouts, and authentication failures.

Exception hierarchy

ZabyError
├── ZabyApiError          — API returned an error response
│   ├── ZabyAuthError     — 401 Unauthorized
│   └── ZabyNotFoundError — 404 Not Found
├── ZabyConnectionError   — Network / transport failure
└── ZabyTimeoutError      — Request exceeded timeout

Catching errors

from zaby import Zaby, ZabyApiError, ZabyAuthError, ZabyNotFoundError

async def create_agent_safely(zaby: Zaby):
    try:
        return await zaby.agents.create({...})
    except ZabyAuthError:
        print("Invalid API key")
    except ZabyNotFoundError as e:
        print(f"Not found: {e.body}")
    except ZabyApiError as e:
        print(f"Error {e.status}: {e.body}")

ZabyApiError fields

status
int
HTTP status code
body
any
Parsed JSON error body (Python)
message
string
Human-readable summary
code
string
Machine-readable error code (TypeScript)
requestId
string
Request identifier for support (TypeScript)
headers
dict
Response headers (Python)

Status codes

cause
string
Malformed request payload or invalid parameters
try:
    await zaby.agents.create({})
except ZabyApiError as e:
    assert e.status == 400
cause
string
Missing or invalid API key / JWT
zaby = Zaby(api_key="wrong-key")
# Raises ZabyAuthError
cause
string
Insufficient permissions for the requested operation
cause
string
Resource does not exist
try:
    await zaby.agents.get("nonexistent")
except ZabyNotFoundError as e:
    assert e.status == 404
cause
string
Duplicate slug or version conflict
cause
string
Too many requests — back off and retry
Configure retries to handle 429s automatically.
cause
string
Temporary server-side failure — retry with backoff

Retry strategy

from zaby import Zaby, ZabyGlobalConfig, RetryPolicy

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

Common issues

Ensure you’re using the right credential type:
# Zaby uses API key
zaby = Zaby(api_key="zaby_pk_...")

# ZabyRuntime uses JWT
runtime = ZabyRuntime(token="eyJhbGciOi...")
Verify the resource exists and has been published:
version = await zaby.agents.publish(agent_id)  # Must publish first
deployment = await zaby.deployments.create(agent_id, {...})  # Then deploy
Increase the timeout for long-running operations:
zaby = Zaby(api_key="...", config=ZabyGlobalConfig(timeout_ms=120_000))
Verify your local server is running:
zaby = Zaby(
    api_key="...",
    config=ZabyGlobalConfig(api_origin="http://localhost:9080"),
)

Debugging

Enable debug logging to inspect requests and responses:
import logging
logging.basicConfig(level=logging.DEBUG)

Testing

MockTransport for deterministic testing.

Configuration

Full configuration reference.