1. POST /ai/generate-image parameter dictionary

Place input, model, and action at the root object; all generation controls belong inside parameters. Unknown JSON keys or null values (except skip_cfg_above_sigma: null) return HTTP 400 before billing. Machine-readable spec: openapi-nai.json.

Field PathType & Allowed Values
inputstring (required non-empty, ≤ 20,000 UTF-8 bytes): Positive prompt passed verbatim.
modelstring (required): Exact model ID; append -inpainting when action is "infill".
action"generate" | "img2img" | "infill"
parameters.width / heightint (required, multiple of 64): 64–3072 per side, total pixels ≤ 3,145,728 (standard free/Opus tier ≤ 1,048,576, e.g. 832×1216, 1024×1024).
parameters.stepsint (default 28, range 1–50): Sampling steps (0 or omitted defaults to 28), typically 23 or 28.
parameters.n_samplesint (default 1, range 1–4): Batch count (0 or omitted defaults to 1).
parameters.scalenumber (default 5, range 0–10): Prompt guidance (CFG scale).
parameters.samplerEnum: k_euler_ancestral | k_euler | k_dpmpp_2s_ancestral | k_dpmpp_2m_sde | k_dpmpp_2m | k_dpmpp_sde
parameters.noise_scheduleEnum: karras | exponential | polyexponential (ignored on V5).
parameters.seedint (optional, 0–4294967295): Omit key for random seed; 0 is a valid fixed seed. Never pass null or -1.
parameters.negative_promptstring (or alias uc, ≤ 20,000 UTF-8 bytes): Pass "" when empty, never null.
parameters.cfg_rescalenumber (default 0, range 0–1).
parameters.skip_cfg_above_sigmanumber | null (0–1000): Variety+ / CFG delay threshold.
parameters.tag_hint_transparent_backgroundboolean (optional): Native transparent background hint on NAI V5.

2. Where each image goes (raw Base64)

GoalactionFields inside parameters
Redraw a source imageimg2imgimage + strength + noise
Redraw a masked regioninfill (with -inpainting model)image + mask + strength (optional mask_blur, inpaintImg2ImgStrength)
Character / style / outfit referencegenerateFive matching director_reference_* arrays (up to 8 on V5, up to 4 on V4.5)

image, mask, and director_reference_images[] require raw Base64 file bytes (no data:image/png;base64, prefix and no URLs). PNG / JPEG / WebP up to 24 MiB per image and 40 MiB max JSON body; source image & matching mask ≤ 16,777,216 pixels (16 MP), director_reference_images[] ≤ 24,000,000 pixels (24 MP).

3. Image-to-image (action: "img2img")

Set top-level action to "img2img" and include these fields inside parameters (0 < strength <= 1):

json
{
  "image": "BASE64_OF_SOURCE_PNG",
  "strength": 0.65,
  "noise": 0
}

Download full img2img Python script

4. Masked inpainting (action: "infill")

Set action: "infill" and append -inpainting to model (e.g. nai-diffusion-5-full-inpainting). Supply a black-and-white PNG mask (white = regenerate, black = keep). If inpaintImg2ImgStrength is sent, it must equal strength.

json
{
  "image": "BASE64_OF_SOURCE_PNG",
  "mask": "BASE64_OF_MASK_PNG",
  "strength": 0.65,
  "noise": 0,
  "inpaintImg2ImgStrength": 0.65
}

Download full inpainting Python script

5. Precise Reference (supported on both NAI V5 & V4.5)

Keep action: "generate" and pass all five equal-length arrays inside parameters. Note the exact V5 vs V4.5 differences:

Parallel Array FieldNAI V5 (Full / Curated, max 8)NAI V4.5 (Full / Curated, max 4)
director_reference_imagesRaw Base64 image per itemRaw Base64 image per item
director_reference_descriptions[].caption.base_captioncharacter | style | character&style | costume | character_mainoutfit | character&style_anyoutfit (char_captions: [])character | style | character&style (char_captions: [])
director_reference_strength_values0 – 5 (typically 1)0 – 1 (typically 1)
director_reference_secondary_strength_valuesMUST be 0 (non-zero returns 400)0 – 1 (1 − fidelity, e.g. 0.3 for fidelity 0.7)
director_reference_information_extractedMUST be 1MUST be 1

NAI V5 character + costume reference parameters snippet:

json
{
  "director_reference_images": [
    "BASE64_OF_CHAR_PNG",
    "BASE64_OF_OUTFIT_PNG"
  ],
  "director_reference_descriptions": [
    {
      "caption": {
        "base_caption": "character",
        "char_captions": []
      }
    },
    {
      "caption": {
        "base_caption": "costume",
        "char_captions": []
      }
    }
  ],
  "director_reference_strength_values": [
    1,
    1
  ],
  "director_reference_secondary_strength_values": [
    0,
    0
  ],
  "director_reference_information_extracted": [
    1,
    1
  ]
}

