API 参考

TaleCraft AI 插画生成 API 完整参考文档。

端点

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

认证

所有请求都需要通过 X-API-Key 请求头传递 API Key。

请求头必填说明
X-API-Key从控制面板获取的 API Key
Content-Type必须为 application/json

获取 API Key

  1. 登录你的 TaleCraft AI 账户
  2. 前往 设置 → API Keys
  3. 点击 创建 API Key
  4. 复制并安全存储

安全提示:请妥善保管你的 API Key,不要在客户端代码或公开仓库中暴露。

请求体

字段类型必填默认值说明
promptstring插画场景描述
stylestring"children_book"插画风格,目前支持:children_book
aspect_ratiostring"1:1"图片宽高比

支持的宽高比

说明
1:1正方形(默认)
2:3竖版
3:2横版
3:4竖版(更高)
4:3横版(更宽)
9:16竖屏 / 手机
16:9宽屏

响应

成功

{
  "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"
  }
}
字段类型说明
codenumber0 表示成功
messagestring成功时为 "ok"
data.idstring唯一任务 ID (UUID)
data.statusstring成功生成时为 "success"
data.image_urlstring生成图片的直接链接

错误

{
  "code": -1,
  "message": "错误描述"
}

错误信息

错误信息原因解决方案
API key is required...缺少请求头添加 X-API-Key 请求头
Invalid API keyKey 无效或已撤销检查 Key 是否正确且有效
prompt is requiredprompt 为空提供非空的 prompt 字段
Unsupported stylestyle 值无效使用 children_book
Unsupported aspect_ratio比例值无效使用支持的比例(见上表)
insufficient credits积分不足购买更多积分
Generation failedAI 模型错误重试或修改 prompt

代码示例

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'])