Getting Started

Authentication

All API requests require a Bearer token in the Authorization header.

Header
Authorization: Bearer md_your_api_key_here

To get an API key, create an account via the sign-up flow:

POST /v1/auth/send-code

Send a verification code to your email.

ParamTypeDescription
emailrequiredstringYour email address
Send verification code
curl -X POST https://mdraftai-production.up.railway.app/v1/auth/send-code \
  -H "Content-Type: application/json" \
  -d '{ "email": "you@example.com" }'

POST /v1/auth/verify

Verify the code and receive your API key. You get 50 free credits on signup.

ParamTypeDescription
emailrequiredstringYour email address
coderequiredstring6-digit code from your email
Verify and get API key
curl -X POST https://mdraftai-production.up.railway.app/v1/auth/verify \
  -H "Content-Type: application/json" \
  -d '{ "email": "you@example.com", "code": "123456" }'
50 free credits on signup. No credit card required.

Base URL

https://mdraftai-production.up.railway.app

All endpoints are prefixed with /v1.


Image Generation

Generate Image

POST /v1/generate

Generate a single image from a text prompt. Optionally pass a style or character reference image.

ParamTypeDescription
promptrequiredstringWhat to generate (max 4,000 chars)
qualitystringstandard (default) or premium
aspect_ratiostringOutput ratio (default 16:9). See table below.
style_refstringBase64 image to match the visual style of
character_refstringBase64 image of a character to keep consistent

Supported aspect ratios:

RatioResolution
1:11024 x 1024
16:91344 x 768
9:16768 x 1344
3:21216 x 832
2:3832 x 1216
4:31152 x 896
3:4896 x 1152

Response:

Response
{
  "success": true,
  "quality": "standard",
  "image": "data:image/png;base64,..."
}
Credits: 1 credit (standard) or 3 credits (premium) per image.
Generate an image
curl -X POST https://mdraftai-production.up.railway.app/v1/generate \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "product photo of sneakers on marble",
    "quality": "premium",
    "aspect_ratio": "1:1"
  }'
With style reference
curl -X POST https://mdraftai-production.up.railway.app/v1/generate \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "hero illustration for a fintech landing page",
    "style_ref": "data:image/png;base64,..."
  }'

Batch Generate

POST /v1/generate/batch

Generate up to 10 images in a single request. Same options as /v1/generate, but with an array of prompts.

ParamTypeDescription
promptsrequiredstring[]Array of prompts (max 10)
qualitystringstandard (default) or premium
aspect_ratiostringApplied to all images
style_refstringBase64 style reference for all images
character_refstringBase64 character reference for all images

Response:

Response
{
  "results": [
    { "prompt": "hero shot", "image": "data:image/png;base64,...", "success": true },
    { "prompt": "side angle", "image": "data:image/png;base64,...", "success": true }
  ],
  "quality": "premium"
}
Credits: Per-image cost (1 or 3) multiplied by number of prompts.
Batch generate
curl -X POST https://mdraftai-production.up.railway.app/v1/generate/batch \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{
    "prompts": ["hero shot", "side angle", "close-up detail"],
    "quality": "premium",
    "style_ref": "data:image/png;base64,..."
  }'

Edit Image

POST /v1/edit

Edit an existing image with a text prompt. Describe the changes you want.

ParamTypeDescription
promptrequiredstringWhat to change
imagerequiredstringBase64-encoded source image

Response:

Response
{
  "success": true,
  "image": "data:image/png;base64,..."
}
Credits: 1 credit per edit.
Edit an image
curl -X POST https://mdraftai-production.up.railway.app/v1/edit \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "change the background to a beach sunset",
    "image": "data:image/png;base64,..."
  }'

Video Generation

Video

POST /v1/video

Generate a 5-second MP4 video. The endpoint uses smart routing based on what you send:

InputModeWhat happens
prompt onlyText-to-videoGenerates video from the description
prompt + imageImage-to-videoAnimates the provided image
image + audioTalking avatarLip-syncs the image to the audio
ParamTypeDescription
promptstringDescription or motion direction
imagestringBase64 image to animate
audiostringBase64 audio for talking avatar
Credits: 10 credits per video. Output: 5-second MP4.
Text to video
curl -X POST https://mdraftai-production.up.railway.app/v1/video \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{ "prompt": "slow pan across mountain lake, sunrise" }'
Animate an image
curl -X POST https://mdraftai-production.up.railway.app/v1/video \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "gentle push in with parallax",
    "image": "data:image/png;base64,..."
  }'
Talking avatar
curl -X POST https://mdraftai-production.up.railway.app/v1/video \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,...",
    "audio": "data:audio/mp3;base64,..."
  }'

Enhancement

Enhance

POST /v1/enhance

Upscale an image to 2x resolution.

ParamTypeDescription
imagerequiredstringBase64-encoded image to upscale

Response:

Response
{
  "success": true,
  "image": "data:image/png;base64,..."
}
Credits: 2 credits per enhancement.
Enhance an image
curl -X POST https://mdraftai-production.up.railway.app/v1/enhance \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{ "image": "data:image/png;base64,..." }'

