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

# MAGI-2

> Generate 4–30s 1080p videos with synchronized sound from text, keyframes, or multimodal references.

## Parameters and input modes

`model` and `input` are required; omitted optional fields use model defaults. See the Body section below for full field definitions.

| Request type | Required input fields |
| - | - |
| Text to video | `mode: "text_to_video"`, `prompt` (no media fields) |
| Image to video | `mode: "image_to_video"`, `prompt`, `first_frame_url` (optional `last_frame_url`) |
| Reference to video | `mode: "reference_to_video"`, `prompt`, and ≥1 of `reference_image_urls` / `reference_video_urls` / `reference_audio_urls` |

## Special modes

* **Reference limits & targeting**: `reference_to_video` accepts up to 10 images, 5 videos (2–30s each, ≤30s total), and 5 audio clips (2–30s each, ≤30s total); cite assets in `prompt` as `@Image1`, `@Video1`, `@Audio1`. English prompts are recommended.

## Use cases

Submit an example to `POST /api/v1/tasks/create_task` with your own prompt and media URLs.

```json Text to video theme={null}
{
  "model": "magi-2",
  "input": {
    "mode": "text_to_video",
    "prompt": "A wooden train glides along a misty coastal viaduct at golden hour, ocean waves crashing below.",
    "resolution": "1080p",
    "aspect_ratio": "16:9",
    "duration": 5,
    "generate_audio": true
  }
}
```

```json Image to video (first + last frame) theme={null}
{
  "model": "magi-2",
  "input": {
    "mode": "image_to_video",
    "prompt": "Smooth tracking shot as twilight lanterns illuminate the quiet courtyard.",
    "first_frame_url": "https://cdn.example.com/start.jpg",
    "last_frame_url": "https://cdn.example.com/end.jpg",
    "aspect_ratio": "16:9",
    "duration": 8
  }
}
```

```json Reference to video theme={null}
{
  "model": "magi-2",
  "input": {
    "mode": "reference_to_video",
    "prompt": "Follow the character appearance from @Image1, camera movement from @Video1, and ambient rhythm from @Audio1.",
    "reference_image_urls": [
      "https://cdn.example.com/character.jpg"
    ],
    "reference_video_urls": [
      "https://cdn.example.com/camera.mp4"
    ],
    "reference_audio_urls": [
      "https://cdn.example.com/ambience.mp3"
    ],
    "aspect_ratio": "16:9",
    "duration": 6
  }
}
```

