For the complete documentation index, see llms.txt. This page is also available as Markdown.

Error Handling

Handle API errors with typed exceptions, stream error events, and built-in retry logic.

This guide covers error handling when using the Amigo SDK in Python or TypeScript. Both SDKs include built-in retry logic for transient failures and provide full error handling for all API operations.

Error Types

Both SDKs provide typed error handling for different types of failures:

from amigo_sdk.errors import (
    AmigoError,           # Base error class
    AuthenticationError,   # Invalid credentials (401)
    ForbiddenError,       # Permission denied (403)
    NotFoundError,        # Resource not found (404)
    BadRequestError,      # Invalid request (400)
    ValidationError,      # Request validation failed (422)
    ConflictError,        # Resource conflict (409)
    RateLimitError,       # Rate limit (429)
    ServerError,          # Server error (5xx)
    ServiceUnavailableError,  # Service unavailable (503)
)

Both SDKs map HTTP status codes to typed errors, including RateLimitError for 429 responses; any failure without a dedicated class is raised through the base AmigoError. The SDKs differ on connection failures: the TypeScript SDK wraps them in a typed NetworkError, while the Python SDK lets the underlying httpx exceptions (for example httpx.ConnectError and httpx.TimeoutException) propagate.

Basic Error Handling

Stream Error Handling

When processing streaming responses, handle errors within the stream. See also Conversations: Interact.

Built-in Retry Logic

Both SDKs share the same default retry policy for transient failures:

Setting
Default

Max attempts

3

Backoff

Exponential with full jitter, 250ms base, 30s max delay per attempt

Retried statuses

408, 429, 500, 502, 503, 504

Retried methods

GET, plus POST when the response is a 429 with a Retry-After header

Retry-After header

Honored (numeric or HTTP-date), capped at the max delay

GET requests are retried; POST requests generally are not. By default, only GET requests are retried on network errors and retryable statuses. POST requests (including conversation creation and interactions) are retried only for a 429 response that carries a Retry-After header; other POST failures surface immediately so you can decide whether to resend.

You can tune this policy: the TypeScript client accepts a retry option (maxAttempts, backoffBaseMs, maxDelayMs, retryOnStatus, retryOnMethods), and the Python client accepts retry_max_attempts, retry_backoff_base, retry_max_delay_seconds, retry_on_status, and retry_on_methods keyword arguments.

Retry Flow Diagram

Best Practices

  1. Handle specific error types. Don't just catch generic exceptions.

  2. Log errors with context. Include relevant IDs and operation details.

  3. Check for stream error events. Monitor the error event type in streams.

  4. Trust built-in retries. Let the SDK retry transient GET failures automatically; handle failed POST requests explicitly.

  5. Graceful degradation. Provide fallback behavior when possible.

  6. Monitor error patterns. Track error rates and types in production.

Next Steps

With proper error handling in place, you're ready to:

Last updated

Was this helpful?