NAI V4.5 single reference parameters snippet:

json
{
  "director_reference_images": [
    "BASE64_OF_REFERENCE_PNG"
  ],
  "director_reference_descriptions": [
    {
      "caption": {
        "base_caption": "character",
        "char_captions": []
      }
    }
  ],
  "director_reference_strength_values": [
    1
  ],
  "director_reference_secondary_strength_values": [
    0.3
  ],
  "director_reference_information_extracted": [
    1
  ]
}

Download V5 Precise Reference Python script · Download V4.5 Precise Reference Python script

6. Separate character prompts (v4_prompt & v4_negative_prompt)

Pass multi-character prompts via parameters.v4_prompt and parameters.v4_negative_prompt (up to 6 on V4/V4.5, up to 32 on V5). Keep characters in matching order across both char_captions arrays. Set use_coords: false for automatic placement or true to apply normalized 0.0 – 1.0 centers.

json
{
  "input": "2girls, watercolor, sunlit cafe terrace, masterpiece",
  "model": "nai-diffusion-5-full",
  "action": "generate",
  "parameters": {
    "width": 1216,
    "height": 832,
    "steps": 23,
    "n_samples": 1,
    "scale": 5,
    "seed": 42,
    "sampler": "k_euler_ancestral",
    "negative_prompt": "lowres, blurry",
    "v4_prompt": {
      "caption": {
        "base_caption": "2girls, watercolor, sunlit cafe terrace, masterpiece",
        "char_captions": [
          {
            "char_caption": "girl, silver hair, blue dress, holding teacup, smile",
            "centers": [
              {
                "x": 0.3,
                "y": 0.5
              }
            ]
          },
          {
            "char_caption": "girl, short black hair, white shirt, reading book",
            "centers": [
              {
                "x": 0.7,
                "y": 0.5
              }
            ]
          }
        ]
      },
      "use_coords": true,
      "use_order": true
    },
    "v4_negative_prompt": {
      "caption": {
        "base_caption": "lowres, blurry",
        "char_captions": [
          {
            "char_caption": "extra fingers",
            "centers": [
              {
                "x": 0.3,
                "y": 0.5
              }
            ]
          },
          {
            "char_caption": "glasses",
            "centers": [
              {
                "x": 0.7,
                "y": 0.5
              }
            ]
          }
        ]
      },
      "use_coords": true,
      "use_order": true
    }
  }
}

Download complete two-character Python script

7. Appendix: /v1/nai/* extension fields (do NOT mix into /ai/generate-image)

The fields below apply ONLY to /v1/nai/estimate and /v1/nai/generations (where images are uploaded first via POST /v1/nai/assets):

Use/v1/nai/* Top-Level Fields
Modelmodel: "nai-v4.5" + model_variant: "nai-diffusion-5-full"
Prompt / CFG / Countprompt / guidance / count
Source & Masksource_image_asset_id / inpaint_mask_asset_id / source_strength / source_noise
Precise Reference (V5 max 8 / V4.5 max 4)references: [{ asset_id, role: "precise", description: "character", strength, fidelity, information_extracted: 1 }]
Vibe Transfer (V4/V4.5/V3)references: [{ asset_id, role: "style", strength: 0.6, information_extracted: 0.7 }]
Characterscharacters: [{ prompt, negative_prompt, x, y }] + auto_character_positions

Complete upload → quote → generate → SSE flow

8. Common errors & fixes

Error / StatusFix
401 UnauthorizedCheck Authorization: Bearer sk-... with a valid NoveaDream key (auth middleware returns {"error": ...}).
402 Payment RequiredInsufficient wallet balance or NAI points.
403 ForbiddenEnsure the key's model allowlist permits nai-v4.5 and check account access.
unsupported or invalid parameters.<key>Remove unknown keys, null values (such as seed: null), or active autoSmea: true.
director_reference_secondary_strength_values (V5 requires 0)Set every entry in director_reference_secondary_strength_values to 0 when using NAI V5.
director_reference_information_extracted (each entry must be 1)Set every entry in director_reference_information_extracted to 1.
action does not match image/mask parametersgenerate takes no image/mask; img2img requires image; infill requires image + mask and a -inpainting model.
409 Conflict / 504 Gateway Timeout409 = Idempotency-Key mismatch or concurrency conflict. On 504, check X-Retry-Same-Key (true = retry with SAME key; false = terminal timeout & refunded, use a NEW UUID).