> Track results via [Query task](https://docs.apistable.ai/query-task.md) or `callback_url` ([Webhook security](https://docs.apistable.ai/webhook-secret.md)); see [Create task](https://docs.apistable.ai/create-task.md) for submission errors. Output URLs remain valid for 14 days; tasks unfinished after 24 hours fail at no charge.

## Playground and pricing

Each successful output is billed separately at 1080p for requested `duration` (4–30 integer seconds) at one flat rate; output clips may run \~0.24s longer without extra charge. Audio, aspect ratio, and reference media add no extra charge; failed outputs cost 0. Check balances via [Available Credits](https://docs.apistable.ai/credits.md).

| Resolution | Credits / s | Price / s |
| - | - | - |
| `1080p` (all modes) | 16.0 | With bonus ≈ \*\*$0.073** · Regular $0.080 |

> [card] [Try in Playground](https://apistable.ai/models/magi-2#try)
>
> Test text, keyframe, and multimodal reference modes interactively.

> [card] [View pricing](https://apistable.ai/models/magi-2#pricing)
>
> View 1080p per-second pricing and top-up bonus rates.


## OpenAPI

````yaml openapi-magi-2.json POST /api/v1/tasks/create_task
openapi: 3.1.0
info:
  title: APIstable API
  version: 1.0.0-preview
  description: >-
    Public /api/v1 protocol. Valid API keys have the same account-scoped access.
    Read the selected model documentation for its ID, supported inputs, result
    format and availability before submitting. No client submission idempotency
    or max_credits. Availability, pricing, file retention and callback formats
    follow the selected model contract. Unconfigured operations return 503.
servers:
  - url: https://apistable.ai
    description: API Stable API
security: []
paths:
  /api/v1/tasks/create_task:
    post:
      summary: MAGI-2
      description: >-
        Generate 4–30s 1080p videos with synchronized sound from text,
        keyframes, or multimodal references.
      operationId: magi-2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
              additionalProperties: false
              properties:
                model:
                  type: string
                  enum:
                    - magi-2
                  example: magi-2
                  description: The APIstable model ID for this endpoint.
                input:
                  description: >-
                    MAGI-2 input. Set `mode`, then fill the media fields that
                    mode uses.
                  type: object
                  properties:
                    mode:
                      type: string
                      enum:
                        - text_to_video
                        - image_to_video
                        - reference_to_video
                      description: >-
                        Required explicit workflow mode: `text_to_video`,
                        `image_to_video`, or `reference_to_video`. Extra fields
                        from another mode return HTTP 400.
                    nsfw_check:
                      type: boolean
                      description: >-
                        Optional APIstable safety screening; defaults to false.
                        When true, screening failures reject the request; only
                        text and up to 20 images are screened; audio and video
                        are not screened (HTTP 400 above this limit). Playground
                        always enables screening.
                    output_count:
                      default: 1
                      type: integer
                      minimum: 1
                      maximum: 4
                      description: >-
                        Number of independent videos: integer 1–4, default 1.
                        Successful outputs are billed individually; failed
                        outputs cost nothing.
                    prompt:
                      type: string
                      minLength: 1
                      maxLength: 8000
                      description: >-
                        Required non-empty scene description (1–8,000
                        characters; English recommended). In
                        `reference_to_video`, cite assets as `@Image1`,
                        `@Video1`, and `@Audio1`.
                    resolution:
                      default: 1080p
                      type: string
                      const: 1080p
                      description: Output resolution. Fixed at `1080p` (default).
                    aspect_ratio:
                      default: '16:9'
                      type: string
                      enum:
                        - '21:9'
                        - '16:9'
                        - '4:3'
                        - '1:1'
                        - '3:4'
                        - '9:16'
                      description: >-
                        Output aspect ratio: `21:9`, `16:9` (default), `4:3`,
                        `1:1`, `3:4`, or `9:16`. `auto` is rejected (HTTP 400).
                    duration:
                      default: 5
                      type: integer
                      minimum: 4
                      maximum: 30
                      description: >-
                        Requested output length in integer seconds from `4` to
                        `30` (default `5`). Determines billable seconds; output
                        clips may be ~0.24s longer without extra charge.
                    generate_audio:
                      default: true
                      type: boolean
                      description: >-
                        Generate synchronized audio alongside video. Default
                        `true`; does not change the per-second rate.
                    first_frame_url:
                      type: string
                      format: uri
                      description: First frame image. Required in `image_to_video`.
                    last_frame_url:
                      type: string
                      format: uri
                      description: >-
                        Last frame image. Optional in `image_to_video`; requires
                        `first_frame_url`.
                    reference_image_urls:
                      minItems: 1
                      maxItems: 10
                      type: array
                      items:
                        type: string
                        format: uri
                      description: >-
                        Optional in `reference_to_video` (at least one image,
                        video, or audio item is required). 1–10 images.
                    reference_video_urls:
                      minItems: 1
                      maxItems: 5
                      type: array
                      items:
                        type: string
                        format: uri
                      description: >-
                        Optional in `reference_to_video`. 1–5 videos; each clip
                        must be 2–30s and total reference video duration ≤30s.
                    reference_audio_urls:
                      minItems: 1
                      maxItems: 5
                      type: array
                      items:
                        type: string
                        format: uri
                      description: >-
                        Optional in `reference_to_video`. 1–5 audio clips, each
                        2–30s; total reference audio duration ≤30s.
                  required:
                    - mode
                    - prompt
                  additionalProperties: false
                  not:
                    anyOf:
                      - properties:
                          mode:
                            const: text_to_video
                        required:
                          - mode
                        anyOf:
                          - required:
                              - first_frame_url
                          - required:
                              - last_frame_url
                          - required:
                              - reference_image_urls
                          - required:
                              - reference_video_urls
                          - required:
                              - reference_audio_urls
                      - properties:
                          mode:
                            const: image_to_video
                        required:
                          - mode
                        not:
                          required:
                            - first_frame_url
                      - properties:
                          mode:
                            const: image_to_video
                        required:
                          - mode
                        anyOf:
                          - required:
                              - reference_image_urls
                          - required:
                              - reference_video_urls
                          - required:
                              - reference_audio_urls
                      - properties:
                          mode:
                            const: reference_to_video
                        required:
                          - mode
                        not:
                          anyOf:
                            - required:
                                - reference_image_urls
                            - required:
                                - reference_video_urls
                            - required:
                                - reference_audio_urls
                      - properties:
                          mode:
                            const: reference_to_video
                        required:
                          - mode
                        anyOf:
                          - required:
                              - first_frame_url
                          - required:
                              - last_frame_url
                callback_url:
                  type: string
                  format: uri
                  description: >-
                    Optional public HTTPS endpoint for signed completion
                    callbacks; no redirects or private IPs.
            example:
              model: magi-2
              input:
                mode: text_to_video
                prompt: >-
                  A wooden train glides along a misty coastal viaduct at golden
                  hour, ocean waves crashing below.
                resolution: 1080p
                aspect_ratio: '16:9'
                duration: 5
                generate_audio: true
      responses:
        '200':
          description: Accepted task. Poll the common task endpoint or use callback_url.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - msg
                  - data
                additionalProperties: false
                properties:
                  code:
                    const: 200
                  msg:
                    const: success
                  data:
                    type: object
                    required:
                      - task_id
                    additionalProperties: false
                    properties:
                      task_id:
                        type: string
        '400':
          description: >-
            40001 invalid JSON, 40002 invalid input/callback or input rejected
            by screening, 40003 unsupported parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Invalid or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: '40201: Insufficient credits (live acceptance).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: '40301: Website session requests require the APIstable site origin.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '40401: Unknown model or resource not found in this account.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: '40901: Resource incompatible with this operation.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '410':
          description: '41001: Source audio or temporary resource has expired.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: '41301: Request too large.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: '42201: Requested capability combination is not enabled.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '42901: Rate/concurrency limit (live acceptance).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '50301: Service unavailable. No live submission or charge.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      callbacks:
        Webhook:
          '{$request.body#/callback_url}':
            post:
              requestBody:
                required: true
                description: >-
                  When the task succeeds or fails, APIstable sends a JSON POST
                  to the `callback_url` supplied at creation. Verify the
                  signature and return HTTP 2xx to acknowledge delivery.


                  Read `data.status` to determine the generation outcome.
                  Successful tasks report `succeeded` with generated video URLs
                  in `data.result.urls`. For a failed task, `data.result` is
                  `null` and `data.message` contains the failure reason.


                  Use `X-APIstable-Signature`, `X-APIstable-Timestamp`, and
                  `X-APIstable-Event-Id` to verify and deduplicate deliveries.
                  See [Webhook security](/webhook-secret).


                  **Webhook payload example**


                  ```json

                  {
                    "code": 200,
                    "msg": "success",
                    "data": {
                      "task_id": "c6adbc82-8b9a-4d6f-8b60-1114c8c4aafb",
                      "model": "magi-2",
                      "status": "succeeded",
                      "created_at": "2026-11-25T08:30:00.000Z",
                      "completed_at": "2026-11-25T08:45:00.000Z",
                      "duration": 900000,
                      "charged_credits": 80,
                      "message": "",
                      "input": "{\"mode\":\"text_to_video\",\"prompt\":\"A wooden train glides along a misty coastal viaduct at golden hour, ocean waves crashing below.\",\"resolution\":\"1080p\",\"aspect_ratio\":\"16:9\",\"duration\":5,\"generate_audio\":true}",
                      "result": {
                        "urls": [
                          "https://cdn.example.com/generated/video.mp4"
                        ],
                        "items": [
                          {
                            "id": "e7aacd19-819a-4747-bbbf-46fb6f2995a5",
                            "urls": [
                              "https://cdn.example.com/generated/video.mp4"
                            ],
                            "last_frame_url": null,
                            "draft": false,
                            "draft_expires_at": null
                          }
                        ]
                      }
                    }
                  }

                  ```
                content:
                  application/json:
                    schema:
                      type: object
                      required:
                        - code
                        - msg
                        - data
                      properties:
                        code:
                          type: integer
                          const: 200
                        msg:
                          type: string
                          const: success
                        data:
                          type: object
                          additionalProperties: false
                          required:
                            - task_id
                            - model
                            - status
                            - created_at
                            - completed_at
                            - duration
                            - charged_credits
                            - message
                            - input
                            - result
                          properties:
                            task_id:
                              type: string
                            model:
                              type: string
                              const: magi-2
                            status:
                              type: string
                              enum:
                                - succeeded
                                - failed
                            created_at:
                              type: string
                              format: date-time
                            completed_at:
                              type:
                                - string
                                - 'null'
                              format: date-time
                            duration:
                              type:
                                - integer
                                - 'null'
                              minimum: 0
                              description: >-
                                Total elapsed milliseconds; null while
                                processing.
                            charged_credits:
                              type:
                                - number
                                - 'null'
                              minimum: 0
                              description: Final charged Credits; null until completion.
                            message:
                              type: string
                              description: >-
                                Failure reason for failed tasks, or an
                                actionable pending-settlement message while
                                processing; empty on success.
                            input:
                              type: string
                              contentMediaType: application/json
                              description: JSON-serialized accepted model input.
                            result:
                              type:
                                - object
                                - 'null'
                              required:
                                - urls
                                - items
                              properties:
                                urls:
                                  type: array
                                  items:
                                    type: string
                                    format: uri
                                items:
                                  type: array
                                  maxItems: 1
                                  items:
                                    type: object
                                    required:
                                      - id
                                      - urls
                                      - last_frame_url
                                      - draft
                                      - draft_expires_at
                                    properties:
                                      id:
                                        type: string
                                        format: uuid
                                      urls:
                                        type: array
                                        items:
                                          type: string
                                          format: uri
                                      last_frame_url:
                                        type:
                                          - string
                                          - 'null'
                                        format: uri
                                      draft:
                                        type: boolean
                                      draft_expires_at:
                                        type:
                                          - string
                                          - 'null'
                                        format: date-time
                    example:
                      code: 200
                      msg: success
                      data:
                        task_id: c6adbc82-8b9a-4d6f-8b60-1114c8c4aafb
                        model: magi-2
                        status: succeeded
                        created_at: '2026-11-25T08:30:00.000Z'
                        completed_at: '2026-11-25T08:45:00.000Z'
                        duration: 900000
                        charged_credits: 80
                        message: ''
                        input: >-
                          {"mode":"text_to_video","prompt":"A wooden train
                          glides along a misty coastal viaduct at golden hour,
                          ocean waves crashing
                          below.","resolution":"1080p","aspect_ratio":"16:9","duration":5,"generate_audio":true}
                        result:
                          urls:
                            - https://cdn.example.com/generated/video.mp4
                          items:
                            - id: e7aacd19-819a-4747-bbbf-46fb6f2995a5
                              urls:
                                - https://cdn.example.com/generated/video.mp4
                              last_frame_url: null
                              draft: false
                              draft_expires_at: null
              responses:
                2XX:
                  description: Webhook acknowledged.
              method: post
              type: path
            path: '{$request.body#/callback_url}'
      security:
        - bearerAuth: []
components:
  schemas:
    Error:
      type: object
      required:
        - code
        - msg
        - data
      properties:
        code:
          type: integer
        msg:
          type: string
        data:
          type: 'null'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Sign in to APIstable, then create and copy a key from [API Key
        management](https://apistable.ai/console/keys).


        Send this HTTP header with every request:


        ```http

        Authorization: Bearer YOUR_API_KEY

        ```


        Replace YOUR_API_KEY with the key you created.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.