Skip to main content

Overview

The RecallrAI SDK implements a comprehensive exception hierarchy to help you handle different error scenarios gracefully. All SDK exceptions inherit from the base RecallrAIError class.

Exception Hierarchy

Importing Exceptions

Import exceptions from the recallrai.exceptions module:

Base Exception

RecallrAIError

The base exception class for all SDK-specific errors.
Catch RecallrAIError to handle all SDK-specific exceptions in one place.

Authentication Errors

AuthenticationError

Raised when there’s an issue with your API key or project ID authentication.
Common causes:
  • Invalid or expired API key
  • Incorrect project ID
  • Missing authentication headers

Network Errors

TimeoutError

Occurs when a request takes too long to complete.

ConnectionError

Happens when the SDK cannot establish a connection to the RecallrAI API.

Server Errors

InternalServerError

Raised when the RecallrAI API returns a 5xx error code.

RateLimitError

Raised when the API rate limit has been exceeded (HTTP 429).
When available, the retry_after value indicates how long to wait before retrying the request.

User Errors

UserNotFoundError

Raised when attempting to access a user that doesn’t exist.

UserAlreadyExistsError

Occurs when creating a user with an ID that already exists.

InvalidCategoriesError

Raised when filtering user memories by categories that don’t exist in the project.
The exception contains the list of invalid categories in the invalid_categories attribute.

Session Errors

SessionNotFoundError

Raised when attempting to access a non-existent session.

InvalidSessionStateError

Occurs when performing an operation that’s not valid for the current session state.
You cannot add messages to a session that has already been processed.

Merge Conflict Errors

MergeConflictNotFoundError

Raised when attempting to access a merge conflict that doesn’t exist.

MergeConflictAlreadyResolvedError

Occurs when trying to resolve a merge conflict that has already been processed.

MergeConflictInvalidQuestionsError

Raised when the provided questions don’t match the original clarifying questions.

MergeConflictMissingAnswersError

Occurs when not all required clarifying questions have been answered.

MergeConflictInvalidAnswerError

Raised when an answer is not one of the valid options for a question.

Validation Errors

ValidationError

Raised when provided data doesn’t meet the required format or constraints.

Best Practices

1. Handle Specific Exceptions First

Catch more specific exceptions before general ones:

2. Implement Retry Logic for Transient Errors

Network and timeout errors might be temporary:

3. Log Detailed Error Information

Exceptions contain useful information for debugging:

4. Handle Common User Flows

Check if resources exist before operations:

5. Graceful Degradation

Provide fallback behavior when errors occur:

Complete Example

Here’s a comprehensive example showing proper exception handling: