Hebbrix
Errors

Error Handling

Learn how to handle API errors gracefully. Hebbrix uses standard HTTP status codes and returns detailed error messages to help you debug issues.

Error Response Format

All error responses follow a consistent JSON format:

Error Response
{
  "error": {
    "code": "invalid_request",
    "message": "The 'content' field is required",
    "type": "validation_error",
    "param": "content",
    "status": 400,
    "request_id": "req_abc123xyz"
  }
}
FieldTypeDescription
codestringMachine-readable error code
messagestringHuman-readable error description
typestringError category (validation_error, auth_error, etc.)
paramstring?Parameter that caused the error (if applicable)
statusintegerHTTP status code
request_idstringUnique request ID for debugging

HTTP Status Codes

400

Bad Request

The request was malformed or missing required parameters.

Missing required fieldsInvalid JSON bodyInvalid parameter types
401

Unauthorized

Authentication failed or API key is invalid.

Missing API keyInvalid API key formatRevoked API key
403

Forbidden

The API key doesn't have permission for this action.

Insufficient permissionsResource belongs to another userFeature not available on tier
404

Not Found

The requested resource doesn't exist.

Invalid IDResource was deletedTypo in endpoint URL
429

Too Many Requests

Rate limit exceeded. Slow down your requests.

Exceeded requests per minuteExceeded monthly quota
500

Internal Server Error

Something went wrong on our end. Retry the request.

Temporary system issueDatabase error

Error Codes

Common error codes returned in the error.code field:

CodeDescription
invalid_api_keyThe API key provided is invalid or expired
missing_api_keyNo API key was provided in the request
invalid_requestThe request body is malformed or missing fields
validation_errorA parameter failed validation rules
resource_not_foundThe requested resource doesn't exist
collection_not_foundThe specified collection doesn't exist
rate_limit_exceededToo many requests in the time window
quota_exceededMonthly API call quota has been exceeded
document_too_largeUploaded file exceeds size limit
unsupported_formatFile format is not supported
permission_deniedThe API key lacks required permissions
internal_errorAn unexpected server error occurred

Handling Errors

Python

Python Error Handling
from hebbrix import Hebbrix
from hebbrix.exceptions import (
    HebbrixError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    NotFoundError
)

client = Hebbrix()

try:
    memory = client.memories.create(content="Test memory")
except AuthenticationError as e:
    # Invalid or missing API key
    print(f"Auth error: {e.message}")
    print(f"Check your API key configuration")

except RateLimitError as e:
    # Too many requests
    print(f"Rate limited. Retry after {e.retry_after} seconds")
    import time
    time.sleep(e.retry_after)
    # Retry the request

except ValidationError as e:
    # Invalid request parameters
    print(f"Validation error: {e.message}")
    print(f"Invalid param: {e.param}")

except NotFoundError as e:
    # Resource doesn't exist
    print(f"Not found: {e.message}")

except HebbrixError as e:
    # Catch-all for other API errors
    print(f"API error [{e.status_code}]: {e.message}")
    print(f"Request ID: {e.request_id}")
    # Log for debugging

TypeScript

TypeScript Error Handling
import {
  Hebbrix,
  HebbrixError,
  AuthenticationError,
  RateLimitError,
  ValidationError,
  NotFoundError
} from 'hebbrix';

const client = new Hebbrix();

try {
  const memory = await client.memories.create({ content: 'Test memory' });
} catch (error) {
  if (error instanceof AuthenticationError) {
    // Invalid or missing API key
    console.error(`Auth error: ${error.message}`);

  } else if (error instanceof RateLimitError) {
    // Too many requests
    console.error(`Rate limited. Retry after ${error.retryAfter}s`);
    await new Promise(r => setTimeout(r, error.retryAfter * 1000));
    // Retry the request

  } else if (error instanceof ValidationError) {
    // Invalid request parameters
    console.error(`Validation error: ${error.message}`);
    console.error(`Invalid param: ${error.param}`);

  } else if (error instanceof NotFoundError) {
    // Resource doesn't exist
    console.error(`Not found: ${error.message}`);

  } else if (error instanceof HebbrixError) {
    // Catch-all for other API errors
    console.error(`API error [${error.status}]: ${error.message}`);
    console.error(`Request ID: ${error.requestId}`);

  } else {
    throw error; // Re-throw unknown errors
  }
}

Rate Limit Handling

When you hit rate limits, the response includes headers to help you retry appropriately:

429 Response
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1705312800
Retry-After: 45

{
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Rate limit exceeded. Please retry after 45 seconds.",
    "type": "rate_limit_error",
    "status": 429,
    "request_id": "req_xyz789"
  }
}

Implementing Exponential Backoff

Python Exponential Backoff
import time
import random
from hebbrix import Hebbrix
from hebbrix.exceptions import RateLimitError, HebbrixError

def make_request_with_retry(client, max_retries=5):
    """Make a request with exponential backoff retry."""

    for attempt in range(max_retries):
        try:
            return client.memories.create(content="Test")

        except RateLimitError as e:
            if attempt == max_retries - 1:
                raise  # Give up after max retries

            # Use Retry-After header if provided
            wait_time = e.retry_after if e.retry_after else (2 ** attempt)

            # Add jitter to prevent thundering herd
            jitter = random.uniform(0, 1)
            sleep_time = wait_time + jitter

            print(f"Rate limited. Retrying in {sleep_time:.1f}s (attempt {attempt + 1})")
            time.sleep(sleep_time)

        except HebbrixError as e:
            if e.status_code >= 500:
                # Retry on server errors
                wait_time = 2 ** attempt
                print(f"Server error. Retrying in {wait_time}s")
                time.sleep(wait_time)
            else:
                raise  # Don't retry client errors

Best Practices

Always Handle Errors

Wrap API calls in try/catch and handle specific error types appropriately.

Implement Retries

Use exponential backoff for rate limits (429) and server errors (5xx).

Log Request IDs

Save the request_id for debugging. Include it when contacting support.

Don't Expose Errors

Don't show raw API errors to end users. Display friendly messages instead.

Next Steps

Assistant

Ask me anything about Hebbrix