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

# 生成图片

> 请求格式、响应与能力边界。

`POST /v1/images/generations`

发送 JSON，必需 `model` 和 `prompt`。从一张图片开始；尺寸、质量及返回格式必须与所选模型匹配。

成功时读取 `data[].url` 或 `data[].b64_json`。本参考描述同步响应；支持图片流的直连渠道需使用对应事件协议，任务插件不提供统一流式模式。等待超时后先检查日志，避免重复生成。

[完整接入指南与可执行示例](/zh/guides/image-generation)

[Read in English](/en/api-reference/images-generations)


## OpenAPI

````yaml openapi/relay.json POST /v1/images/generations
openapi: 3.0.3
info:
  title: API — Core inference API
  version: 0.5.0
  description: >-
    面向接入的精选规范，不是全部管理或供应商接口。 / Curated integration specification, not the entire
    management or provider API.
  license:
    name: AGPL-3.0-or-later
servers:
  - url: https://gateway.example.com
    description: >-
      Example only; replace with your gateway origin and optional path prefix,
      without /v1.
security:
  - BearerAuth: []
paths:
  /v1/images/generations:
    post:
      summary: 生成图片 / Generate images
      description: >-
        常用接入字段；能力取决于模型、渠道与部署。 / Common integration fields; support depends on
        the model, channel, and deployment.
      operationId: POSTImagesGenerations
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerateRequest'
      responses:
        '200':
          description: 图片结果 / Image result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResult'
              example:
                created: 1700000000
                data:
                  - url: https://cdn.example.com/image.png
        '400':
          description: 请求参数错误 / Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: 身份校验失败 / Authentication failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: 访问被拒绝 / Access denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: 接口或资源不存在 / Endpoint or resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: 请求被限流或受配额限制 / Rate or quota restriction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: 网关或上游错误 / Gateway or upstream error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: 服务暂不可用 / Service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '504':
          description: 等待任务超时；工作仍可能继续 / Timed out waiting; work may continue
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        default:
          description: 其他网关或上游错误；格式可能不同 / Other gateway or upstream error; shape may vary
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ImageGenerateRequest:
      type: object
      properties:
        model:
          type: string
          description: >-
            当前密钥可用且支持此接口的模型 ID / Model ID available to the key and supporting
            this endpoint
          example: YOUR_MODEL_ID
        prompt:
          type: string
          description: >-
            任务描述；遵循模型的长度和内容要求 / Task description; follow model length and
            content requirements
        'n':
          type: integer
          description: >-
            请求图片数，模型通常有更小限制；建议从 1 开始 / Requested image count; models usually
            impose a smaller limit; start with 1
          minimum: 1
          maximum: 128
        size:
          type: string
          description: 模型支持的尺寸，使用 x 而不是 × / Model-supported size; use x rather than ×
        quality:
          type: string
          description: 质量档位，由模型决定 / Quality setting determined by the model
        response_format:
          type: string
          description: >-
            url 或 b64_json，仅在模型支持时指定；有些模型固定返回 Base64 / url or b64_json when
            supported; some models always return Base64
        output_format:
          type: string
          description: >-
            输出编码，例如 png、jpeg、webp；需模型支持 / Output encoding such as png, jpeg,
            webp; requires model support
        background:
          type: string
          description: >-
            背景选项；透明背景需模型和编码支持 / Background option; transparency requires model
            and format support
      required:
        - model
        - prompt
    ImageResult:
      type: object
      properties:
        created:
          type: integer
          description: Unix 秒 / Unix seconds
        data:
          type: array
          description: >-
            检查每项的 url 或 b64_json，不能仅凭 HTTP 200 判断有图片 / Check url or b64_json in
            each item; HTTP 200 alone does not guarantee an image
          items:
            type: object
            properties:
              url:
                type: string
                description: >-
                  可能短期有效；不要向此 URL 发送网关密钥 / May expire; never send the gateway
                  key to this URL
              b64_json:
                type: string
                description: 图片字节的 Base64，不是 data URL / Base64 image bytes, not a data URL
              revised_prompt:
                type: string
                description: 可选改写提示词 / Optional revised prompt
      required:
        - data
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
              nullable: true
            code:
              nullable: true
              description: 错误标识；类型随上游变化 / Error identifier; type varies by upstream
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 模型调用 API Key，不是控制台登录凭据 / Model API key, not console login credentials

````

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