Quick Start

Complete workflow examples in different languages.

Python

import requests

BASE_URL = "https://api.memof.ai"
headers = {
    "Authorization": "Bearer moa_your_token",
    "Content-Type": "application/json"
}

# Create workspace
workspace = requests.post(
    f"{BASE_URL}/api/workspaces/workspace/create",
    headers=headers,
    json={"name": "My Workspace"}
).json()

# Create bot
bot = requests.post(
    f"{BASE_URL}/api/bots/bot/create",
    headers=headers,
    json={
        "name": "Assistant",
        "workspace_id": workspace['id']
    }
).json()

# Store memory
memory = requests.post(
    f"{BASE_URL}/api/integrations/memory/store",
    headers=headers,
    json={
        "bot_id": bot['id'],
        "content": "User prefers Python"
    }
).json()

# Search
results = requests.post(
    f"{BASE_URL}/api/integrations/memory/search",
    headers=headers,
    json={
        "bot_id": bot['id'],
        "query": "programming preferences",
        "limit": 5
    }
).json()

JavaScript/Node.js

const BASE_URL = 'https://api.memof.ai';
const headers = {
  'Authorization': 'Bearer moa_your_token',
  'Content-Type': 'application/json'
};

async function main() {
  // Create workspace
  const workspace = await fetch(`${BASE_URL}/api/workspaces/workspace/create`, {
    method: 'POST',
    headers,
    body: JSON.stringify({ name: 'My Workspace' })
  }).then(r => r.json());

  // Create bot
  const bot = await fetch(`${BASE_URL}/api/bots/bot/create`, {
    method: 'POST',
    headers,
    body: JSON.stringify({
      name: 'Assistant',
      workspace_id: workspace.id
    })
  }).then(r => r.json());

  // Store memory
  const memory = await fetch(`${BASE_URL}/api/integrations/memory/store`, {
    method: 'POST',
    headers,
    body: JSON.stringify({
      bot_id: bot.id,
      content: 'User prefers JavaScript'
    })
  }).then(r => r.json());

  // Search
  const results = await fetch(`${BASE_URL}/api/integrations/memory/search`, {
    method: 'POST',
    headers,
    body: JSON.stringify({
      bot_id: bot.id,
      query: 'programming preferences',
      limit: 5
    })
  }).then(r => r.json());

  console.log(results);
}

main();

cURL/Bash

TOKEN="moa_your_token"
BASE_URL="https://api.memof.ai"

# Create workspace
WORKSPACE=$(curl -s -X POST "$BASE_URL/api/workspaces/workspace/create" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "My Workspace"}')

WORKSPACE_ID=$(echo $WORKSPACE | jq -r '.id')

# Create bot
BOT=$(curl -s -X POST "$BASE_URL/api/bots/bot/create" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"name\": \"Assistant\", \"workspace_id\": \"$WORKSPACE_ID\"}")

BOT_ID=$(echo $BOT | jq -r '.id')

# Store memory
curl -X POST "$BASE_URL/api/integrations/memory/store" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"bot_id\": \"$BOT_ID\", \"content\": \"User prefers bash\"}"

# Search
curl -X POST "$BASE_URL/api/integrations/memory/search" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"bot_id\": \"$BOT_ID\", \"query\": \"preferences\", \"limit\": 5}"

Error Handling

Python with Retries

import requests
import time

def api_call_with_retry(method, url, headers, json_data=None, max_retries=3):
    for attempt in range(max_retries):
        try:
            response = requests.request(method, url, headers=headers, json=json_data)
            
            if response.status_code == 429:
                retry_after = int(response.headers.get('X-RateLimit-Retry-After', 60))
                time.sleep(retry_after)
                continue
            
            response.raise_for_status()
            return response.json()
            
        except requests.exceptions.RequestException as e:
            if attempt == max_retries - 1:
                raise
            time.sleep(2 ** attempt)  # Exponential backoff

JavaScript with Retries

async function apiCallWithRetry(url, options, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      const response = await fetch(url, options);
      
      if (response.status === 429) {
        const retryAfter = parseInt(response.headers.get('X-RateLimit-Retry-After') || '60');
        await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
        continue;
      }
      
      if (!response.ok) throw new Error(`HTTP ${response.status}`);
      return await response.json();
      
    } catch (error) {
      if (attempt === maxRetries - 1) throw error;
      await new Promise(resolve => setTimeout(resolve, Math.pow(2, attempt) * 1000));
    }
  }
}

Next Steps