Manual Setup

If you prefer working without a coding agent, store credentials in .env:

# .env
MOONDB_API_BASE=https://moondb.ai/p/{project_id}
MOONDB_ADMIN_KEY=sk_...
MOONDB_PUBLIC_KEY=pk_...

Client-side usage

Use the public key for browser reads. MoonDB has CORS enabled so any origin can call the API.

// Read tasks
const res = await fetch(
  `$https://moondb.ai/api/tasks?sort=created_at.desc&limit=20`,
  { headers: { 'X-Public-Key': 'pk_...' } }
);
const { data } = await res.json();

// Create task (requires auth token)
const res = await fetch(`$https://moondb.ai/api/tasks`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + userToken
  },
  body: JSON.stringify({ title: 'Buy milk', done: false })
});

Server-side usage

Use the admin key for schema changes and privileged operations. Never expose it to the client.

// Node.js / server-side
const res = await fetch(`$https://moondb.ai/v1/schema`, {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'X-Admin-Key': process.env.MOONDB_ADMIN_KEY
  },
  body: JSON.stringify({ tables: { ... } })
});