Error Handling

The Rekall API uses conventional HTTP status codes and returns structured error objects to help you identify and resolve issues quickly.

Error Response Format

All error responses follow a consistent structure with an error object containing a machine-readable code, a human-readable message, and optional details about the error.

Error Response Structure
{
"error": {
"code": "validation_error",
"message": "The request body contains invalid fields.",
"details": {
"field": "type",
"reason": "Must be one of: episodic, semantic, procedural, long_term, short_term, execution, preferences"
}
}
}
FieldTypeDescription
codestringMachine-readable error code (e.g., validation_error)
messagestringHuman-readable description of the error
detailsobject | nullAdditional context about the error (field-level validation errors, constraints, etc.)

HTTP Status Codes

The API uses standard HTTP status codes to indicate the success or failure of a request. Codes in the 2xx range indicate success, 4xx codes indicate client errors, and 5xx codes indicate server errors.

CodeStatusDescription
200OKRequest succeeded
201CreatedResource was created successfully
204No ContentRequest succeeded with no response body (e.g., delete)
400Bad RequestThe request body is malformed or missing required fields
401UnauthorizedMissing or invalid authentication credentials
403ForbiddenValid credentials but insufficient permissions or scopes
404Not FoundThe requested resource does not exist
409ConflictThe request conflicts with the current state of the resource
422Unprocessable EntityThe request was well-formed but contains semantic errors
429Too Many RequestsRate limit exceeded. Check Retry-After header
500Internal Server ErrorAn unexpected error occurred on the server

Error Code Reference

The error.code field provides a machine-readable identifier for the error. Use these codes in your error handling logic.

CodeHTTP StatusDescription
bad_request400Malformed JSON or invalid request structure
authentication_required401No authentication credentials provided
invalid_token401Token is expired, revoked, or malformed
insufficient_permissions403Token lacks the required scopes for this action
resource_not_found404The specified resource ID does not exist
conflict409Resource already exists or state conflict
validation_error422Request body failed validation (see details for fields)
rate_limit_exceeded429Too many requests in the current window
internal_error500Unexpected server error. Contact support if persistent

Handling Errors

Here are examples of robust error handling patterns for common scenarios.

Error Handling Examples
async function createMemory(content: string) {
const response = await fetch('https://api.rekall.ai/v1/memories', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.REKALL_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ type: 'episodic', content }),
});
if (!response.ok) {
const { error } = await response.json();
switch (error.code) {
case 'authentication_required':
case 'invalid_token':
throw new Error('Invalid API key. Check your credentials.');
case 'insufficient_permissions':
throw new Error(`Missing scope: ${error.details?.required_scope}`);
case 'validation_error':
throw new Error(`Validation failed: ${error.message}`);
case 'rate_limit_exceeded':
const retryAfter = response.headers.get('Retry-After');
throw new Error(`Rate limited. Retry after ${retryAfter}s`);
case 'internal_error':
throw new Error('Server error. Please retry or contact support.');
default:
throw new Error(`API error: ${error.message}`);
}
}
const { data } = await response.json();
return data;
}

Validation Errors

When the API returns a 422 status with a validation_error code, the details field contains specific information about which fields failed validation.

Validation Error Example
{
"error": {
"code": "validation_error",
"message": "Request validation failed",
"details": {
"errors": [
{
"field": "type",
"message": "Required field is missing"
},
{
"field": "content",
"message": "Must be between 1 and 50000 characters"
},
{
"field": "metadata.tags",
"message": "Must be an array of strings"
}
]
}
}
}

Debugging Tips

Check the request ID

Every API response includes an X-Request-Id header. Include this ID when contacting support for faster debugging.

Use sandbox keys for testing

Test error handling logic using rk_sandbox_ keys. The sandbox environment simulates all error types.

Log error details

Always log the full error response body, including the details field. This context is invaluable when debugging production issues.

SDK error classes

The official SDKs provide typed error classes for each error code. For example, the TypeScript SDK throws RekallAuthError, RekallValidationError, and RekallRateLimitError for easy pattern matching.

Rekall
rekall