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

# 创建图片生成并等待结果

> 创建图片任务，并在配置的最大等待时间内等待任务完成。



## OpenAPI

````yaml /zh/openapi.json post /v1/images/generations/sync
openapi: 3.1.0
info:
  title: APIAny.AI 公开 API
  version: 1.0.0
  description: APIAny.AI 模型聚合、异步媒体任务、对话生成、积分查询和任务查询的公开 API。
servers:
  - url: https://apiany.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Models
    description: 公开模型目录。
  - name: Chat
    description: 文本生成和对话兼容接口。
  - name: Images
    description: 图片生成和图片编辑接口。
  - name: Videos
    description: 视频生成接口。
  - name: Moderation
    description: Image safety and moderation endpoints.
  - name: Tasks
    description: 异步任务查询。
  - name: Account
    description: 账户与积分查询。
  - name: Free APIs
    description: Free utility APIs protected by API key rate limits.
paths:
  /v1/images/generations/sync:
    post:
      tags:
        - Images
      summary: 创建图片生成并等待结果
      description: 创建图片任务，并在配置的最大等待时间内等待任务完成。
      operationId: createImageGenerationSync
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
      responses:
        '200':
          description: OpenAI 兼容图片生成结果。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIImageResponse'
        '202':
          description: 达到最大等待时间后任务仍在处理中。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AsyncTaskCreateResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  schemas:
    ImageGenerationRequest:
      oneOf:
        - $ref: '#/components/schemas/GPTImage2GenerationRequest'
        - $ref: '#/components/schemas/GenericImageGenerationRequest'
    OpenAIImageResponse:
      type: object
      properties:
        created:
          type: integer
        data:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
                format: uri
              b64_json:
                type: string
              revised_prompt:
                type: string
        usage:
          $ref: '#/components/schemas/TokenUsage'
      required:
        - created
        - data
    AsyncTaskCreateResponse:
      type: object
      properties:
        task_id:
          type: string
          example: task_123
        status:
          type: string
          enum:
            - pending
            - processing
        model:
          type: string
        poll_url:
          type: string
          example: /v1/tasks/task_123
      required:
        - task_id
        - status
        - poll_url
    GPTImage2GenerationRequest:
      type: object
      properties:
        model:
          type: string
          const: gpt-image-2
        prompt:
          type: string
        size:
          type: string
          description: >-
            Accepts auto, a positive WIDTHxHEIGHT target, or ratio shorthand
            such as 16:9. Every non-auto target is mapped to the nearest
            official popular size: 1024x1024, 1536x1024, 1024x1536, 2048x2048,
            2048x1152, 3840x2160, or 2160x3840.
          examples:
            - auto
            - 1024x1024
            - 1280x720
            - '16:9'
        quality:
          type: string
          description: GPT-Image 2 rendering quality.
          enum:
            - auto
            - low
            - medium
            - high
          default: auto
        'n':
          type: integer
          minimum: 1
          maximum: 10
          description: Number of images to generate. Billing scales with the image count.
          default: 1
        aspect_ratio:
          type: string
          description: >-
            Deprecated ratio shorthand. The ratio and compatibility tier are
            mapped to the nearest official popular size.
          deprecated: true
        resolution:
          type: string
          description: >-
            Deprecated compatibility tier used to form the target size before
            nearest-official-size mapping.
          enum:
            - 1K
            - 2K
            - 4K
          deprecated: true
        input_images:
          type: array
          items:
            type: string
            format: uri
        callback_url:
          type: string
          format: uri
      required:
        - model
        - prompt
    GenericImageGenerationRequest:
      type: object
      properties:
        model:
          type: string
          not:
            const: gpt-image-2
          example: nano-banana
        prompt:
          type: string
        size:
          type: string
          description: Model-specific image size or aspect ratio shorthand.
          example: 1k
        input_images:
          type: array
          items:
            type: string
            format: uri
        callback_url:
          type: string
          format: uri
      required:
        - model
        - prompt
    TokenUsage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
        input_tokens:
          type: integer
        output_tokens:
          type: integer
        cached_input_tokens:
          type: integer
      additionalProperties: true
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
              enum:
                - invalid_request
                - auth_error
                - rate_limit
                - insufficient_quota
                - content_policy
                - timeout
                - network_error
                - service_error
                - billable_error
                - unknown
            message:
              type: string
            param:
              type:
                - string
                - 'null'
            code:
              type:
                - string
                - 'null'
          required:
            - type
            - message
      required:
        - error
  responses:
    BadRequest:
      description: 请求参数无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key

````