> ## 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 a video

> Starts a background job that generates a video. The mode follows from the inputs you send:
nothing extra for text-to-video, `start_frame_image_id` for image-to-video (plus
`end_frame_image_id` for first/last frame), `reference_image_ids` and/or `reference_video_ids`
for references, or `source_video_id` to edit a video. The response contains a `job_id` to poll
with `GET /video/{job_id}`, and the credits the job is expected to cost.
Requires a valid `X-API-KEY` header.

Throws:
- 400 if the model, mode, resolution, duration or aspect ratio is not supported, a clip is too
  short or long, or the prompt references inputs 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 an image or video does not exist or is not accessible
- 422 if the request body is invalid, e.g. it mixes inputs from different modes



## OpenAPI

````yaml POST /video
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:
  /video:
    post:
      tags:
        - Videos
      summary: Generate a video
      description: >-
        Starts a background job that generates a video. The mode follows from
        the inputs you send:

        nothing extra for text-to-video, `start_frame_image_id` for
        image-to-video (plus

        `end_frame_image_id` for first/last frame), `reference_image_ids` and/or
        `reference_video_ids`

        for references, or `source_video_id` to edit a video. The response
        contains a `job_id` to poll

        with `GET /video/{job_id}`, and the credits the job is expected to cost.

        Requires a valid `X-API-KEY` header.


        Throws:

        - 400 if the model, mode, resolution, duration or aspect ratio is not
        supported, a clip is too
          short or long, or the prompt references inputs 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 an image or video does not exist or is not accessible

        - 422 if the request body is invalid, e.g. it mixes inputs from
        different modes
      operationId: generate_video_video_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateVideoApiRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateVideoJobResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    GenerateVideoApiRequest:
      properties:
        prompt:
          type: string
          minLength: 1
          title: Prompt
          description: What to generate. Refer to references as `@Image 1` or `@Video 1`.
        model_id:
          type: string
          title: Model Id
          description: A model `id` from `GET /video/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 16:9 when supported
        duration:
          anyOf:
            - type: integer
              maximum: 30
              minimum: 1
            - type: 'null'
          title: Duration
          description: >-
            Seconds, one of the model's `durations`; defaults to its
            `default_duration`
        start_frame_image_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Start Frame Image Id
          description: >-
            Image to open the video with (image mode), from `POST /image/upload`
            or an image job
        end_frame_image_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: End Frame Image Id
          description: >-
            Image to end the video with (frames mode); requires
            `start_frame_image_id`
        reference_image_ids:
          items:
            type: string
            format: uuid
          type: array
          title: Reference Image Ids
          description: Subject or style reference images (references mode), in prompt order
        reference_video_ids:
          items:
            type: string
            format: uuid
          type: array
          title: Reference Video Ids
          description: Motion or style reference clips (references mode), in prompt order
        source_video_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Source Video Id
          description: >-
            Video to edit (video_to_video mode), from `POST /video/upload` or a
            video job
      additionalProperties: false
      type: object
      required:
        - prompt
        - model_id
      title: GenerateVideoApiRequest
    CreateVideoJobResponse:
      properties:
        job_id:
          type: string
          format: uuid
          title: Job Id
          description: Poll `GET /video/{job_id}` with this ID
        estimated_credits:
          type: number
          title: Estimated Credits
          description: Credits this job is expected to cost once the video is ready
      type: object
      required:
        - job_id
        - estimated_credits
      title: CreateVideoJobResponse
    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.