Copy-paste ready examples in every language 🌍
# Set these first!
export MEMOFAI_TOKEN="moa_your_token_here"
export API_URL="https://api.memof.ai"import requests
import os
BASE_URL = "https://api.memof.ai"
headers = {
"Authorization": f"Bearer {os.getenv('MEMOFAI_TOKEN')}",
"Content-Type": "application/json"
}
# Create workspace
workspace = requests.post(
f"{BASE_URL}/api/workspaces/workspace/create",
headers=headers,
json={"name": "My Workspace"}
).json()
print(f"Workspace ID: {workspace['id']}")
# Create bot
bot = requests.post(
f"{BASE_URL}/api/bots/bot/create",
headers=headers,
json={
"name": "My Bot",
"workspace_id": workspace['id']
}
).json()
print(f"Bot ID: {bot['id']}")
# Store memory
memory = requests.post(
f"{BASE_URL}/api/integrations/memory/store",
headers=headers,
json={
"bot_id": bot['id'],
"content": "User loves Python"
}
).json()
print(f"Memory ID: {memory['id']}")
# Search memories
results = requests.post(
f"{BASE_URL}/api/integrations/memory/search",
headers=headers,
json={
"bot_id": bot['id'],
"query": "programming preferences",
"limit": 5
}
).json()
print(f"Found {len(results)} memories")
for result in results:
print(f" - {result['content']}")import httpx
import asyncio
import os
async def main():
headers = {
"Authorization": f"Bearer {os.getenv('MEMOFAI_TOKEN')}",
"Content-Type": "application/json"
}
async with httpx.AsyncClient() as client:
# Create workspace
response = await client.post(
"https://api.memof.ai/api/workspaces/workspace/create",
headers=headers,
json={"name": "Async Workspace"}
)
workspace = response.json()
# Create bot
response = await client.post(
"https://api.memof.ai/api/bots/bot/create",
headers=headers,
json={
"name": "Async Bot",
"workspace_id": workspace['id']
}
)
bot = response.json()
# Store memories concurrently
tasks = [
client.post(
"https://api.memof.ai/api/integrations/memory/store",
headers=headers,
json={
"bot_id": bot['id'],
"content": content
}
)
for content in [
"User loves Python",
"User prefers async code",
"User values type safety"
]
]
results = await asyncio.gather(*tasks)
print(f"Stored {len(results)} memories")
asyncio.run(main())const MEMOFAI_TOKEN = process.env.MEMOFAI_TOKEN;
const BASE_URL = 'https://api.memof.ai';
const headers = {
'Authorization': `Bearer ${MEMOFAI_TOKEN}`,
'Content-Type': 'application/json'
};
async function main() {
// Create workspace
const workspaceRes = await fetch(`${BASE_URL}/api/workspaces/workspace/create`, {
method: 'POST',
headers,
body: JSON.stringify({ name: 'My Workspace' })
});
const workspace = await workspaceRes.json();
console.log('Workspace ID:', workspace.id);
// Create bot
const botRes = await fetch(`${BASE_URL}/api/bots/bot/create`, {
method: 'POST',
headers,
body: JSON.stringify({
name: 'My Bot',
workspace_id: workspace.id
})
});
const bot = await botRes.json();
console.log('Bot ID:', bot.id);
// Store memory
const memoryRes = await fetch(`${BASE_URL}/api/integrations/memory/store`, {
method: 'POST',
headers,
body: JSON.stringify({
bot_id: bot.id,
content: 'User loves JavaScript'
})
});
const memory = await memoryRes.json();
console.log('Memory ID:', memory.id);
// Search
const searchRes = await fetch(`${BASE_URL}/api/integrations/memory/search`, {
method: 'POST',
headers,
body: JSON.stringify({
bot_id: bot.id,
query: 'programming preferences',
limit: 5
})
});
const results = await searchRes.json();
console.log(`Found ${results.length} memories`);
results.forEach(r => console.log(` - ${r.content}`));
}
main().catch(console.error);const axios = require('axios');
const client = axios.create({
baseURL: 'https://api.memof.ai',
headers: {
'Authorization': `Bearer ${process.env.MEMOFAI_TOKEN}`,
'Content-Type': 'application/json'
}
});
async function main() {
// Create workspace
const { data: workspace } = await client.post('/api/workspaces/workspace/create', {
name: 'My Workspace'
});
// Create bot
const { data: bot } = await client.post('/api/bots/bot/create', {
name: 'My Bot',
workspace_id: workspace.id
});
// Store memory
const { data: memory } = await client.post('/api/integrations/memory/store', {
bot_id: bot.id,
content: 'User loves Node.js'
});
// Search
const { data: results } = await client.post('/api/integrations/memory/search', {
bot_id: bot.id,
query: 'programming',
limit: 5
});
console.log('Results:', results);
}
main();#!/bin/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')
echo "Workspace ID: $WORKSPACE_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\": \"My Bot\", \"workspace_id\": \"$WORKSPACE_ID\"}")
BOT_ID=$(echo $BOT | jq -r '.id')
echo "Bot ID: $BOT_ID"
# Store memory
MEMORY=$(curl -s -X POST "$BASE_URL/api/integrations/memory/store" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"bot_id\": \"$BOT_ID\", \"content\": \"User loves bash scripts\"}")
echo "Memory stored: $(echo $MEMORY | jq -r '.id')"
# Search
RESULTS=$(curl -s -X POST "$BASE_URL/api/integrations/memory/search" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"bot_id\": \"$BOT_ID\", \"query\": \"programming\", \"limit\": 5}")
echo "Search results:"
echo $RESULTS | jq -r '.[] | " - \(.content)"'package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
const baseURL = "https://api.memof.ai"
type Client struct {
httpClient *http.Client
token string
}
func NewClient(token string) *Client {
return &Client{
httpClient: &http.Client{},
token: token,
}
}
func (c *Client) request(method, path string, body interface{}) (map[string]interface{}, error) {
jsonBody, _ := json.Marshal(body)
req, _ := http.NewRequest(method, baseURL+path, bytes.NewBuffer(jsonBody))
req.Header.Set("Authorization", "Bearer "+c.token)
req.Header.Set("Content-Type", "application/json")
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
return result, nil
}
func main() {
client := NewClient(os.Getenv("MEMOFAI_TOKEN"))
// Create workspace
workspace, _ := client.request("POST", "/api/workspaces/workspace/create", map[string]string{
"name": "My Workspace",
})
workspaceID := workspace["id"].(string)
fmt.Println("Workspace ID:", workspaceID)
// Create bot
bot, _ := client.request("POST", "/api/bots/bot/create", map[string]interface{}{
"name": "My Bot",
"workspace_id": workspaceID,
})
botID := bot["id"].(string)
fmt.Println("Bot ID:", botID)
// Store memory
memory, _ := client.request("POST", "/api/integrations/memory/store", map[string]interface{}{
"bot_id": botID,
"content": "User loves Go",
})
fmt.Println("Memory ID:", memory["id"])
// Search
results, _ := client.request("POST", "/api/integrations/memory/search", map[string]interface{}{
"bot_id": botID,
"query": "programming",
"limit": 5,
})
fmt.Println("Search results:", results)
}require 'net/http'
require 'json'
require 'uri'
class MemofaiClient
BASE_URL = 'https://api.memof.ai'
def initialize(token)
@token = token
end
def request(method, path, body = nil)
uri = URI("#{BASE_URL}#{path}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = case method
when 'POST' then Net::HTTP::Post.new(uri)
when 'GET' then Net::HTTP::Get.new(uri)
end
request['Authorization'] = "Bearer #{@token}"
request['Content-Type'] = 'application/json'
request.body = body.to_json if body
response = http.request(request)
JSON.parse(response.body)
end
end
# Usage
client = MemofaiClient.new(ENV['MEMOFAI_TOKEN'])
# Create workspace
workspace = client.request('POST', '/api/workspaces/workspace/create', {
name: 'My Workspace'
})
puts "Workspace ID: #{workspace['id']}"
# Create bot
bot = client.request('POST', '/api/bots/bot/create', {
name: 'My Bot',
workspace_id: workspace['id']
})
puts "Bot ID: #{bot['id']}"
# Store memory
memory = client.request('POST', '/api/integrations/memory/store', {
bot_id: bot['id'],
content: 'User loves Ruby'
})
puts "Memory ID: #{memory['id']}"
# Search
results = client.request('POST', '/api/integrations/memory/search', {
bot_id: bot['id'],
query: 'programming',
limit: 5
})
puts "Found #{results.length} memories"<?php
class MemofaiClient {
private $token;
private $baseURL = 'https://api.memof.ai';
public function __construct($token) {
$this->token = $token;
}
private function request($method, $path, $body = null) {
$ch = curl_init($this->baseURL . $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $this->token,
'Content-Type: application/json'
]);
if ($method === 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
if ($body) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
}
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
public function createWorkspace($name) {
return $this->request('POST', '/api/workspaces/workspace/create', [
'name' => $name
]);
}
public function createBot($name, $workspaceId) {
return $this->request('POST', '/api/bots/bot/create', [
'name' => $name,
'workspace_id' => $workspaceId
]);
}
public function storeMemory($botId, $content) {
return $this->request('POST', '/api/integrations/memory/store', [
'bot_id' => $botId,
'content' => $content
]);
}
public function searchMemories($botId, $query, $limit = 5) {
return $this->request('POST', '/api/integrations/memory/search', [
'bot_id' => $botId,
'query' => $query,
'limit' => $limit
]);
}
}
// Usage
$client = new MemofaiClient(getenv('MEMOFAI_TOKEN'));
$workspace = $client->createWorkspace('My Workspace');
echo "Workspace ID: " . $workspace['id'] . "\n";
$bot = $client->createBot('My Bot', $workspace['id']);
echo "Bot ID: " . $bot['id'] . "\n";
$memory = $client->storeMemory($bot['id'], 'User loves PHP');
echo "Memory ID: " . $memory['id'] . "\n";
$results = $client->searchMemories($bot['id'], 'programming', 5);
echo "Found " . count($results) . " memories\n";
?>use reqwest;
use serde_json::{json, Value};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = env::var("MEMOFAI_TOKEN")?;
let client = reqwest::Client::new();
let base_url = "https://api.memof.ai";
// Create workspace
let workspace: Value = client
.post(format!("{}/api/workspaces/workspace/create", base_url))
.header("Authorization", format!("Bearer {}", token))
.json(&json!({"name": "My Workspace"}))
.send()
.await?
.json()
.await?;
println!("Workspace ID: {}", workspace["id"]);
// Create bot
let bot: Value = client
.post(format!("{}/api/bots/bot/create", base_url))
.header("Authorization", format!("Bearer {}", token))
.json(&json!({
"name": "My Bot",
"workspace_id": workspace["id"]
}))
.send()
.await?
.json()
.await?;
println!("Bot ID: {}", bot["id"]);
// Store memory
let memory: Value = client
.post(format!("{}/api/integrations/memory/store", base_url))
.header("Authorization", format!("Bearer {}", token))
.json(&json!({
"bot_id": bot["id"],
"content": "User loves Rust"
}))
.send()
.await?
.json()
.await?;
println!("Memory ID: {}", memory["id"]);
// Search
let results: Value = client
.post(format!("{}/api/integrations/memory/search", base_url))
.header("Authorization", format!("Bearer {}", token))
.json(&json!({
"bot_id": bot["id"],
"query": "programming",
"limit": 5
}))
.send()
.await?
.json()
.await?;
println!("Search results: {:?}", results);
Ok(())
}Need more? Check the HTTP API documentation for complete endpoint reference!