Skip to main content
Memory operations are network calls, and network calls can fail. The difference between a brittle agent and a production-ready one is whether it handles those failures gracefully. Remem raises specific, typed exceptions for every failure scenario so you can catch exactly the right error and respond appropriately — whether that means logging and continuing, notifying the user, or halting immediately.

Exception Hierarchy

Remem exposes five exception classes, each mapping to a specific HTTP status code and failure scenario:

Importing Exception Classes

Import all exception classes at the top of your module:

Handling Each Exception

AuthenticationError — 401

Raised when your API key is invalid, missing, or revoked. This is not a transient error — retrying with the same key will always fail.
Never retry on AuthenticationError. The key is wrong — retrying with the same key will always fail. Fix the key and redeploy.

PlanLimitError — 402

Raised when your account has reached its memory limit for the current plan. You can still read and search memories — only new writes are blocked.
Handle it gracefully in your agent by skipping the write rather than crashing:
Your agent can still read and search memories when the limit is hit — only new writes are blocked. Your agent will not go blind; it just stops learning new things until you upgrade.

MemoryNotFoundError — 404

Raised when you try to update or delete a memory ID that does not exist — either because it was already deleted or the ID is wrong.

DuplicateMemoryError — 409

Raised when you try to store content that is already present at 95% similarity or above. This is Remem protecting your memory store from redundant data — treat it as a no-op.
DuplicateMemoryError is not a real error in most cases — it means Remem protected your database from storing the same fact twice. Ignore it silently in production.

RememError — Catch-All

RememError is the base class for all Remem exceptions. Use it as a fallback to catch unexpected errors — server errors, rate limits, or anything else not matched by a specific subclass.

Production-Ready Pattern

This is the pattern to use in any production agent. Both helper functions are guaranteed never to raise — your agent continues regardless of what Remem returns.

Retry Logic

For transient server errors (5xx), use exponential backoff before giving up. Don’t retry on client errors (4xx) — those require a code or configuration fix.

Error Reference

Production Checklist

Run through this checklist before shipping any agent that uses Remem in production.
Wrap every remember() call — DuplicateMemoryError is common and safe to ignore
Handle PlanLimitError gracefully — agent should continue without storing, not crash
Log AuthenticationError immediately — it means your key needs fixing
Return an empty list from recall() on error — agent degrades gracefully with no context
Add retry logic for 5xx errors — transient server issues should not kill your agent