AI Endpoints

MoonDB includes built-in AI endpoints powered by Cloudflare Workers AI. Define endpoints in your schema, call them via the REST API, and pay with credits.

Defining AI endpoints

Add an ai_endpoints section to your schema:

{
  "tables": { ... },
  "ai_endpoints": {
    "summarize": {
      "model": "gemma",
      "prompt": "Summarize this text in 2 sentences: {{text}}",
      "access": "auth"
    },
    "generate_avatar": {
      "model": "flux-schnell",
      "prompt": "A minimal avatar for a user named {{name}}, flat design",
      "access": "auth"
    }
  }
}

Template parameters ({{name}}) are filled from the request body at call time.

Available models

AliasTypeCreditsDescription
gemmaText1/2 per 1K in/outFast & cheap. 256K context, vision, reasoning.
gpt-ossText2/4 per 1K in/outMost intelligent. Complex reasoning, code gen.
flux-schnellImage10 per imageFast image generation for prototyping.
flux-devImage100 per imageHigh quality, photorealistic images.

Calling an endpoint

POST /p/{project_id}/ai/{endpoint_name}
Authorization: Bearer {token}
Content-Type: application/json

{
  "text": "MoonDB is a DBaaS built for coding agents..."
}

Response

Text models return:

{ "type": "text", "result": "...", "model": "gemma", "credits_used": 3 }

Image models return base64-encoded data:

{ "type": "image", "image": "data:image/png;base64,...", "model": "flux-schnell", "credits_used": 10 }

Access control

Each endpoint has an access field:

Credits

Each plan includes free credits per month. When exhausted, buy more via POST /v1/billing/ai-credits. Check your balance in Dashboard → AI.