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.
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.
| Alias | Type | Credits | Description |
|---|---|---|---|
gemma | Text | 1/2 per 1K in/out | Fast & cheap. 256K context, vision, reasoning. |
gpt-oss | Text | 2/4 per 1K in/out | Most intelligent. Complex reasoning, code gen. |
flux-schnell | Image | 10 per image | Fast image generation for prototyping. |
flux-dev | Image | 100 per image | High quality, photorealistic images. |
POST /p/{project_id}/ai/{endpoint_name}
Authorization: Bearer {token}
Content-Type: application/json
{
"text": "MoonDB is a DBaaS built for coding agents..."
}
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 }
Each endpoint has an access field:
"public" — no auth required."auth" (default) — end-user JWT or API key required."admin" — admin key only.Each plan includes free credits per month. When exhausted, buy more via POST /v1/billing/ai-credits. Check your balance in Dashboard → AI.