Skip to main content

REST API: Errors & Limits

Error handling, rate limits, and resource quotas in the Trix REST API.

Overview

The Trix API uses conventional HTTP response codes to indicate the success or failure of requests. Codes in the 2xx range indicate success, 4xx indicate client errors, and 5xx indicate server errors.

Error Response Format

All errors return a consistent JSON structure:

error-response.json
{
  "statusCode": 429,
  "error": "Too Many Requests",
  "message": "Rate limit exceeded"
}

Error Fields

FieldTypeDescription
statusCodenumberHTTP status code
errorstringHTTP status text
messagestringHuman-readable description

HTTP Status Codes

Success Codes

CodeDescription
200 OKRequest succeeded
201 CreatedResource created successfully
204 No ContentSuccessful deletion, no response body

Client Error Codes

CodeDescription
400 Bad RequestInvalid request parameters or body
401 UnauthorizedMissing or invalid authentication
403 ForbiddenValid auth but insufficient permissions
404 Not FoundResource doesn't exist
409 ConflictResource conflict (e.g., duplicate)
422 Unprocessable EntityValid syntax but semantic errors
429 Too Many RequestsRate limit exceeded

Server Error Codes

CodeDescription
500 Internal Server ErrorUnexpected server error
502 Bad GatewayUpstream service unavailable
503 Service UnavailableTemporary overload or maintenance
504 Gateway TimeoutRequest took too long

Error Codes

Authentication Errors

CodeHTTPDescription
missing_auth401No Authorization header provided
invalid_api_key401API key doesn't exist or was revoked
expired_token401JWT token has expired
insufficient_permissions403Key lacks required permissions
space_access_denied403Key not authorized for this space

Validation Errors

CodeHTTPDescription
invalid_request400Malformed JSON or invalid parameters
missing_field400Required field not provided
invalid_field400Field value failed validation
content_too_large422Memory content exceeds size limit
invalid_embedding422Custom embedding has wrong dimensions

Resource Errors

CodeHTTPDescription
not_found404Resource doesn't exist
duplicate_memory409Memory with same content exists
relationship_exists409Relationship already exists
space_not_empty409Cannot delete space with memories

Rate Limit Errors

CodeHTTPDescription
rate_limit_exceeded429Too many requests
quota_exceeded429Monthly quota exhausted
concurrent_limit429Too many concurrent requests

Rate Limits

Rate limits protect the API from abuse and ensure fair usage. Limits are applied per API key and vary by plan.

Default Limits

PlanRequests/minRequests/dayConcurrent
Free6010,0005
Pro300100,00020
Max1,000500,00050
EnterpriseUnlimitedUnlimitedUnlimited

Rate Limit Headers

Every response includes rate limit information:

Rate Limit Headers
X-RateLimit-Limit: 300
X-RateLimit-Remaining: 287
X-RateLimit-Reset: 2024-01-15T10:31:00Z
Retry-After: 45
HeaderDescription
X-RateLimit-LimitMaximum requests per window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetISO 8601 datetime when window resets
Retry-AfterSeconds until retry is allowed (only on 429 responses)

Handling Rate Limits

async function fetchWithRetry(
  url: string,
  options: RequestInit,
  maxRetries = 3
): Promise<Response> {
  for (let i = 0; i < maxRetries; i++) {
    const response = await fetch(url, options);

    if (response.status === 429) {
      const resetAfter = parseInt(
        response.headers.get('Retry-After') || '30'
      );
      console.log(`Rate limited. Waiting ${resetAfter}s...`);
      await new Promise(r => setTimeout(r, resetAfter * 1000));
      continue;
    }

    return response;
  }

  throw new Error('Max retries exceeded');
}

// Usage
const response = await fetchWithRetry(
  'https://api.trixdb.com/v1/memories',
  { headers: { 'Authorization': `Bearer ${apiKey}` } }
);

Resource Limits

In addition to rate limits, there are limits on resource sizes and counts:

Memory Limits

ResourceLimit
Content size1 MB per memory
Tags per memory100
Tag length255 characters
Metadata size16 KB
Bulk create batch100 memories

Search Limits

ResourceLimit
Results per page100
Max offset10,000
Query length1,000 characters
Filters per query20

Graph Limits

ResourceLimit
Traversal depth5 hops
Nodes per traversal500
Relationships per memory1,000
Context size100 memories

Account Limits

ResourceFreeProMaxEnterprise
Memories1,000100,000500,000Unlimited
Spaces3UnlimitedUnlimitedUnlimited
API Keys31050Unlimited
Webhooks11050Unlimited

Error Handling Best Practices

Implement Exponential Backoff

async function fetchWithBackoff<T>(
  fn: () => Promise<T>,
  maxRetries = 5,
  baseDelay = 1000
): Promise<T> {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error: unknown) {
      const status = (error as { response?: { status?: number } }).response?.status;

      // Don't retry client errors (except rate limits)
      if (status >= 400 && status < 500 && status !== 429) {
        throw error;
      }

      if (i === maxRetries - 1) throw error;

      // Exponential backoff with jitter
      const delay = baseDelay * Math.pow(2, i) + Math.random() * 1000;
      await new Promise(r => setTimeout(r, delay));
    }
  }
  throw new Error('Unreachable');
}

Handle Specific Errors

error-handler.ts
async function handleApiError(error: ApiError) {
  switch (error.code) {
    case 'rate_limit_exceeded':
      // Wait and retry
      await sleep(error.details?.reset_after || 60);
      return retry();

    case 'duplicate_memory':
      // Return existing memory
      return getMemory(error.details?.existing_id);

    case 'content_too_large':
      // Split content and retry
      return createChunkedMemories(content);

    case 'invalid_api_key':
      // Refresh credentials
      await refreshApiKey();
      return retry();

    default:
      // Log and rethrow
      console.error('Unhandled API error:', error);
      throw error;
  }
}

Include the request_id from error responses when contacting support. This helps us quickly locate and diagnose issues.

Debugging

Health Check

Check API status without authentication:

health-check.sh
curl -X GET "https://api.trixdb.com/v1/health"

# Response
{
  "status": "ok",
  "uptime": 86400,
  "version": "1.2.3",
  "timestamp": "2024-01-15T10:30:00Z"
}