> ## Documentation Index
> Fetch the complete documentation index at: https://docs.viggle.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成图片

> 根据 `prompt` 异步生成 `n` 张 PNG 图片（1–6 张），可选用最多 8 张参考图引导。`aspect_ratio` 和 `resolution` 决定输出尺寸（见 `CreateImageForm`）。返回 `200` 和排队中的 `Image`；轮询 `GET /v1/images/{image_id}`，直到其变为 `ready` 或 `failed`。

每张图片在 `1K` 下消耗 1 积分，在 `2K` 下消耗 2 积分。整个任务的费用（`n` × 单张价格）在创建时预扣，余额不足时返回 `402`；任务失败则全额退款。返回 `400` 时不会创建任务，也不会上传任何文件。`429 RATE_LIMITED` 表示积分预扣闸门繁忙；请退避重试。




## OpenAPI

````yaml zh/openapi.yaml POST /v1/images
openapi: 3.0.3
info:
  title: Viggle API
  description: >
    Viggle API 可生成 AI 视频（Viggle H3、Viggle Remake、Video Remix）、图片（Viggle Image）、2
    倍视频超分（FlashVSR），以及 JST-2 3D 角色、动作和场景。所有任务都是异步的：先创建，再轮询（渲染任务也可监听进度），直到任务进入终态。


    基础 URL：`https://apis.viggle.ai`。每个请求都需通过 `Authorization: Bearer <API key>`
    认证。用量按积分计费（1 积分 = $0.01）。指南与价格：https://docs.viggle.ai/zh/v1/introduction
  version: 2.0.0
  contact:
    name: Viggle Support
    url: https://viggle.ai
servers:
  - url: https://apis.viggle.ai
    description: 生产环境服务器
security:
  - bearerAuth: []
tags:
  - name: Renders
    description: >-
      Video Remix（JST-1）。准备输入、创建渲染任务、监听进度、取消以及下载结果。渲染任务的状态通过 `GET
      /v1/videos/{video_id}` 读取。
  - name: Credits
    description: 读取调用方 API 密钥可用的积分余额。
  - name: Characters
    description: |
      创建、列出、查看和删除可复用的角色资产。`type` 决定创建时是否同时提取 3D vsplat；就绪后需单独导出其下载链接。
  - name: Motions
    description: |
      创建、列出、查看和删除可复用的动作资产，也可从官方动作模板导入。`type` 决定创建时是否同时提取或生成 3D 动画；就绪后需单独导出其下载链接。
  - name: Videos
    description: >
      从文本、帧或参考素材生成 Viggle H3 视频（`vid_` 前缀），或从驱动视频和角色图生成 Viggle Remake 视频（`anim_`
      前缀）；用 FlashVSR 将视频超分 2 倍（`vsr_` 前缀）；并以统一视图读取调用方 API 密钥创建的所有视频——H3
      生成、Remake 生成以及 Video Remix 渲染任务（`render_` 前缀）——合并为同一种资源。
  - name: Images
    description: |
      Viggle Image——根据文本提示词生成 1–6 张 PNG 图片，可选用最多 8 张参考图引导（`img_` 前缀），并可按 ID 获取。
  - name: Scenes
    description: >
      场景模型——从文本提示词或 360° 全景图构建 3D
      高斯泼溅场景（`.spz`），生成新的指定位姿视角，并基于这些视角重建场景。每个操作都是一个异步任务（`scn_` 前缀），按 ID
      读取结果。每次运行按每个视角 1 积分计费，一张全景图计为 6 个视角。除非任务以 `ready` 结束，否则积分全额退款。
