Create Image
Generate AI images programmatically using the BetterWaifu API.
Endpoint
POST /v1/images/generateRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Text description of the image |
negative_prompt | string | No | Elements to exclude |
model | string | No | Model ID (default: noobai-xl) |
steps | integer | No | Number of steps (20-50, default: 28) |
cfg_scale | number | No | CFG scale (1-20, default: 7) |
width | integer | No | Image width (default: 832) |
height | integer | No | Image height (default: 1216) |
sampler | string | No | Sampler method (default: dpm-2m-karras) |
seed | integer | No | Seed 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 modelduchaiten- Painterly anime styleduchaiten-real- Realistic animehassaku-illustrious- Illustration-focusedwai-nsfw-illustrious- NSFW-specializedplant-milk- Experimental aesthetic
Available Samplers
euler-a- Fast, good qualitydpm-2m-karras- High quality (recommended)dpm-sde-karras- Maximum detailddim- 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
- Optimize parameters - Start with defaults and adjust as needed
- Use webhooks - For async processing in production
- Handle errors - Implement retry logic with exponential backoff
- Cache results - Store generated images to avoid regenerating
- Monitor usage - Track API calls against your rate limits
Related Endpoints
- Get Images - Retrieve generated images
- Delete Image - Remove images
- Webhooks - Async notifications