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

# Text to Video

> Generate videos from text descriptions using AI video generation models. Supported model_id are `wan2.2` and `ltx-2.3`. Any other models passed will be ignored and defauted to `wan2.2` 

![Text to Video Example](https://assets.modelslab.ai/generations/9a4d8540-68e9-4e26-b5de-f887d2e38f2a.png)

## Request

Make a `POST` request to the endpoint below with the required parameters.

```bash theme={null}
POST https://modelslab.com/api/v6/video/text2video
```

# Body

```json json theme={null}
{
    "key": "your_api_key",
    "prompt": "A majestic space station orbiting Earth, with the sun rising behind it, cinematic, 4K",
    "negative_prompt": "low quality, blurry, static",
    "model_id": "wan2.2",
    "height": 512,
    "width": 512,
    "num_frames": 25,
    "num_inference_steps": 20,
    "guidance_scale": 7,
    "output_type": "mp4",
    "webhook": null,
    "track_id": null
}
```

## Async Pattern

Since video generation takes time, use this pattern:

```python theme={null}
import requests
import time

def generate_video(prompt, api_key):
    # 1. Submit the request
    response = requests.post(
        "https://modelslab.com/api/v6/video/text2video",
        json={
            "key": api_key,
            "prompt": prompt,
            "num_frames": 25
        }
    )
    data = response.json()

    if data["status"] == "error":
        raise Exception(data["message"])

    request_id = data["id"]

    # 2. Poll for results
    while True:
        fetch = requests.post(
            f"https://modelslab.com/api/v6/video/fetch/{request_id}",
            json={"key": api_key}
        )
        result = fetch.json()

        if result["status"] == "success":
            return result["output"][0]
        elif result["status"] == "failed":
            raise Exception(result.get("message", "Generation failed"))

        # Still processing, wait and retry
        time.sleep(5)

# Usage
video_url = generate_video("A sunset over the ocean", "your_api_key")
print(f"Video ready: {video_url}")
```

## Tips for Better Videos

<AccordionGroup>
  <Accordion title="Describe Motion">
    Unlike images, videos need motion descriptions:

    * ❌ "A cat"
    * ✅ "A cat walking across a sunny room, tail swaying"
  </Accordion>

  <Accordion title="Keep It Simple">
    Video models work best with clear, focused prompts. Avoid overly complex scenes.
  </Accordion>

  <Accordion title="Use Upscaling">
    Generate at 512x512 then use upscale parameters for higher resolution output.
  </Accordion>

  <Accordion title="Choose Output Format">
    * **MP4**: Best for most uses, smaller file size
    * **GIF**: Good for short loops, works everywhere
  </Accordion>
</AccordionGroup>


## OpenAPI

````yaml POST /video/text2video
openapi: 3.1.0
info:
  title: ModelsLab Video API
  description: >-
    A comprehensive API for AI-driven video generation including text-to-video,
    image-to-video, scene transitions, and video management capabilities
  license:
    name: MIT
  version: 6.0.0
servers:
  - url: https://modelslab.com/api/v6
security: []
paths:
  /video/text2video:
    post:
      summary: Generate video from text prompt
      description: >-
        Creates a video based on a text description using specified models like
        cogvideox or wanx
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TextToVideoRequest'
      responses:
        '200':
          description: Video generation response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VideoResponse'
        '400':
          description: Bad request - invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized - invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    TextToVideoRequest:
      type: object
      required:
        - key
        - model_id
        - prompt
      properties:
        key:
          type: string
          description: Your API Key used for request authorization
        model_id:
          type: string
          enum:
            - cogvideox
            - wanx
          description: The ID of the model to use
        prompt:
          type: string
          description: Text prompt describing the video content
        negative_prompt:
          type: string
          description: Items you don't want in the video
        seed:
          oneOf:
            - type: integer
            - type: 'null'
          description: >-
            Seed for reproducible results. Same seed gives same result. Pass
            null for random
        height:
          type: integer
          default: 512
          maximum: 512
          description: Height of the video in pixels
        width:
          type: integer
          default: 512
          maximum: 512
          description: Width of the video in pixels
        num_frames:
          type: integer
          default: 25
          maximum: 25
          description: Number of frames in the video
        num_inference_steps:
          type: integer
          default: 20
          maximum: 50
          description: Number of denoising steps
        guidance_scale:
          type: number
          default: 7
          minimum: 0
          maximum: 8
          description: Scale for classifier-free guidance
        clip_skip:
          oneOf:
            - type: integer
              maximum: 2
            - type: 'null'
          description: >-
            Number of CLIP layers to skip. Skipping 2 layers often gives more
            aesthetic results
        upscale_height:
          type: integer
          default: 640
          maximum: 1024
          description: The upscaled height for videos generated
        upscale_width:
          type: integer
          default: 1024
          maximum: 1024
          description: The upscaled width for videos generated
        upscale_strength:
          type: number
          default: 0.6
          minimum: 0
          maximum: 1
          description: >-
            Strength of upscaling. Higher values result in more noticeable
            differences
        upscale_guidance_scale:
          type: number
          default: 12
          minimum: 0
          maximum: 8
          description: Guidance scale for upscaling videos
        upscale_num_inference_steps:
          type: integer
          default: 20
          maximum: 50
          description: Number of denoising steps for upscaling
        use_improved_sampling:
          type: boolean
          default: false
          description: >-
            Whether to use improved sampling technique for better temporal
            consistency
        improved_sampling_seed:
          type: integer
          description: Seed for consistent video generation with improved sampling
        fps:
          type: integer
          maximum: 16
          description: Frames per second rate of the generated video
        output_type:
          type: string
          default: gif
          enum:
            - mp4
            - gif
          description: Output format type
        instant_response:
          type: boolean
          default: false
          description: >-
            If true, returns future links for queued requests instantly instead
            of waiting
        temp:
          type: boolean
          default: false
          description: If true, stores video in temporary storage (cleaned every 24 hours)
        webhook:
          type: string
          format: uri
          description: URL to receive a POST API call once video generation is complete
        track_id:
          type: string
          description: Unique ID used in webhook response to identify the request
    VideoResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - success
            - processing
            - error
          description: Status of the video generation
        generationTime:
          type: number
          description: Time taken to generate the video in seconds
        id:
          type: integer
          description: Unique identifier for the video generation
        output:
          type: array
          items:
            type: string
            format: uri
          description: Array of generated video URLs
        proxy_links:
          type: array
          items:
            type: string
            format: uri
          description: Array of proxy video URLs
        future_links:
          type: array
          items:
            type: string
            format: uri
          description: Array of future video URLs for queued requests
        meta:
          type: object
          description: Metadata about the video generation including all parameters used
        eta:
          type: integer
          description: Estimated time for completion in seconds (processing status)
        message:
          type: string
          description: Status message or additional information
        tip:
          type: string
          description: Additional information or tips for the user
        fetch_result:
          type: string
          format: uri
          description: URL to fetch the result when processing
    Error:
      type: object
      required:
        - status
        - message
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          description: Error message description

````