{
  "openapi": "3.1.0",
  "info": {
    "title": "MAGI-2 API — 1080p Video & Audio Generation API",
    "version": "2026.11.27",
    "description": "MAGI-2 API is an independent API platform providing hosted REST API access to Sand.ai MAGI-2 1080p 25fps audio-video generation (4-30s, up to 20 multimodal references, $0.088/s flat billing with $0 reference fee).",
    "contact": {
      "name": "MAGI-2 API",
      "url": "https://magi2api.net",
      "email": "support@magi2api.net"
    }
  },
  "servers": [
    {
      "url": "https://api.beatapi.io",
      "description": "MAGI-2 API Video Inference Endpoint"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key"
      }
    },
    "schemas": {
      "Magi2CreateTaskRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "magi-2"
            ],
            "default": "magi-2"
          },
          "prompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000
          },
          "duration": {
            "type": "integer",
            "minimum": 4,
            "maximum": 30,
            "default": 5
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "16:9",
              "9:16",
              "1:1",
              "4:3",
              "3:4",
              "21:9"
            ],
            "default": "16:9",
            "description": "Must be omitted when images[] is provided."
          },
          "resolution": {
            "type": "string",
            "enum": [
              "1080p"
            ],
            "default": "1080p"
          },
          "generate_audio": {
            "type": "boolean",
            "default": true
          },
          "seed": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2147483647
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "minItems": 1,
            "maxItems": 2,
            "description": "Mutually exclusive with reference_* arrays. 1 URL = First-Frame; 2 URLs = First+Last Keyframes."
          },
          "reference_images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 10
          },
          "reference_videos": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 5
          },
          "reference_audios": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 5
          },
          "callback_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/videos/tasks": {
      "post": {
        "operationId": "createMagi2VideoTask",
        "summary": "Create an asynchronous MAGI-2 video generation task",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "24-hour idempotency token preventing duplicate charges."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Magi2CreateTaskRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Task accepted; poll GET /v1/tasks/{task_id}."
          },
          "400": {
            "description": "Malformed JSON or missing required field."
          },
          "401": {
            "description": "Invalid or missing Bearer key."
          },
          "402": {
            "description": "Insufficient credit balance."
          },
          "422": {
            "description": "Schema violation (e.g., images + reference_* conflict or aspect_ratio sent with images)."
          },
          "429": {
            "description": "Rate limit exceeded."
          }
        }
      }
    },
    "/v1/tasks/{task_id}": {
      "get": {
        "operationId": "getVideoTaskStatus",
        "summary": "Poll status and download URL of a video generation task",
        "parameters": [
          {
            "name": "task_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current task state (queued, processing, succeeded, failed) and output URL."
          },
          "404": {
            "description": "Task not found."
          }
        }
      }
    },
    "/v1/files": {
      "post": {
        "operationId": "uploadReferenceFile",
        "summary": "Upload local reference image/audio (<=50 MB) or video (<=100 MB) to public HTTPS URL",
        "responses": {
          "201": {
            "description": "Hosted reference URL returned."
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getApiUsage",
        "summary": "Fetch API usage metrics across 24h, 7d, 30d, or all periods",
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Credit usage breakdown."
          }
        }
      }
    }
  }
}