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

# Video generation

> Generate videos from text prompts using video generation models via the v1/responses endpoint

You can access video generation models and interact with
them through a REST API. This page explains how to use the
[`v1/responses`](/api-reference/inference/create-response) endpoint to generate videos from
text prompts, with examples for each input type.

Before you start, check the [supported models](/models) page to see
which video generation models are available via shared endpoints (available
out of the box) versus dedicated endpoints (custom deployments), since not
every model or endpoint supports every modality.

## Call the v1/responses endpoint

The `v1/responses` endpoint provides a unified interface for
diverse AI tasks including video generation, with structured input and output
handling. It's built on [Open
Responses](https://huggingface.co/blog/open-responses), an open-source
initiative to create a standardized, provider-agnostic API specification that
works across different AI providers and model backends.

### Generate from a text prompt

For text-to-video generation, set `input` to a plain string describing the
video you want. The model returns the generated video as base64-encoded data in
`output[0].content[0].image_data`:

<Tabs>
  <Tab title="Python">
    Pass a text string as the `input` field and read back the base64-encoded video
    data:

    ```python theme={null}
    response = client.responses.create(
        model="Wan-AI/Wan2.2-T2V-A14B-Diffusers",
        input="Your text prompt here",
        extra_body={
            "provider_options": {
                "image": {"height": 512, "width": 512, "steps": 28}
            }
        }
    )

    video_data = response.output[0].content[0].image_data
    ```
  </Tab>

  <Tab title="curl">
    Send the prompt as the `input` field in the request body:

    ```bash theme={null}
    curl -X POST https://api.modular.com/v1/responses \
      -H "Authorization: Bearer $MODULAR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "Wan-AI/Wan2.2-T2V-A14B-Diffusers",
        "input": "Your text prompt here",
        "provider_options": {
          "image": {"height": 512, "width": 512, "steps": 28}
        }
      }'
    ```
  </Tab>
</Tabs>

### Configure generation parameters

The `provider_options` argument is an extension point in the Open Responses spec
that lets each API provider expose parameters beyond the standard request fields.
It's used here to surface video generation controls such as dimensions and
denoising steps.

The following parameters are available under `provider_options.image`:

| Parameter          | Default | Description                                           |
| ------------------ | ------- | ----------------------------------------------------- |
| `height` / `width` | 512     | Output dimensions in pixels (must be multiples of 16) |
| `steps`            | 28      | Number of denoising steps                             |

**Height and width**: Video dimensions must be a multiple of 16 and are
automatically scaled to a multiple of 16 if an incompatible integer is provided.

**Steps**: `steps` has the greatest effect on generation time. Diffusion models
work by iteratively refining a noisy initial state. More steps produce
higher-quality results but take proportionally longer. You can experiment with
`steps` when considering the tradeoffs of speed and quality.

If you encounter memory errors, try reducing your output video dimensions or the
number of denoising steps:

```json theme={null}
"provider_options": {"image": {"height": 480, "width": 480, "steps": 20}}
```

## Generate a video from text

Generate a video from a text description by sending a request to the
`v1/responses` endpoint. The `input` field is a text string describing the
desired video, and `provider_options` controls generation parameters. You can
send requests using either the OpenAI Python SDK or curl:

<Tabs>
  <Tab title="Python">
    Send the prompt and write the decoded video to a file:

    ```python title="generate-video.py" theme={null}
    import os
    import base64
    from openai import OpenAI

    client = OpenAI(
        base_url="https://api.modular.com/v1",
        api_key=os.environ["MODULAR_API_KEY"],
    )

    response = client.responses.create(
        model="Wan-AI/Wan2.2-T2V-A14B-Diffusers",
        input="A campfire crackles in a forest clearing at night, sparks spiraling upward into a star-filled sky",
        extra_body={
            "provider_options": {
                "image": {"height": 512, "width": 512, "steps": 28}
            }
        }
    )

    video_data = response.output[0].content[0].image_data
    with open("output-text-to-video.mp4", "wb") as f:
        f.write(base64.b64decode(video_data))
    ```

    Run the script to generate the video:

    ```bash theme={null}
    python generate-video.py
    ```

    The model saves the generated video to `output-text-to-video.mp4` in your
    current directory.
  </Tab>

  <Tab title="curl">
    Send a request to the `v1/responses` endpoint and decode the base64-encoded
    video data from the response:

    ```bash theme={null}
    curl -X POST https://api.modular.com/v1/responses \
      -H "Authorization: Bearer $MODULAR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "Wan-AI/Wan2.2-T2V-A14B-Diffusers",
        "input": "A campfire crackles in a forest clearing at night, sparks spiraling upward into a star-filled sky",
        "provider_options": {
          "image": {"height": 512, "width": 512, "steps": 28}
        }
      }' | jq -r '.output[0].content[0].image_data' | base64 -d > output-text-to-video.mp4
    ```

    This sends a text prompt to the model and decodes the base64-encoded video data
    from the response into `output-text-to-video.mp4`.
  </Tab>
</Tabs>

Your output should look similar to the following:

<video src="https://mintcdn.com/modular/21dnEKVIFHhCZ_2p/inference/images/output-text-to-video.mp4?fit=max&auto=format&n=21dnEKVIFHhCZ_2p&q=85&s=c29428d5a856561521c291c53406b73a" width="512" controls muted loop data-path="inference/images/output-text-to-video.mp4" />
