Create Image

Generate AI images programmatically using the BetterWaifu API.

Endpoint

POST /v1/images/generate

Request Body

ParameterTypeRequiredDescription
promptstringYesText description of the image
negative_promptstringNoElements to exclude
modelstringNoModel ID (default: noobai-xl)
stepsintegerNoNumber of steps (20-50, default: 28)
cfg_scalenumberNoCFG scale (1-20, default: 7)
widthintegerNoImage width (default: 832)
heightintegerNoImage height (default: 1216)
samplerstringNoSampler method (default: dpm-2m-karras)
seedintegerNoSeed for reproducibility (default: -1/random)

Example Request

cURL

curl -X POST https://api.betterwaifu.com/v1/images/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "1girl, long blue hair, detailed eyes, anime style, masterpiece",
    "negative_prompt": "ugly, blurry, low quality",
    "model": "noobai-xl",
    "steps": 30,
    "cfg_scale": 8,
    "width": 832,
    "height": 1216,
    "sampler": "dpm-2m-karras",
    "seed": -1
  }'

Python

import requests
 
url = "https://api.betterwaifu.com/v1/images/generate"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "prompt": "1girl, long blue hair, detailed eyes, anime style, masterpiece",
    "negative_prompt": "ugly, blurry, low quality",
    "model": "noobai-xl",
    "steps": 30,
    "cfg_scale": 8,
    "width": 832,
    "height": 1216
}
 
response = requests.post(url, json=data, headers=headers)
result = response.json()
 
print(f"Image URL: {result['data']['url']}")

JavaScript (Node.js)

const response = await fetch('https://api.betterwaifu.com/v1/images/generate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: '1girl, long blue hair, detailed eyes, anime style, masterpiece',
    negative_prompt: 'ugly, blurry, low quality',
    model: 'noobai-xl',
    steps: 30,
    cfg_scale: 8,
    width: 832,
    height: 1216
  })
});
 
const result = await response.json();
console.log('Image URL:', result.data.url);

Response

Success (200 OK)

{
  "success": true,
  "data": {
    "image_id": "img_abc123def456",
    "url": "https://cdn.betterwaifu.com/images/abc123def456.png",
    "status": "completed",
    "parameters": {
      "prompt": "1girl, long blue hair...",
      "model": "noobai-xl",
      "steps": 30,
      "cfg_scale": 8,
      "width": 832,
      "height": 1216,
      "seed": 1234567890
    },
    "created_at": "2024-01-15T10:30:00Z"
  }
}

Available Models

  • noobai-xl - Versatile anime model
  • duchaiten - Painterly anime style
  • duchaiten-real - Realistic anime
  • hassaku-illustrious - Illustration-focused
  • wai-nsfw-illustrious - NSFW-specialized
  • plant-milk - Experimental aesthetic

Available Samplers

  • euler-a - Fast, good quality
  • dpm-2m-karras - High quality (recommended)
  • dpm-sde-karras - Maximum detail
  • ddim - Quick iterations

Error Responses

Invalid Parameters (400)

{
  "success": false,
  "error": {
    "code": "invalid_parameter",
    "message": "steps must be between 20 and 50",
    "parameter": "steps"
  }
}

Rate Limit Exceeded (429)

{
  "success": false,
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Rate limit exceeded. Please try again in 60 seconds.",
    "retry_after": 60
  }
}

Best Practices

  1. Optimize parameters - Start with defaults and adjust as needed
  2. Use webhooks - For async processing in production
  3. Handle errors - Implement retry logic with exponential backoff
  4. Cache results - Store generated images to avoid regenerating
  5. Monitor usage - Track API calls against your rate limits

Related Endpoints