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

# Create an image

> Starts an image generation task. The price is reserved from your credits now, charged when the task completes, and refunded if it fails.



## OpenAPI

````yaml /openapi.json post /v1/images/generations
openapi: 3.1.0
info:
  title: one-api.ai
  version: 1.0.0
  description: Image and video generation tasks.
servers:
  - url: https://one-api.ai
security:
  - bearerAuth: []
tags:
  - name: Generate
    description: Start an image or video task.
  - name: Tasks
    description: Read task status and results.
paths:
  /v1/images/generations:
    post:
      tags:
        - Generate
      summary: Create an image
      description: >-
        Starts an image generation task. The price is reserved from your credits
        now, charged when the task completes, and refunded if it fails.
      operationId: createImage
      parameters:
        - name: wait
          in: query
          required: false
          description: >-
            Hold the call open until the task finishes, for at most this many
            seconds. `Prefer: wait=<seconds>` does the same.
          schema:
            type: integer
            minimum: 0
            maximum: 60
            default: 0
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageRequest'
            example:
              model: z-image-turbo
              prompt: a red fox asleep in fresh snow
              size: '16:9'
      responses:
        '200':
          description: >-
            The task was accepted. Without `wait`, the entry holds the task id
            and `submitted`. With `wait`, it also holds the task as it stood
            when the wait ended.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedResponse'
              examples:
                submitted:
                  summary: Without wait
                  value:
                    code: 200
                    data:
                      - task_id: task_0a17552fb8dbea3a74bc42048e5212e1
                        status: submitted
        '400':
          description: A field is missing, out of range, or not supported by the model.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: The API key is missing, wrong or revoked.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: The balance does not cover the task. Nothing was started.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The model is not offered on this route.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Too many requests, or five tasks are already unfinished.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ImageRequest:
      type: object
      additionalProperties: false
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          enum:
            - z-image-turbo
        prompt:
          type: string
          minLength: 1
          maxLength: 2000
          description: What to draw.
        size:
          type: string
          enum:
            - '1:1'
            - '4:3'
            - '3:4'
            - '16:9'
            - '9:16'
            - '3:2'
            - '2:3'
          default: '1:1'
          description: Aspect ratio.
        resolution:
          type: string
          enum:
            - 1K
            - 2K
          default: 1K
          description: Resolution tier. Not case-sensitive.
        seed:
          type: integer
          description: Seed for a reproducible result.
        output_format:
          type: string
          enum:
            - jpg
            - png
            - webp
          default: jpg
        'n':
          type: integer
          enum:
            - 1
          default: 1
          description: Images per request. Only 1 is accepted.
    CreatedResponse:
      type: object
      required:
        - code
        - data
      properties:
        code:
          type: integer
          examples:
            - 200
        data:
          type: array
          minItems: 1
          maxItems: 1
          items:
            $ref: '#/components/schemas/CreatedTask'
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - bad_request
                - unauthorized
                - insufficient_credits
                - not_found
                - method_not_allowed
                - rate_limited
                - bad_gateway
            message:
              type: string
    CreatedTask:
      type: object
      required:
        - task_id
        - status
      description: >-
        Always holds `task_id` and `status`. When the call waited, the other
        task fields are included as well.
      properties:
        task_id:
          type: string
        status:
          type: string
          enum:
            - submitted
            - pending
            - processing
            - completed
            - failed
      additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Your one-api.ai API key.

````

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