Error Handling
The session and sync APIs return JSON errors with a stringerror field:
error.code or error.message property in the current REST contract.
Validate payloads against the API reference. Some validation failures currently return 500; retrying the same invalid body will not repair it.
Read errors safely
Check partial batch failures
POST /sync/batch can return HTTP 200 and ok: true with a nonempty errors array. Inspect that array before marking a batch complete. Keep external IDs stable when retrying session or message snapshots.
Retry temporary failures
Use a small, bounded number of retries with exponential backoff and jitter for temporary network or service errors. HonorRetry-After if supplied. Do not retry missing credentials or malformed payloads indefinitely. Avoid logging API keys or private message bodies.