1. 先选对协议(切勿混用字段)

用途完整请求地址模型与提示词字段
官方 NovelAI 兼容直出(推荐首选)POST https://noveadream.com/ai/generate-imagemodel: nai-diffusion-5-full / nai-diffusion-4-5-full;input;action;parameters
OpenAI 图片客户端简化调用 V4.5POST https://noveadream.com/v1/images/generationsmodel: nai-v4.5;prompt
工作台异步任务、报价预检、Vibe 与 SSEPOST /v1/nai/estimate → POST /v1/nai/generationsmodel: nai-v4.5;model_variant: 具体版本;prompt;quote_id

AI Agent 接入必读:POST /ai/generate-image 根域名不带 /v1,model 必须填具体模型名(严禁填 nai-v4.5 或 nai-v5),提示词字段名为 input(不是 prompt),且成功状态码为 HTTP 201 Created(请判断 200 <= status < 300,不要写死 status == 200)。机器可读规范可直接读取 NAI OpenAPI 3.1 JSON Schema。

2. 配置 API Key 与幂等键

在本站创建 API Key(sk-...),HTTP 请求头携带 Authorization: Bearer <API_KEY>。如果该 Key 开启了模型白名单,请勾选允许公开模型键 nai-v4.5(它同时控制 V3 / V4 / V4.5 / V5 的原生接口权限)。切勿将 NovelAI 官方 pst-... 令牌填入本站。

管理我的 API Key

powershell
$env:NOVEA_API_KEY = "sk-your-noveadream-key"
$env:NOVEA_REQUEST_ID = [guid]::NewGuid().ToString()
$env:REQUEST_ID = $env:NOVEA_REQUEST_ID
bash
export NOVEA_API_KEY="sk-your-noveadream-key"
export REQUEST_ID="$(python3 -c 'import uuid; print(uuid.uuid4())')"
export NOVEA_REQUEST_ID="$REQUEST_ID"

3. 支持的 model ID 与能力矩阵

显示名称model(/ai/generate-image 必填值)独立角色上限精准参考(Precise Reference)
NAI V5 Fullnai-diffusion-5-full32支持(最多 8 张,含服装模式)
NAI V5 Curatednai-diffusion-5-curated32支持(最多 8 张,含服装模式)
NAI V4.5 Fullnai-diffusion-4-5-full6支持(最多 4 张)
NAI V4.5 Curatednai-diffusion-4-5-curated6支持(最多 4 张)
NAI V4 Fullnai-diffusion-4-full6不支持
NAI V4 Curatednai-diffusion-4-curated-preview6不支持
NAI Anime V3nai-diffusion-30不支持
NAI Furry V3nai-diffusion-furry-30不支持

局部蒙版重绘(action: "infill")时使用对应的 -inpainting 后缀模型名(例如 nai-diffusion-5-full-inpainting)。V5 节约档(Medium)仅限网页工作台会员使用,API 不接受 -medium。

在酒馆 SillyTavern 与第三方客户端配置地址

4. 交互式完整代码示例(Python / Node.js / JSON)

切换模型与操作即可自动生成零依赖可运行脚本(支持 V5 / V4.5 文生图、图生图、蒙版重绘、精准参考与多角色)。

POST /ai/generate-image

下载默认文生图 Python 脚本 · 查看完整参数字典、多角色 v4_prompt 与 V5/V4.5 精准参考 JSON

5. 使用 cURL 直接提交

将下方 JSON 保存为 request.json。服务端启用严格字段检查:切勿传入未文档化的未知字段或 null 值(随机种子请直接省略 seed 键,不要传 seed: null 或 -1)。

json
{
  "input": "watercolor, a blue ceramic teapot on a wooden table, soft daylight",
  "model": "nai-diffusion-5-full",
  "action": "generate",
  "parameters": {
    "width": 832,
    "height": 1216,
    "steps": 23,
    "n_samples": 1,
    "scale": 5,
    "seed": 42,
    "sampler": "k_euler_ancestral",
    "negative_prompt": "lowres, blurry"
  }
}
bash
curl --fail-with-body 'https://noveadream.com/ai/generate-image' \
  -H "Authorization: Bearer $NOVEA_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H "Idempotency-Key: $REQUEST_ID" \
  --data-binary @request.json

6. 响应解析(JSON / 官方 ZIP 双模式)与错误码

请求头 / 场景HTTP 状态码与返回结构
Accept: application/json(推荐脚本使用)201 Created;返回 {"images": [{"image": "纯Base64 PNG(无 data: 前缀)", "index": 0, "seed": 42}]}。注意不是 OpenAI 的 data[].url。
省略 Accept 或传 application/zip(官方默认兼容)201 Created;Content-Type: application/zip 二进制流,解压得到 image_0.png、image_1.png…,与官方 image.novelai.net 完全一致。
响应头 X-Generation-ID服务端生图任务 ID,可用于工单排查。
错误响应(400 / 401 / 402 / 403 / 409 / 502 / 504)控制器返回 {"statusCode": 400, "message": "具体原因"}(402 为余额不足,403 为 Key 模型白名单或账号限制,409 为幂等键参数冲突或并发占用);鉴权/限流网关(401/429)可能返回 {"error": {"message": "..."}}。遇到 504 请检查响应头 X-Retry-Same-Key:为 true 时任务仍在运行,用原 Idempotency-Key 重试取图;为 false 时任务已终态超时退款,重新提交请换新 UUID。
json
{
  "images": [
    {
      "image": "BASE64_PNG",
      "index": 0,
      "seed": 42
    }
  ]
}
python
import io, json, os, uuid, zipfile
from urllib.request import Request, urlopen

payload = {
    "input": "1girl, solo, watercolor, soft daylight",
    "model": "nai-diffusion-5-full",
    "action": "generate",
    "parameters": {
        "width": 832, "height": 1216, "steps": 23, "n_samples": 1,
        "scale": 5, "seed": 42, "sampler": "k_euler_ancestral", "negative_prompt": "lowres, blurry"
    }
}
req = Request(
    "https://noveadream.com/ai/generate-image",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": f"Bearer {os.environ['NOVEA_API_KEY']}",
        "Content-Type": "application/json",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    method="POST",
)
with urlopen(req, timeout=660) as resp:
    assert 200 <= resp.status < 300  # HTTP 201 Created
    with zipfile.ZipFile(io.BytesIO(resp.read())) as zf:
        zf.extractall("outputs")  # Extracts image_0.png, image_1.png ...

需要报价预检、Vibe 风格迁移或 SSE 实时流式状态:查看 /v1/nai/* 扩展接口