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

# 同步生成 GPT Image 图片

> 查看并测试 OpenAI Images 形式的 Generate 接口，包括模型、提示词、尺寸、quality、Base64 PNG 和错误响应。

调用方可以保持连接直到图片完成时使用该接口。`model` 选择 Web 或 VIP；两个逆向接口都会转发 quality，实际效果取决于所选上游。

<Warning>在线测试会产生真实费用。发送前确认模型、尺寸和 quality，并且不要分享包含密钥的 cURL。</Warning>

需要快速获得 `task_id` 时，改用[统一异步图片任务](/cn/api-reference/image-tasks)，并设置 `action=generate`。


## OpenAPI

````yaml openapi-locales/zh-CN/openapi.json POST /v1/images/generations
openapi: 3.1.0
info:
  title: YingTu 图片 API
  version: 1.0.0
  description: 提供 Gemini 原生 Nano Banana 与 OpenAI Images 形状的 GPT Image 生图、编辑和任务接口。
servers:
  - url: https://api.yingtu.ai
    description: YingTu API
security: []
tags:
  - name: Synchronous generation
    description: 在同一个 HTTP 请求中等待完整 Gemini 响应。
  - name: Asynchronous tasks
    description: 提交图片任务，再查询到任务进入终态。
  - name: GPT Image generation
    description: 同步生成 GPT Image 图片，或提交 YingTu 任务式生图请求。
  - name: GPT Image editing
    description: 使用 GPT Image 同步编辑一张来源图片。
paths:
  /v1/images/generations:
    post:
      tags:
        - GPT Image generation
      summary: 同步生成 GPT Image 图片（真实计费）
      description: >-
        这会发送真实计费请求，并等待一张 Base64 PNG。请先在 https://api.yingtu.ai/pricing
        查看当前固定价格。两个逆向图片接口都接受 low、medium、high 或 auto，实际效果由所选上游决定。
      operationId: generateGptImageSynchronously
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenAIImageGenerationRequest'
            examples:
              web:
                summary: 使用 the Web route 生成图片
                value:
                  model: gpt-image-2-web
                  prompt: 浅色桌面上的蓝色陶瓷茶壶，不要文字
                  size: 1024x1024
                  'n': 1
              vip:
                summary: 使用 VIP quality 生成图片
                value:
                  model: gpt-image-2-vip
                  prompt: 深色石材上的银色腕表，不要文字
                  size: 1024x1024
                  quality: medium
                  'n': 1
      responses:
        '200':
          description: 完整 GPT Image 响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIImagesResponse'
              example:
                created: 1788307200
                data:
                  - b64_json: iVBORw0KGgo=
                usage:
                  input_tokens: 24
                  output_tokens: 1756
                  total_tokens: 1780
                  input_tokens_details:
                    text_tokens: 24
                    image_tokens: 0
                  output_tokens_details:
                    text_tokens: 0
                    image_tokens: 1756
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/ServerError'
      security:
        - BearerAuth: []
components:
  schemas:
    OpenAIImageGenerationRequest:
      title: GPT Image 生图请求
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          $ref: '#/components/schemas/OpenAIImageModelId'
        prompt:
          title: 提示词
          type: string
          minLength: 1
          example: 浅色桌面上的蓝色陶瓷茶壶，不要文字
        size:
          $ref: '#/components/schemas/OpenAIImageSize'
        quality:
          $ref: '#/components/schemas/OpenAIImageQuality'
        'n':
          title: 图片数量
          type: integer
          enum:
            - 1
          default: 1
          description: 当前文档子集返回一张图片。
    OpenAIImagesResponse:
      title: GPT Image 响应
      type: object
      required:
        - created
        - data
      properties:
        created:
          type: integer
          format: int64
          description: Unix 秒级时间戳。
        data:
          type: array
          minItems: 1
          maxItems: 1
          items:
            $ref: '#/components/schemas/OpenAIImageData'
        size:
          type: string
          description: Output size when returned by the selected GPT Image route.
        quality:
          type: string
          description: Quality value reported by the selected GPT Image route.
        usage:
          $ref: '#/components/schemas/OpenAIImageUsage'
    OpenAIImageModelId:
      title: GPT Image 模型 ID
      type: string
      enum:
        - gpt-image-2-web
        - gpt-image-2-vip
      example: gpt-image-2-web
    OpenAIImageSize:
      title: 输出尺寸
      type: string
      enum:
        - 1024x1024
        - 2048x2048
        - 3840x2160
      example: 1024x1024
      description: 当前公开支持三档尺寸。请明确传入 size 以获得可预测的像素尺寸；4K 横图使用 3840x2160。
    OpenAIImageQuality:
      title: 图片质量
      type: string
      enum:
        - low
        - medium
        - high
        - auto
      example: low
      description: 两个 GPT Image 接口都会转发该值；实际效果由所选上游决定。
    OpenAIImageData:
      type: object
      required:
        - b64_json
      properties:
        b64_json:
          type: string
          format: byte
          description: 不带 data URL 前缀的 Base64 图片字节。
          example: iVBORw0KGgo=
    OpenAIImageUsage:
      type: object
      properties:
        input_tokens:
          type: integer
          minimum: 0
        output_tokens:
          type: integer
          minimum: 0
        total_tokens:
          type: integer
          minimum: 0
        input_tokens_details:
          $ref: '#/components/schemas/OpenAIImageTokenDetails'
        output_tokens_details:
          $ref: '#/components/schemas/OpenAIImageTokenDetails'
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorObject'
    OpenAIImageTokenDetails:
      type: object
      properties:
        text_tokens:
          type: integer
          minimum: 0
        image_tokens:
          type: integer
          minimum: 0
    ErrorObject:
      type: object
      required:
        - message
        - type
      properties:
        message:
          type: string
        type:
          type: string
          example: invalid_request_error
        param:
          type:
            - string
            - 'null'
        code:
          type:
            - string
            - 'null'
          example: insufficient_user_quota
  responses:
    BadRequest:
      description: 模型、字段或参数值无效
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: YingTu API Key 缺失或无效
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: 密钥有效，但当前账号缺少余额或请求权限
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: Insufficient balance for this request
              type: new_api_error
              param: ''
              code: insufficient_user_quota
    RateLimited:
      description: >-
        当前所选上游返回了速率、配额、消费或模型容量限制。对于文档中的 Nano Banana 接口，该限制来自官方上游，网关不设置固定的平台侧 RPM
        上限。目前没有单独公布 GPT Image 的网关 RPM 或可用率目标。
      headers:
        Retry-After:
          description: 响应提供时，表示重试前应等待的秒数。
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ServerError:
      description: 请求未能完成
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: YingTu API Key。

````