magic_hour 0.83.0

Magic Hour Rust SDK
Documentation
# v1.ai_ugc_ad

## Module Functions

### AI UGC Ad Generator <a name="create"></a>

Create a spoken UGC video from a prepared image and script. Returns a project ID; poll GET /v1/video-projects/{id} for status and downloads. To compose an image, generate the image separately with the Image Editor API and supply its download URL.

**API Endpoint**: `POST /v1/ai-ugc-ad`

#### Parameters

| Parameter               | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                 | Example                                                                                                    |
| ----------------------- | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `assets`                |    ✓     |                                                                                                                                                                                                                                                                                                                                                                                                             | `V1AiUgcAdCreateBodyAssets {image_file_path: "api-assets/id/image.jpg".to_string(), ..Default::default()}` |
| `└─ image_file_path`    |    ✓     | Prepared image to animate. This value is either - a direct URL to the file. The URL path must end in a supported file extension. - `file_path` field from the response of the [upload urls API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls). See the [file upload guide](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file) for details.    | `"api-assets/id/image.jpg".to_string()`                                                                    |
| `end_seconds`           |    ✓     | Video duration in seconds. Supported values by model: * kling-3.0: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 seconds. * ltx-2.5: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 seconds. * veo3.1: 4, 6, 8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 120, 127, 134, 141 seconds. Free plans are limited to 5 seconds unless a credit pack has been purchased. | `4.0`                                                                                                      |
| `script`                |    ✓     | The words the actor should speak. Character limits apply after trimming: * kling-3.0: 2304 characters. * ltx-2.5: 1804 characters. * veo3.1: 2500 characters. LTX and Kling dialogue wrappers count toward their model prompt limit.                                                                                                                                                                        | `"Meet your new everyday essential.".to_string()`                                                          |
| `additional_properties` |    ✗     |                                                                                                                                                                                                                                                                                                                                                                                                             | `std::collections::HashMap::<String, serde_json::Value>::new()`                                            |
| `model`                 |    ✗     | Defaults to kling-3.0 on paid plans and ltx-2.5 on free plans.                                                                                                                                                                                                                                                                                                                                              | `V1AiUgcAdCreateBodyModelEnum::Kling30`                                                                    |
| `resolution`            |    ✗     | Defaults to 720p on paid plans and 480p on free plans. Unsupported model/resolution combinations and resolutions unavailable for your plan are rejected.                                                                                                                                                                                                                                                    | `V1AiUgcAdCreateBodyResolutionEnum::Enum1080p`                                                             |

#### Example Snippet

```rust
let client = magic_hour::Client::default()
    .with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
    .v1()
    .ai_ugc_ad()
    .create(magic_hour::resources::v1::ai_ugc_ad::CreateRequest {
        assets: magic_hour::models::V1AiUgcAdCreateBodyAssets {
            image_file_path: "api-assets/id/image.jpg".to_string(),
            ..Default::default()
        },
        end_seconds: 4.0,
        script: "Meet your new everyday essential.".to_string(),
        ..Default::default()
    })
    .await;
```

#### Response

##### Type

[V1AiUgcAdCreateResponse](/src/models/v1_ai_ugc_ad_create_response.rs)

##### Example

```rust
V1AiUgcAdCreateResponse {credits_charged: 450, estimated_frame_cost: 123, id: "cuid-example".to_string()}
```