API Reference

Complete reference for the TaleCraft AI illustration generation API.

Endpoint

POST https://talescaleai.com/api/v1/generate

Authentication

All requests require an API key passed via the X-API-Key header.

HeaderRequiredDescription
X-API-KeyYesYour personal API key from the dashboard
Content-TypeYesMust be application/json

Getting Your API Key

  1. Log in to your TaleCraft AI account
  2. Navigate to Settings → API Keys
  3. Click Create New API Key
  4. Copy and securely store your key

Security: Keep your API key confidential. Do not expose it in client-side code or public repositories.

Request Body

FieldTypeRequiredDefaultDescription
promptstringYesScene description for the illustration
stylestringNo"children_book"Illustration style. Currently supported: children_book
aspect_ratiostringNo"1:1"Image aspect ratio

Supported Aspect Ratios

ValueDescription
1:1Square (default)
2:3Portrait
3:2Landscape
3:4Portrait (taller)
4:3Landscape (wider)
9:16Vertical / mobile
16:9Widescreen

Response

Success

{
  "code": 0,
  "message": "ok",
  "data": {
    "id": "9da9465c-a56c-4614-81af-257aaccb2646",
    "status": "success",
    "image_url": "https://pub-56194e5487384280af43a03cc4ea8ee4.r2.dev/uploads/illustrations/6188896c-ee02-4e70-881b-483bcbb1739c.jpeg"
  }
}
FieldTypeDescription
codenumber0 indicates success
messagestring"ok" on success
data.idstringUnique task ID (UUID)
data.statusstring"success" for successful generation
data.image_urlstringDirect URL to the generated image

Error

{
  "code": -1,
  "message": "Error description"
}
FieldTypeDescription
codenumber-1 indicates error
messagestringHuman-readable error description

Error Messages

MessageCauseSolution
API key is required. Please provide X-API-Key header.Missing headerAdd X-API-Key header
Invalid API keyKey not found or revokedCheck your key is correct and active
prompt is requiredEmpty or missing promptProvide a non-empty prompt field
Unsupported styleInvalid style valueUse children_book
Unsupported aspect_ratioInvalid ratio valueUse a supported ratio (see table above)
insufficient creditsNo remaining creditsPurchase more credits
Generation failedAI model errorRetry or modify your prompt

Code Examples

cURL

curl -X POST https://talescaleai.com/api/v1/generate \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A brave knight in an enchanted forest",
    "style": "children_book",
    "aspect_ratio": "16:9"
  }'

TypeScript / JavaScript

const response = await fetch('https://talescaleai.com/api/v1/generate', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'A brave knight in an enchanted forest',
    style: 'children_book',
    aspect_ratio: '16:9'
  })
});

const result = await response.json();

if (result.code !== 0) {
  throw new Error(result.message);
}

console.log(result.data.image_url);

Python

import requests

response = requests.post(
    'https://talescaleai.com/api/v1/generate',
    headers={
        'X-API-Key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'prompt': 'A brave knight in an enchanted forest',
        'style': 'children_book',
        'aspect_ratio': '16:9'
    }
)

result = response.json()

if result['code'] != 0:
    raise Exception(result['message'])

print(result['data']['image_url'])