Prompt

Prompt Refinement

POST /v1/prompt/refine

Automatically rewrite a rough prompt into a detailed, production-quality prompt optimized for generation.

ParamTypeDescription
promptrequiredstringYour rough prompt
modestringimage (default) or video

Response:

Response
{
  "refined_prompt": "A pair of white leather sneakers resting on a slab of Calacatta marble, soft directional lighting from upper left, shallow depth of field..."
}
Free -- no credits charged.
Refine a prompt
curl -X POST https://mdraftai-production.up.railway.app/v1/prompt/refine \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{ "prompt": "sneakers on marble", "mode": "image" }'

Credits

Check Balance

GET /v1/credits

Returns your current credit balance.

Check balance
curl https://mdraftai-production.up.railway.app/v1/credits \
  -H "Authorization: Bearer md_..."

Usage History

GET /v1/usage

Returns your last 100 actions with timestamps, types, and credit costs.

Get usage history
curl https://mdraftai-production.up.railway.app/v1/usage \
  -H "Authorization: Bearer md_..."

Buy Credits

POST /v1/credits/buy

Purchase a credit pack. Returns a Stripe checkout URL.

ParamTypeDescription
packrequiredstringpack_100, pack_300, or pack_1000

Response:

Response
{
  "checkout_url": "https://checkout.stripe.com/..."
}
Buy credits
curl -X POST https://mdraftai-production.up.railway.app/v1/credits/buy \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{ "pack": "pack_300" }'

Auto-Reload

Set a threshold so your credits automatically replenish when they run low. Your app never stops generating.

POST /v1/credits/auto-reload

Enable or update auto-reload settings.

ParamTypeDescription
thresholdrequirednumberReload when balance drops below this
packrequiredstringpack_100, pack_300, or pack_1000
Enable auto-reload
curl -X POST https://mdraftai-production.up.railway.app/v1/credits/auto-reload \
  -H "Authorization: Bearer md_..." \
  -H "Content-Type: application/json" \
  -d '{ "threshold": 50, "pack": "pack_1000" }'

GET /v1/credits/auto-reload

Check current auto-reload settings.

Get auto-reload settings
curl https://mdraftai-production.up.railway.app/v1/credits/auto-reload \
  -H "Authorization: Bearer md_..."

DELETE /v1/credits/auto-reload

Disable auto-reload.

Disable auto-reload
curl -X DELETE https://mdraftai-production.up.railway.app/v1/credits/auto-reload \
  -H "Authorization: Bearer md_..."

Reference

Rate Limits

Per-minute limits per API key. Exceeding these returns 429 Too Many Requests.

EndpointMethodLimit
/v1/generatePOST10 req/min
/v1/generate/batchPOST3 req/min
/v1/editPOST10 req/min
/v1/videoPOST5 req/min
/v1/enhancePOST10 req/min
/v1/prompt/refinePOST20 req/min
/v1/creditsGET30 req/min
/v1/usageGET10 req/min
/v1/credits/buyPOST5 req/min
/v1/credits/auto-reloadPOST/GET/DELETE10 req/min
/v1/auth/send-codePOST3 req/min
/v1/auth/verifyPOST5 req/min

Error Handling

All errors return JSON with an error string.

Error response format
{
  "error": "Insufficient credits. You need 3 credits but have 1."
}

HTTP status codes:

CodeMeaning
400Bad request -- missing or invalid parameters
401Unauthorized -- invalid or missing API key
402Insufficient credits
404Endpoint not found
410Content policy violation -- prompt was rejected
413Payload too large -- image exceeds 10 MB or body exceeds 50 MB
429Rate limit exceeded -- slow down
500Internal server error
503Service temporarily unavailable

Common errors:

ErrorWhat to do
Content policy410Rephrase your prompt. The content was flagged.
Insufficient credits402Buy more credits or enable auto-reload.
Generation failed500Retry. Credits are auto-refunded on failure.
Timed out503Retry after a few seconds. Credits are refunded.
Credits are automatically refunded when a generation fails or times out.

Input Limits

LimitValue
Max prompt length4,000 characters
Max image size10 MB (base64-encoded)
Max batch size10 prompts
Max request body50 MB

MCP Integration

POST /mcp

Moondraft exposes all generation tools via the Model Context Protocol. This means you can generate images and video directly from Claude Code, Cursor, Windsurf, or any MCP-compatible client.

Add this to your ~/.mcp.json:

~/.mcp.json
{
  "mcpServers": {
    "moondraft": {
      "type": "url",
      "url": "https://mdraftai-production.up.railway.app/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

Once configured, your AI coding assistant can generate images, create videos, enhance assets, and manage credits -- all from natural language in your terminal or editor.

Example usage in Claude Code
# In your terminal, just ask:
"Generate a hero illustration for the landing page and save it to assets/"
"Create 5 onboarding illustrations matching the app's color scheme"
"Animate this product photo with a slow zoom"