Skip to content

Latest commit

 

History

History
124 lines (89 loc) · 14.4 KB

File metadata and controls

124 lines (89 loc) · 14.4 KB

v1.text-to-video

Module Functions

Text To Video Generate Workflow

The workflow performs the following action

  1. upload local assets to Magic Hour storage. So you can pass in a local path instead of having to upload files yourself
  2. trigger a generation
  3. poll for a completion status. This is configurable
  4. if success, download the output to local directory

Tip

This is the recommended way to use the SDK unless you have specific needs where it is necessary to split up the actions.

Parameters

In addition to the parameters listed in the create section below, generate introduces 3 new parameters:

  • waitForCompletion (boolean, default true): Whether to wait for the project to complete.
  • downloadOutputs (boolean, default true): Whether to download the generated files
  • downloadDirectory (string, optional): Directory to save downloaded files (defaults to current directory)

Example Snippet

import { Client } from "magic-hour";

const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.textToVideo.generate(
  {
    endSeconds: 5.0,
    name: "Text To Video video",
    orientation: "landscape",
    resolution: "720p",
    style: { prompt: "a dog running" },
  },
  {
    waitForCompletion: true,
    downloadOutputs: true,
    downloadDirectory: ".",
  },
);

Text-to-Video

What this API does

Create the same Text To Video you can make in the browser, but programmatically, so you can automate it, run it at scale, or connect it to your own app or workflow.

Good for

  • Automation and batch processing
  • Adding text to video into apps, pipelines, or tools

How it works (3 steps)

  1. Upload your inputs (video, image, or audio) with Generate Upload URLs and copy the file_path.
  2. Send a request to create a text to video job with the basic fields.
  3. Check the job status until it's complete, then download the result from downloads.

Key options

  • Inputs: usually a file, sometimes a YouTube link, depending on project type
  • Resolution: free users are limited to 576px; higher plans unlock HD and larger sizes
  • Extra fields: e.g. face_swap_mode, start_seconds/end_seconds, or a text prompt

Cost
Credits are only charged for the frames that actually render. You'll see an estimate when the job is queued, and the final total after it's done.

For detailed examples, see the product page.

API Endpoint: POST /v1/text-to-video

Parameters

Parameter Required Deprecated Description Example
endSeconds The total duration of the output video in seconds. Supported durations depend on the chosen model: * ltx-2: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30 * wan-2.2: 3, 4, 5, 6, 7, 8, 9, 10, 15 * seedance: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 * seedance-2.0: 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 * kling-2.5: 5, 10 * kling-3.0: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 * sora-2: 4, 8, 12, 24, 36, 48, 60 * veo3.1: 4, 6, 8, 16, 24, 32, 40, 48, 56 * veo3.1-lite: 8, 16, 24, 32, 40, 48, 56 Legacy models: * kling-1.6: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 5.0
style {"prompt": "a dog running"}
└─ prompt The prompt used for the video. "a dog running"
└─ qualityMode DEPRECATED: Please use resolution field instead. For backward compatibility: * quick maps to 720p resolution * studio maps to 1080p resolution This field will be removed in a future version. Use the resolution field to directly to specify the resolution. "quick"
aspectRatio Determines the aspect ratio of the output video. * ltx-2: Supports 9:16, 16:9, 1:1. * wan-2.2: Supports 9:16, 16:9, 1:1. * seedance: Supports 9:16, 16:9, 1:1. * seedance-2.0: Supports 9:16, 16:9, 1:1. * kling-2.5: Supports 9:16, 16:9, 1:1. * kling-3.0: Supports 9:16, 16:9, 1:1. * sora-2: Supports 9:16, 16:9. * veo3.1: Supports 9:16, 16:9. * veo3.1-lite: Supports 9:16, 16:9. Legacy models: * kling-1.6: Supports 9:16, 16:9, 1:1. "16:9"
audio Whether to include audio in the video. Defaults to false if not specified. Audio support varies by model: * ltx-2: Automatically included with no extra credits * wan-2.2: Not supported * seedance: Not supported * seedance-2.0: Automatically included with no extra credits * kling-2.5: Automatically included with no extra credits * kling-3.0: Toggle-able (can enable/disable) * sora-2: Automatically included with no extra credits * veo3.1: Toggle-able (can enable/disable) * veo3.1-lite: Toggle-able (can enable/disable) Legacy models: * kling-1.6: Not supported true
model The AI model to use for video generation. * default: uses our currently recommended model for general use. For paid tiers, defaults to kling-3.0. For free tiers, it defaults to ltx-2. * ltx-2: Fast iteration with audio and lip-sync * wan-2.2: Fast, strong visuals with effects * seedance: Fast iteration and start/end frames * seedance-2.0: State-of-the-art quality and consistency * kling-2.5: Motion, action, and camera control * kling-3.0: Cinematic, multi-scene storytelling * sora-2: Story-first concepts and creativity * veo3.1: Realistic visuals and prompt adherence * veo3.1-lite: Good for fast, affordable, high-quality daily generation. Legacy models: * kling-1.6: Reliable baseline with smooth motion If you specify the deprecated model value that includes the -audio suffix, this will be the same as included audio as true. "kling-3.0"
name Give your video a custom name for easy identification. "My Text To Video video"
orientation Deprecated. Use aspect_ratio instead. "landscape"
resolution Controls the output video resolution. Defaults to 720p on paid tiers and 480p on free tiers. * ltx-2: Supports 480p, 720p, 1080p. * wan-2.2: Supports 480p, 720p, 1080p. * seedance: Supports 480p, 720p, 1080p. * seedance-2.0: Supports 480p, 720p. * kling-2.5: Supports 720p, 1080p. * kling-3.0: Supports 720p, 1080p. * sora-2: Supports 720p. * veo3.1: Supports 720p, 1080p. * veo3.1-lite: Supports 720p, 1080p. Legacy models: * kling-1.6: Supports 720p, 1080p. "720p"

Example Snippet

import { Client } from "magic-hour";

const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.textToVideo.create({
  aspectRatio: "16:9",
  audio: true,
  endSeconds: 5.0,
  model: "kling-3.0",
  name: "My Text To Video video",
  orientation: "landscape",
  resolution: "720p",
  style: { prompt: "a dog running" },
});

Response

Type

V1TextToVideoCreateResponse

Example
{"creditsCharged": 450, "estimatedFrameCost": 450, "id": "cuid-example"}