{
  "openapi": "3.1.0",
  "info": {
    "title": "NoveaDream NovelAI-Compatible Image Generation API",
    "version": "2026.12",
    "summary": "NovelAI (image.novelai.net) compatible image generation endpoint and NoveaDream workbench extension endpoints.",
    "description": "Use your NoveaDream site API key (`Authorization: Bearer sk-...`). Base URL for native NovelAI image requests is `https://noveadream.com` (do NOT append `/v1` to `/ai/generate-image`). Unknown JSON keys and `null` parameter values (except `skip_cfg_above_sigma: null`) are rejected with HTTP 400 before billing. String byte limits (`input` / `negative_prompt` <= 20,000 UTF-8 bytes; character captions <= 4,000 UTF-8 bytes) are enforced on raw UTF-8 byte length."
  },
  "servers": [
    {
      "url": "https://noveadream.com",
      "description": "Production API Server"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "NoveaDream API Key (`sk-...`). If model allowlist is enabled on the key, include `nai-v4.5`."
      }
    },
    "schemas": {
      "NativeError": {
        "type": "object",
        "required": ["statusCode", "message"],
        "properties": {
          "statusCode": { "type": "integer", "example": 400 },
          "message": { "type": "string", "example": "invalid novelai request: unsupported or invalid parameters.autoSmea" }
        }
      },
      "GatewayMiddlewareError": {
        "type": "object",
        "description": "Returned by authentication / rate-limit middleware before entering the native NovelAI controller.",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["message"],
            "properties": {
              "message": { "type": "string", "example": "Invalid token" },
              "type": { "type": "string", "example": "new_api_error" },
              "code": { "type": ["string", "null"] }
            }
          }
        }
      },
      "V4Center": {
        "type": "object",
        "additionalProperties": false,
        "required": ["x", "y"],
        "properties": {
          "x": { "type": "number", "minimum": 0, "maximum": 1, "example": 0.3 },
          "y": { "type": "number", "minimum": 0, "maximum": 1, "example": 0.5 }
        }
      },
      "V4CharCaption": {
        "type": "object",
        "additionalProperties": false,
        "required": ["char_caption", "centers"],
        "properties": {
          "char_caption": {
            "type": "string",
            "description": "Tags describing this individual character (or negative tags in `v4_negative_prompt`). Max 4,000 UTF-8 bytes."
          },
          "centers": {
            "type": "array",
            "maxItems": 32,
            "items": { "$ref": "#/components/schemas/V4Center" }
          }
        }
      },
      "V4Prompt": {
        "type": "object",
        "additionalProperties": false,
        "required": ["caption"],
        "properties": {
          "caption": {
            "type": "object",
            "additionalProperties": false,
            "required": ["base_caption", "char_captions"],
            "properties": {
              "base_caption": {
                "type": "string",
                "description": "Global scene caption (must match top-level `input` / `negative_prompt`). Max 20,000 UTF-8 bytes."
              },
              "char_captions": {
                "type": "array",
                "description": "Up to 6 characters on V4/V4.5; up to 32 characters on V5. Keep matching order between v4_prompt and v4_negative_prompt.",
                "items": { "$ref": "#/components/schemas/V4CharCaption" }
              }
            }
          },
          "use_coords": {
            "type": "boolean",
            "default": false,
            "description": "`false` lets the model place characters automatically; `true` uses `centers` coordinates."
          },
          "use_order": { "type": "boolean", "default": true },
          "legacy_uc": { "type": "boolean", "default": false }
        }
      },
      "CharacterPromptMirrorItem": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "enabled": { "type": "boolean", "const": true },
          "prompt": { "type": "string" },
          "uc": { "type": "string" },
          "center": { "$ref": "#/components/schemas/V4Center" }
        },
        "description": "Optional client editor mirror; if non-empty, every entry must be enabled and match `v4_prompt` / `v4_negative_prompt`."
      },
      "NativeImg2ImgNested": {
        "type": "object",
        "additionalProperties": false,
        "required": ["strength"],
        "properties": {
          "strength": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
          "color_correct": { "type": "boolean" }
        },
        "description": "Optional nested img2img mirror sent by official NovelAI clients; `strength` must match `parameters.strength`."
      },
      "DirectorReferenceDescription": {
        "type": "object",
        "additionalProperties": false,
        "required": ["caption"],
        "properties": {
          "caption": {
            "type": "object",
            "additionalProperties": false,
            "required": ["base_caption", "char_captions"],
            "properties": {
              "base_caption": {
                "type": "string",
                "enum": [
                  "character",
                  "style",
                  "character&style",
                  "costume",
                  "character_mainoutfit",
                  "character&style_anyoutfit"
                ],
                "description": "`costume`, `character_mainoutfit`, and `character&style_anyoutfit` require NAI V5 (`nai-diffusion-5-full` or `nai-diffusion-5-curated`)."
              },
              "char_captions": {
                "type": "array",
                "maxItems": 0,
                "items": {},
                "description": "Must always be an empty array `[]`."
              }
            }
          },
          "legacy_uc": { "type": "boolean" }
        }
      },
      "NativeParameters": {
        "type": "object",
        "additionalProperties": false,
        "required": ["width", "height"],
        "properties": {
          "width": {
            "type": "integer",
            "minimum": 64,
            "maximum": 3072,
            "multipleOf": 64,
            "description": "Must be a multiple of 64, and `width * height <= 3145728`.",
            "example": 832
          },
          "height": {
            "type": "integer",
            "minimum": 64,
            "maximum": 3072,
            "multipleOf": 64,
            "example": 1216
          },
          "steps": {
            "type": "integer",
            "minimum": 0,
            "maximum": 50,
            "default": 28,
            "description": "1..50 sampling steps (0 or omitted defaults to 28).",
            "example": 23
          },
          "n_samples": {
            "type": "integer",
            "minimum": 0,
            "maximum": 4,
            "default": 1,
            "description": "1..4 outputs per request (0 or omitted defaults to 1)."
          },
          "scale": { "type": "number", "minimum": 0, "maximum": 10, "default": 5 },
          "sampler": {
            "type": "string",
            "enum": [
              "k_euler_ancestral",
              "k_euler",
              "k_dpmpp_2s_ancestral",
              "k_dpmpp_2m_sde",
              "k_dpmpp_2m",
              "k_dpmpp_sde"
            ],
            "default": "k_euler_ancestral"
          },
          "noise_schedule": {
            "type": "string",
            "enum": ["karras", "exponential", "polyexponential"],
            "default": "karras",
            "description": "Used by V3 / V4 / V4.5; ignored on V5."
          },
          "seed": {
            "type": "integer",
            "minimum": 0,
            "maximum": 4294967295,
            "description": "Omit for a random seed; `0` is a valid fixed seed. Do NOT pass `null` or negative numbers."
          },
          "extra_noise_seed": {
            "type": "integer",
            "minimum": -1,
            "maximum": 4294967295
          },
          "prompt": {
            "type": "string",
            "description": "Optional mirror of top-level `input`; if present, must equal `input`."
          },
          "negative_prompt": {
            "type": "string",
            "default": "",
            "description": "Negative prompt (max 20,000 UTF-8 bytes). Pass `\"\"` when empty, never `null`."
          },
          "uc": {
            "type": "string",
            "description": "Optional alias of `negative_prompt`; if both are sent, they must match."
          },
          "cfg_rescale": { "type": "number", "minimum": 0, "maximum": 1, "default": 0 },
          "skip_cfg_above_sigma": {
            "type": ["number", "null"],
            "minimum": 0,
            "maximum": 1000
          },
          "image": {
            "type": "string",
            "description": "Raw Base64 PNG/JPEG/WebP (no `data:image/...` prefix) for `img2img` and `infill`. Max 24 MiB and 16,777,216 pixels (16 MP)."
          },
          "mask": {
            "type": "string",
            "description": "Raw Base64 black-and-white PNG/JPEG/WebP mask for `infill` (white = redraw, black = keep). Must match `image` dimensions; max 24 MiB and 16,777,216 pixels (16 MP)."
          },
          "strength": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 1,
            "description": "Required and > 0 when `image` is provided (`img2img` / `infill`)."
          },
          "noise": { "type": "number", "minimum": 0, "maximum": 1, "default": 0 },
          "mask_blur": { "type": "integer", "minimum": 0, "maximum": 16 },
          "img2img": { "$ref": "#/components/schemas/NativeImg2ImgNested" },
          "inpaintImg2ImgStrength": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 1,
            "description": "When `action` is `infill`, must equal `strength`; otherwise must be `1` if sent."
          },
          "v4_prompt": { "$ref": "#/components/schemas/V4Prompt" },
          "v4_negative_prompt": { "$ref": "#/components/schemas/V4Prompt" },
          "characterPrompts": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/CharacterPromptMirrorItem" }
          },
          "director_reference_images": {
            "type": "array",
            "description": "Precise Reference raw Base64 images (max 24 MiB and 24,000,000 pixels / 24 MP per image). Max 4 on V4.5; max 8 on V5 (not supported during V5 infill). Must match lengths of the 4 companion arrays.",
            "items": { "type": "string" }
          },
          "director_reference_descriptions": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/DirectorReferenceDescription" }
          },
          "director_reference_strength_values": {
            "type": "array",
            "description": "`0..1` on V4.5; `0..5` on V5.",
            "items": { "type": "number", "minimum": 0, "maximum": 5 }
          },
          "director_reference_secondary_strength_values": {
            "type": "array",
            "description": "`0..1` (`1 - fidelity`) on V4.5; MUST be `0` for every entry on V5.",
            "items": { "type": "number", "minimum": 0, "maximum": 1 }
          },
          "director_reference_information_extracted": {
            "type": "array",
            "description": "MUST be `1` for every entry.",
            "items": { "type": "number", "const": 1 }
          },
          "stream": {
            "type": "string",
            "const": "msgpack",
            "description": "Client compatibility hint accepted on the synchronous endpoint."
          },
          "cfg_sched_eligibility": {
            "type": "string",
            "const": "enable_for_post_summer_samplers"
          },
          "params_version": { "type": "integer", "minimum": -1, "maximum": 4 },
          "ucPreset": { "type": "integer", "minimum": -1, "maximum": 4 },
          "tag_hint_qt": { "type": "integer", "minimum": -1, "maximum": 4 },
          "tag_hint_uc_preset": { "type": "integer", "minimum": -1, "maximum": 4 },
          "qualityToggle": { "type": "boolean" },
          "prefer_brownian": { "type": "boolean" },
          "deliberate_euler_ancestral_bug": { "type": "boolean" },
          "dynamic_thresholding": { "type": "boolean" },
          "legacy": { "type": "boolean" },
          "legacy_v3_extend": { "type": "boolean" },
          "legacy_uc": { "type": "boolean" },
          "use_coords": { "type": "boolean" },
          "use_order": { "type": "boolean" },
          "normalize_reference_strength_multiple": { "type": "boolean" },
          "add_original_image": { "type": "boolean" },
          "color_correct": { "type": "boolean" },
          "straight_alpha": { "type": "boolean" },
          "tag_hint_transparent_background": { "type": "boolean" },
          "autoSmea": {
            "type": "boolean",
            "const": false,
            "description": "Legacy SMEA is unsupported; only `false` is accepted."
          },
          "sm": {
            "type": "boolean",
            "const": false,
            "description": "Compatibility-only field; must be `false` if sent."
          },
          "sm_dyn": {
            "type": "boolean",
            "const": false,
            "description": "Compatibility-only field; must be `false` if sent."
          },
          "upscaled_enhance": {
            "type": "boolean",
            "const": false,
            "description": "Compatibility-only field; must be `false` if sent."
          },
          "controlnet_strength": {
            "type": "number",
            "const": 1,
            "description": "Compatibility-only default; must be `1` if sent."
          },
          "uncond_scale": {
            "type": "number",
            "const": 1,
            "description": "Compatibility-only default; must be `1` if sent."
          },
          "reference_image_multiple": { "type": "array", "maxItems": 0, "items": {} },
          "reference_information_extracted_multiple": { "type": "array", "maxItems": 0, "items": {} },
          "reference_strength_multiple": { "type": "array", "maxItems": 0, "items": {} },
          "reference_image_multiple_cached": { "type": "array", "maxItems": 0, "items": {} },
          "director_reference_images_cached": { "type": "array", "maxItems": 0, "items": {} }
        }
      },
      "NativeGenerateRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["input", "model", "action", "parameters"],
        "properties": {
          "input": {
            "type": "string",
            "minLength": 1,
            "description": "Non-empty positive prompt tags or natural language caption (max 20,000 UTF-8 bytes).",
            "example": "1girl, solo, watercolor, a quiet sunlit studio"
          },
          "model": {
            "type": "string",
            "enum": [
              "nai-diffusion-5-full",
              "nai-diffusion-5-curated",
              "nai-diffusion-5-full-inpainting",
              "nai-diffusion-5-curated-inpainting",
              "nai-diffusion-4-5-full",
              "nai-diffusion-4-5-curated",
              "nai-diffusion-4-5-full-inpainting",
              "nai-diffusion-4-5-curated-inpainting",
              "nai-diffusion-4-full",
              "nai-diffusion-4-curated-preview",
              "nai-diffusion-4-full-inpainting",
              "nai-diffusion-4-curated-preview-inpainting",
              "nai-diffusion-3",
              "nai-diffusion-3-inpainting",
              "nai-diffusion-furry-3",
              "nai-diffusion-furry-3-inpainting"
            ],
            "description": "Exact NovelAI model ID. Append `-inpainting` ONLY when `action` is `infill` (`nai-diffusion-5-curated-inpainting` automatically routes to `nai-diffusion-5-full-inpainting` upstream). Never pass `nai-v4.5` or `nai-v5` here."
          },
          "action": {
            "type": "string",
            "enum": ["generate", "img2img", "infill"]
          },
          "parameters": { "$ref": "#/components/schemas/NativeParameters" },
          "use_new_shared_trial": {
            "type": "boolean",
            "description": "Client compatibility hint only; never affects NoveaDream billing or trial quota."
          }
        }
      },
      "NativeJsonResponse": {
        "type": "object",
        "required": ["images"],
        "properties": {
          "images": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["image", "index"],
              "properties": {
                "image": {
                  "type": "string",
                  "description": "Raw Base64-encoded PNG bytes (no `data:image/png;base64,` prefix)."
                },
                "index": { "type": "integer", "example": 0 },
                "seed": { "type": "integer", "example": 42 }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/ai/generate-image": {
      "post": {
        "operationId": "generateNaiImageNative",
        "summary": "Generate images using the native NovelAI protocol",
        "description": "Single-step synchronous generation compatible with `image.novelai.net/ai/generate-image`. Returns HTTP **201 Created** on success. Set `Accept: application/json` to receive Base64 PNG strings in JSON, or omit `Accept` (or pass `Accept: application/zip`) to receive a standard NovelAI `.zip` archive containing `image_0.png`, `image_1.png`, etc.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": { "type": "string", "maxLength": 200 },
            "description": "Client-generated UUID. Reuse ONLY when `X-Retry-Same-Key: true` (or network disconnect while task is running); reusing with modified parameters returns 409 Conflict."
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["application/json", "application/zip"]
            },
            "description": "Pass `application/json` for Base64 JSON response; omit or pass `application/zip` for official NovelAI ZIP binary."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/NativeGenerateRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Images generated successfully (`201 Created`).",
            "headers": {
              "X-Generation-ID": {
                "schema": { "type": "string" },
                "description": "Server generation task ID for diagnostics."
              },
              "Idempotency-Key": {
                "schema": { "type": "string" }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeJsonResponse" }
              },
              "application/zip": {
                "schema": { "type": "string", "format": "binary" }
              }
            }
          },
          "400": {
            "description": "Invalid parameters, unknown JSON field, `null` value, or invalid/oversized image (`image`/`mask` > 16 MP, `director_reference_images` > 24 MP, or > 24 MiB).",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "401": {
            "description": "Missing, expired, or invalid Bearer API key (returned by auth middleware as `{\"error\": ...}`).",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/GatewayMiddlewareError" },
                    { "$ref": "#/components/schemas/NativeError" }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "Insufficient wallet balance or NAI points for the quoted request.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "403": {
            "description": "API key model allowlist blocks `nai-v4.5`, or account NAI access is restricted.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "409": {
            "description": "`Idempotency-Key` reused with different parameters, active single-flight trial busy, or quote/allowance changed concurrently.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "413": {
            "description": "JSON request body exceeds 40 MiB.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "429": {
            "description": "Rate limit or generation concurrency limit reached.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/NativeError" },
                    { "$ref": "#/components/schemas/GatewayMiddlewareError" }
                  ]
                }
              }
            }
          },
          "502": {
            "description": "Upstream generation failure (precharge automatically refunded when `X-Retry-Same-Key: false`; if `X-Retry-Same-Key: true`, generated image read transiently failed and can be fetched with the same key).",
            "headers": {
              "X-Retry-Same-Key": { "schema": { "type": "string", "enum": ["true", "false"] } },
              "X-Failure-Code": { "schema": { "type": "string" } }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "503": {
            "description": "Image generation service temporarily paused for maintenance.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          },
          "504": {
            "description": "Check response header `X-Retry-Same-Key`: if `true`, the generation is still running past the HTTP wait window — retry with the SAME `Idempotency-Key` and body without double-charging. If `false` (`X-Failure-Code: generation_timeout`), the task terminally timed out and was refunded — use a NEW `Idempotency-Key` to start a new generation.",
            "headers": {
              "X-Retry-Same-Key": { "schema": { "type": "string", "enum": ["true", "false"] } },
              "X-Failure-Code": { "schema": { "type": "string" } }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NativeError" }
              }
            }
          }
        }
      }
    }
  }
}
