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

# Generate images

> Starts a background job that generates images from a prompt, optionally editing or combining
reference images. The response contains a `job_id` to poll with `GET /image/{job_id}`, and the
credits the job will be charged. Requires a valid `X-API-KEY` header.

Throws:
- 400 if the model, resolution or aspect ratio is not supported, the model does not accept
  reference images, or the prompt references images the request does not carry
- 402 if the workspace does not have enough credits, or the model is not available on its plan
- 404 if a reference image does not exist or is not accessible
- 422 if the request body is invalid



## OpenAPI

````yaml POST /image
openapi: 3.1.0
info:
  title: Wondercraft Public API
  version: 0.0.1
servers:
  - url: https://api.wondercraft.ai/v1
    description: Base Wondercraft API
security: []
paths:
  /image:
    post:
      tags:
        - Images
      summary: Generate images
      description: >-
        Starts a background job that generates images from a prompt, optionally
        editing or combining

        reference images. The response contains a `job_id` to poll with `GET
        /image/{job_id}`, and the

        credits the job will be charged. Requires a valid `X-API-KEY` header.


        Throws:

        - 400 if the model, resolution or aspect ratio is not supported, the
        model does not accept
          reference images, or the prompt references images the request does not carry
        - 402 if the workspace does not have enough credits, or the model is not
        available on its plan

        - 404 if a reference image does not exist or is not accessible

        - 422 if the request body is invalid
      operationId: generate_image_image_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateImageApiRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateImageJobResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    GenerateImageApiRequest:
      properties:
        prompt:
          type: string
          minLength: 1
          title: Prompt
          description: What to generate. Refer to references as `@Image 1`, …
        model_id:
          type: string
          title: Model Id
          description: A model `id` from `GET /image/models`
        resolution:
          anyOf:
            - $ref: '#/components/schemas/ApiResolution'
            - type: 'null'
          description: >-
            One of the model's `resolutions`; defaults to its
            `default_resolution`
        aspect_ratio:
          anyOf:
            - $ref: '#/components/schemas/ApiAspectRatio'
            - type: 'null'
          description: One of the model's `aspect_ratios`; defaults to 1:1 when supported
        number_of_images:
          type: integer
          maximum: 4
          minimum: 1
          title: Number Of Images
          description: How many images to generate in this job
          default: 1
        reference_image_ids:
          items:
            type: string
            format: uuid
          type: array
          title: Reference Image Ids
          description: >-
            Images from `POST /image/upload` or earlier image jobs, in prompt
            order. The first is the image being edited; the rest are extra
            references.
      additionalProperties: false
      type: object
      required:
        - prompt
        - model_id
      title: GenerateImageApiRequest
    CreateImageJobResponse:
      properties:
        job_id:
          type: string
          format: uuid
          title: Job Id
          description: Poll `GET /image/{job_id}` with this ID
        estimated_credits:
          type: number
          title: Estimated Credits
          description: Credits this job will be charged once the images are ready
      type: object
      required:
        - job_id
        - estimated_credits
      title: CreateImageJobResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ApiResolution:
      type: string
      enum:
        - 480p
        - 720p
        - 1080p
        - 2k
        - 4k
      title: ApiResolution
      description: >-
        Output resolution shared by the image and video APIs; each model lists
        the values it supports.
    ApiAspectRatio:
      type: string
      enum:
        - '16:9'
        - '9:16'
        - '1:1'
      title: ApiAspectRatio
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-KEY

````

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