Skip to main content
Production integrations must handle errors gracefully to provide a reliable experience. Network issues, rate limits, and temporary server problems are inevitable - your integration should recover from them automatically when possible and fail gracefully when not.

Overview

Why Error Handling Matters

Robust error handling ensures your integration:
  • Stays reliable - Automatically recovers from transient failures
  • Protects data - Prevents data loss during network interruptions
  • Provides visibility - Gives clear feedback when issues occur
  • Scales gracefully - Handles rate limits without cascading failures
The Sully.ai SDKs include built-in retry logic for transient errors. This guide covers the underlying concepts and how to customize behavior for production use cases.

Error Response Format

All Sully.ai API errors follow a consistent structure:
The HTTP response also includes the appropriate status code in the response header.

HTTP Status Codes

Transient vs Permanent Errors

Understanding which errors are transient (temporary) versus permanent is critical for implementing proper retry logic.

Transient Errors (Retry)

These errors are temporary and may succeed if retried:
  • 429 - Rate limited, will succeed after backoff
  • 500 - Server error, often recovers quickly
  • 502/503/504 - Gateway or availability issues
  • Network errors - Connection timeouts, DNS failures

Permanent Errors (Do Not Retry)

These errors indicate a problem with the request itself:
  • 400 - Bad request parameters
  • 401 - Invalid credentials
  • 403 - Permission denied
  • 404 - Resource not found

Retry Strategies

Exponential Backoff with Jitter

The recommended retry strategy uses exponential backoff with random jitter to prevent thundering herd problems:
  • Base delay: Starting wait time (e.g., 1000ms)
  • Max delay: Maximum wait time cap (e.g., 30000ms)
  • Jitter: Random variation to spread out retries (e.g., 0-25% of delay)

Complete Retry Wrapper

When to Give Up

Set reasonable limits to avoid infinite retry loops:
  • Max attempts: 3-5 attempts for most operations
  • Max total time: Cap total retry time (e.g., 2 minutes)
  • Circuit breaker: After repeated failures, stop retrying temporarily
Never retry indefinitely. Set a maximum number of attempts and handle the final failure gracefully - log the error, notify the user, or queue for manual review.

SDK Error Handling

The Sully.ai SDKs provide specific error classes for different failure scenarios, making it easy to handle errors appropriately.

TypeScript SDK

Python SDK

Error Properties

SDK errors include helpful properties for debugging and logging:

WebSocket Error Recovery

Real-time streaming connections require special error handling for connection drops, token expiration, server error messages that may or may not be terminal, and state recovery.

Connection Drops

WebSocket connections can drop unexpectedly due to network issues. Implement automatic reconnection:

Server Error Messages

The streaming API can send error frames before either continuing the session or closing it:
Handle these separately from disconnects:
Treat type: "error" messages as signals to surface immediately, not as a definitive reconnect trigger. Some runtime errors are followed by later transcript or status messages, while other failures are followed by socket closure. Reconnect when the socket closes or another terminal condition is observed.

Token Expiration

Streaming tokens have limited validity. Handle expiration gracefully:

State Recovery After Reconnection

Buffer audio during reconnection to prevent data loss:
For complete WebSocket error handling implementation, see the Audio Transcription guide.

Timeout Handling

Setting Appropriate Timeouts

Configure timeouts based on operation type:

Handling Timeout Errors

Timeout does not mean failure - the operation may still complete on the server:
A timeout error does not mean the operation failed. The server may have received and processed the request. Use webhooks or implement idempotency to handle this safely.

Next Steps

Webhooks Guide

Use webhooks instead of polling for reliable async notifications

Audio Transcription

Production streaming with reconnection and error recovery

TypeScript SDK

Built-in error handling and automatic retries

Python SDK

Error classes and retry configuration