paths:
  /v1/images:
    post:
      tags:
        - Images
      summary: 生成图片
      description: >
        根据 `prompt` 异步生成 `n` 张 PNG 图片（1–6 张），可选用最多 8 张参考图引导。`aspect_ratio` 和
        `resolution` 决定输出尺寸（见 `CreateImageForm`）。返回 `200` 和排队中的 `Image`；轮询 `GET
        /v1/images/{image_id}`，直到其变为 `ready` 或 `failed`。


        每张图片在 `1K` 下消耗 1 积分，在 `2K` 下消耗 2 积分。整个任务的费用（`n` × 单张价格）在创建时预扣，余额不足时返回
        `402`；任务失败则全额退款。返回 `400` 时不会创建任务，也不会上传任何文件。`429 RATE_LIMITED`
        表示积分预扣闸门繁忙；请退避重试。
      operationId: createImage
      parameters:
        - $ref: '#/components/parameters/RequestId'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/CreateImageForm'
      responses:
        '200':
          description: 图片生成已受理并进入排队。
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Image'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/V1Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '408':
          $ref: '#/components/responses/UploadTimeout'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  parameters:
    RequestId:
      name: X-Request-Id
      in: header
      required: false
      description: 可选，调用方提供的关联 ID，会原样回显在响应头中。不传则由服务生成。用于链路追踪和技术支持。
      schema:
        type: string
        minLength: 1
  schemas:
    CreateImageForm:
      description: >
        `POST /v1/images` 的请求体，仅支持
        `multipart/form-data`。未提供参考图时为文生图，提供至少一张时为参考图引导生成。`aspect_ratio` 和
        `resolution` 共同选择模型的一个固定输出尺寸（宽 × 高，单位像素）；使用参考图时，`2K` 的尺寸比不使用时小：


        | aspect_ratio | 1K | 2K | 2K（使用参考图） |

        | --- | --- | --- | --- |

        | 1:1 | 1024×1024 | 2048×2048 | 1536×1536 |

        | 16:9 | 1376×768 | 2720×1536 | 2048×1152 |

        | 9:16 | 768×1376 | 1536×2720 | 1152×2048 |

        | 4:3 | 1184×896 | 2368×1760 | 1760×1344 |

        | 3:4 | 896×1184 | 1760×2368 | 1344×1760 |

        | 3:2 | 1248×832 | 2496×1664 | 1888×1248 |

        | 2:3 | 832×1248 | 1664×2496 | 1248×1888 |


        参考图合计最多 8 张，可任意组合 `reference_image` 上传和 `reference_image_url`
        URL。模型先接收上传的图片，再接收 URL，各自按发送顺序排列。
      type: object
      required:
        - prompt
      properties:
        prompt:
          type: string
          minLength: 1
          maxLength: 4000
          description: 图片的文本描述。最多 4000 个字符，按 Unicode 码点计数（一个中日韩字符计为一个）。不能为空白。
        model:
          type: string
          enum:
            - viggle-image
          default: viggle-image
          description: 图片模型。省略或传 `viggle-image`。
        aspect_ratio:
          type: string
          enum:
            - '1:1'
            - '16:9'
            - '9:16'
            - '4:3'
            - '3:4'
            - '3:2'
            - '2:3'
          default: '1:1'
          description: 输出宽高比。与 `resolution` 共同决定确切的输出尺寸。
        resolution:
          type: string
          enum:
            - 1K
            - 2K
          default: 1K
          description: >-
            输出尺寸档位，不区分大小写，同时决定每张图片的价格——`1K` 为 1 积分，`2K` 为 2 积分。使用任意参考图时，`2K` 约为
            1536² 像素，而非约 2048²。
        'n':
          type: integer
          minimum: 1
          maximum: 6
          default: 1
          description: 生成图片的数量。任务会预扣 `n` × 单张价格。
        seed:
          type: integer
          format: int64
          minimum: 0
          maximum: 2147483647
          description: >
            第 `i` 张图片（从 0 开始计数）使用种子 `(seed + i) mod 2147483648`
            生成。省略时服务器随机选择种子；每张图片会返回其实际使用的种子。
        reference_image:
          type: array
          maxItems: 8
          items:
            type: string
            format: binary
          description: >-
            参考图上传；多张时重复该字段。每张最大 24 MiB，长短边之比不超过 8；支持 JPEG、PNG、WebP、GIF、BMP、TIFF
            或 HEIC。与 `reference_image_url` 共享 8 张的总数上限。
        reference_image_url:
          type: array
          maxItems: 8
          items:
            type: string
            format: uri
          description: >-
            公网可访问的 http(s) 参考图 URL，在处理创建请求时下载；多张时重复该字段。限制与 `reference_image`
            相同，并计入同一个 8 张总数上限。
    Image:
      description: >
        图片生成任务（`img_` 前缀），由 `POST /v1/images` 和 `GET /v1/images/{image_id}`
        返回。状态只会向前推进——`queued` → `processing` → `ready` 或 `failed`——且不会变为
        `cancelled`。任务变为 `ready` 前 `images` 始终为空，之后按请求顺序列出所有生成的图片。任务要么生成全部 `n`
        张图片，要么失败；不会返回部分结果。
      type: object
      additionalProperties: false
      required:
        - id
        - status
        - model
        - progress
        - images
        - created_at
        - completed_at
        - error
      properties:
        id:
          type: string
          minLength: 1
          description: 公开的图片任务 ID，`img_` 前缀。
        status:
          type: string
          enum:
            - queued
            - processing
            - ready
            - failed
          description: 生命周期状态。`ready` 和 `failed` 为终态。
        model:
          type: string
          description: 运行该任务的模型，`viggle-image`。
        progress:
          type: integer
          nullable: true
          minimum: 0
          maximum: 100
          description: 已生成图片占请求数量的比例——排队时为 `0`，处理中为 0–99，就绪时为 `100`，失败时为 null。
        images:
          type: array
          description: '`ready` 前为空，之后按请求顺序包含全部 `n` 张生成的图片。'
          items:
            $ref: '#/components/schemas/GeneratedImage'
        created_at:
          type: string
          format: date-time
          nullable: true
          description: 创建时间戳，RFC 3339 格式。
        completed_at:
          type: string
          format: date-time
          nullable: true
          description: 进入终态的时间戳；任务变为 `ready` 或 `failed` 后设置，此前为 null。
        error:
          type: object
          nullable: true
          description: >
            失败详情，仅在 `status` 为 `failed` 时提供；否则为 null。`code` 为
            `SERVICE_BUSY`（可重试——生成服务繁忙或不可用，或任务未在 15
            分钟内完成）、`TASK_FAILED`（可重试——其他生成或上传失败）或
            `INVALID_REQUEST`（不可重试——模型拒绝了请求，例如参考图不可用）。
          allOf:
            - $ref: '#/components/schemas/ErrorBody'
    GeneratedImage:
      type: object
      additionalProperties: false
      required:
        - url
        - width
        - height
        - seed
      properties:
        url:
          type: string
          format: uri
          nullable: true
          description: PNG 的签名下载链接，有效期 1 小时；重新获取任务可得到新链接。文件在任务结束 24 小时后被删除，届时为 null。
        width:
          type: integer
          minimum: 1
          description: 实际宽度（像素）。
        height:
          type: integer
          minimum: 1
          description: 实际高度（像素）。
        seed:
          type: integer
          format: int64
          minimum: 0
          description: 该图片实际使用的种子。
    ErrorBody:
      type: object
      additionalProperties: false
      required:
        - code
        - message
        - retryable
        - request_id
        - details
        - remediation
      properties:
        code:
          description: 稳定的机器可读错误代码。请据此进行程序化处理，而不要解析 `message`。
          allOf:
            - $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
          description: 人类可读的说明，适合写入日志或展示给开发者。
        retryable:
          type: boolean
          description: 不修改输入直接重试该操作是否可能成功。HTTP 408、429 和 5xx 响应为 true。
        request_id:
          type: string
          description: 用于追踪和技术支持的关联标识符。报告失败时请附上。
        details:
          type: object
          description: 特定于该错误的结构化上下文；可用的键取决于 `code`。
          additionalProperties: true
        remediation:
          description: 建议的恢复操作及可选的重试延迟。
          allOf:
            - $ref: '#/components/schemas/ErrorRemediation'
    ErrorResponse:
      type: object
      additionalProperties: false
      required:
        - error
      properties:
        error:
          description: 错误负载，包含稳定的错误代码、消息、重试建议、关联 ID 以及特定于该错误的详情。
          allOf:
            - $ref: '#/components/schemas/ErrorBody'
    ErrorCode:
      description: >
        API 返回的错误代码，出现在同步错误信封以及失败任务的 `error` 对象中。客户端应能容忍此处未列出的代码。没有公开映射的异步失败会以
        `PROCESSING_FAILED` 呈现。
      type: string
      enum:
        - INVALID_REQUEST
        - UNAUTHENTICATED
        - INVALID_CREDENTIAL
        - INSUFFICIENT_CREDITS
        - RENDER_NOT_FOUND
        - CHARACTER_NOT_FOUND
        - MOTION_NOT_FOUND
        - DRAFT_NOT_FOUND
        - NOT_FOUND
        - RESULT_EXPIRED
        - IDEMPOTENCY_KEY_REUSED
        - ID_ALREADY_EXISTS
        - UPLOAD_TIMEOUT
        - CONTENT_POLICY_VIOLATION
        - RATE_LIMITED
        - SERVICE_BUSY
        - INTERNAL_ERROR
        - IMAGE_REQUIRED
        - MOTION_VIDEO_REQUIRED
        - UNSUPPORTED_MEDIA
        - VIDEO_TOO_LONG
        - VIDEO_TOO_LARGE
        - VIDEO_RESOLUTION_TOO_HIGH
        - VIDEO_UNREADABLE
        - VIDEO_DIMENSIONS_MUST_BE_EVEN
        - VIDEO_INACCESSIBLE
        - NO_HUMANS_DETECTED
        - MOTION_NOT_READY
        - MOTION_MODEL_MISMATCH
        - INVALID_BACKGROUND_MODE
        - ALL_WORKERS_BUSY
        - WORKER_STOPPED
        - TASK_FAILED
        - PROCESSING_FAILED
    ErrorRemediation:
      type: object
      additionalProperties: false
      required:
        - action
        - retry_after_ms
      properties:
        action:
          type: string
          enum:
            - none
            - retry
          description: 建议的下一步操作。同步错误始终为 `none`；失败任务的 `error` 在失败可重试时为 `retry`。
        retry_after_ms:
          type: integer
          description: 重试前建议等待的毫秒数；不建议定时重试时为 null。
          nullable: true
          format: int64
          minimum: 0
  headers:
    RequestId:
      description: 用于技术支持和链路追踪的稳定请求标识。
      schema:
        type: string
  responses:
    BadRequest:
      description: 请求无效。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    V1Unauthorized:
      description: 缺少 API 密钥或 API 密钥无效。错误码 `UNAUTHENTICATED`。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    PaymentRequired:
      description: 积分不足。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UploadTimeout:
      description: >-
        multipart 上传未能在 10 分钟的读取截止时间内传完。错误码 `UPLOAD_TIMEOUT`，可重试：直接重试，或改传 URL
        代替文件。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: >
        积分预扣闸门繁忙（错误码 `RATE_LIMITED`，可重试）。不存在按账户的限流；仅在 Viggle
        Remake、图片和场景创建时出现。请退避重试。
      headers:
        Retry-After:
          schema:
            type: integer
            minimum: 0
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: 服务器意外错误。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ServiceUnavailable:
      description: 服务暂时不可用。
      headers:
        Retry-After:
          schema:
            type: integer
            minimum: 0
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: >
        以 `Authorization: Bearer <API key>` 的形式发送 API 密钥。密钥以 `sk-`
        开头。缺少密钥或密钥无效时返回 `401 UNAUTHENTICATED`。切勿在浏览器代码中暴露 API 密钥。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.