Error Handling
Handle API errors with typed exceptions, stream error events, and built-in retry logic.
This guide covers error handling when using the Concurrence 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)
)import {
AmigoError, // Base error class
AuthenticationError, // Invalid credentials (401)
PermissionError, // 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)
NetworkError, // Network/connection failures
} from '@amigo-ai/sdk'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:
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
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
Handle specific error types. Don't just catch generic exceptions.
Log errors with context. Include relevant IDs and operation details.
Check for stream error events. Monitor the
errorevent type in streams.Trust built-in retries. Let the SDK retry transient
GETfailures automatically; handle failedPOSTrequests explicitly.Graceful degradation. Provide fallback behavior when possible.
Monitor error patterns. Track error rates and types in production.
Next Steps
With proper error handling in place, you're ready to:
Work with conversations. Streaming and reliable handlers.
Manage users. User management with error handling.
Last updated
Was this helpful?

