{
  "openapi": "3.1.0",
  "info": {
    "title": "Mosaic Motion",
    "version": "1.0.0",
    "description": "Create and poll durable Rio Motion-agent video generation jobs."
  },
  "servers": [
    {
      "url": "https://api.motion.so/api/motion"
    }
  ],
  "security": [
    {
      "MotionApiKey": []
    }
  ],
  "paths": {
    "/sessions": {
      "post": {
        "summary": "Create a Rio Motion-agent job",
        "operationId": "createMotionSession",
        "security": [
          {
            "MotionApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMotionSessionRequest"
              },
              "examples": {
                "basic": {
                  "value": {
                    "prompt": "Create a 15 second product launch video for a new AI calendar app.",
                    "aspect_ratio": "16:9",
                    "duration": "10-30s",
                    "design_system_id": "stripe"
                  }
                },
                "withReferences": {
                  "value": {
                    "prompt": "Create a short event recap video.",
                    "aspect_ratio": "9:16",
                    "duration": "30s-1min",
                    "design_md": {
                      "filename": "DESIGN.md",
                      "content": "# Design System\n\nUse a dark editorial canvas, crisp white type, and cobalt accent lines.",
                      "jsonFilename": "style-extraction.json",
                      "jsonContent": "{\"taste_dna\":{\"mood\":\"editorial precision\"}}"
                    },
                    "style_reference_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
                    "attachments": [
                      {
                        "url": "https://storage.example.com/signed/hero-image.png",
                        "name": "Hero image",
                        "type": "image",
                        "content_type": "image/png"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateMotionSessionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Mosaic Motion API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient Mosaic Motion credits. Purchase credits or configure auto top-ups in the Motion frontend at https://motion.so.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InsufficientCreditsError"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{job_id}/followups": {
      "post": {
        "summary": "Create a followup for a completed Rio Motion-agent job",
        "operationId": "createMotionSessionFollowup",
        "security": [
          {
            "MotionApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Completed job ID returned by POST /sessions."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMotionSessionRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Followup accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateMotionSessionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Mosaic Motion API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Job not found or not owned by API key user",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Followups are only allowed for completed jobs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FollowupRequiresCompletedJobError"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{job_id}": {
      "get": {
        "summary": "Get Rio Motion-agent job status",
        "operationId": "getMotionSessionStatus",
        "security": [
          {
            "MotionApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Job ID returned by POST /sessions."
          }
        ],
        "responses": {
          "200": {
            "description": "Job status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MotionJobStatus"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Mosaic Motion API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Job not found or not owned by API key user",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "MotionApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Mosaic Motion API key. Keys start with motion_."
      }
    },
    "schemas": {
      "CreateMotionSessionRequest": {
        "type": "object",
        "description": "Creates a durable Rio Motion-agent job owned by the API key user. Requires available Mosaic Motion credits on that user's account. Credits and auto top-ups are managed at https://motion.so, not through the API.",
        "required": ["prompt"],
        "additionalProperties": false,
        "properties": {
          "prompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 12000
          },
          "aspect_ratio": {
            "$ref": "#/components/schemas/MotionAspectRatio"
          },
          "duration": {
            "$ref": "#/components/schemas/MotionDurationBucket"
          },
          "design_system_id": {
            "$ref": "#/components/schemas/MotionDesignSystemId"
          },
          "design_md": {
            "description": "Pro/Max custom DESIGN.md content, optionally with a companion style extraction JSON artifact. If both design_system_id and design_md are sent, design_md content is used.",
            "anyOf": [
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 200000
              },
              {
                "$ref": "#/components/schemas/MotionDesignMd"
              }
            ]
          },
          "style_reference_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "Optional YouTube style reference URL."
          },
          "attachments": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/MotionAttachment"
            }
          }
        }
      },
      "MotionAspectRatio": {
        "type": "string",
        "enum": ["16:9", "9:16", "1:1", "4:5", "21:9"],
        "description": "Target video aspect ratio."
      },
      "MotionDurationBucket": {
        "type": "string",
        "enum": ["<10s", "10-30s", "30s-1min", "1-5min"],
        "description": "Target video duration bucket."
      },
      "MotionDesignSystemId": {
        "type": "string",
        "enum": [
          "mosaic",
          "apple",
          "claude",
          "cursor",
          "linear",
          "vercel",
          "stripe",
          "figma",
          "notion",
          "spotify",
          "supabase",
          "raycast",
          "framer",
          "resend",
          "mintlify",
          "sentry",
          "tesla",
          "nike",
          "shopify",
          "airbnb",
          "posthog"
        ],
        "description": "Pro/Max built-in DESIGN.md preset to apply."
      },
      "MotionDesignMd": {
        "type": "object",
        "required": ["content"],
        "additionalProperties": false,
        "properties": {
          "filename": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "default": "DESIGN.md"
          },
          "sourceUrl": {
            "type": "string",
            "maxLength": 2048,
            "description": "Optional source website URL for imported style extraction context."
          },
          "content": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200000,
            "description": "Pro/Max markdown design system guidance saved as DESIGN.md for the job."
          },
          "jsonFilename": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "default": "style-extraction.json",
            "description": "Optional companion style extraction JSON filename."
          },
          "jsonContent": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200000,
            "description": "Optional structured style extraction JSON saved alongside DESIGN.md for agent context."
          }
        }
      },
      "MotionAttachment": {
        "type": "object",
        "required": ["url"],
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 4096,
            "description": "Publicly accessible signed URL."
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 240
          },
          "type": {
            "type": "string",
            "enum": ["image", "video", "audio", "file"]
          },
          "content_type": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          }
        }
      },
      "CreateMotionSessionResponse": {
        "type": "object",
        "required": ["job_id", "status", "status_url"],
        "properties": {
          "job_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["queued"]
          },
          "status_url": {
            "type": "string",
            "format": "uri",
            "description": "Authenticated public API polling URL for GET /sessions/{job_id}. This is not a Motion app page."
          },
          "chat_url": {
            "type": ["string", "null"],
            "format": "uri",
            "description": "Motion app chat URL for a human to open, inspect, or continue the run. Null only for legacy flows where no chat is available."
          }
        }
      },
      "MotionJobStatus": {
        "type": "object",
        "required": ["job_id", "status", "created_at", "updated_at", "completed_at", "error", "pending_user_input", "output"],
        "properties": {
          "job_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["queued", "created", "running", "awaiting_user_input", "completed", "failed"]
          },
          "chat_url": {
            "type": ["string", "null"],
            "format": "uri",
            "description": "Motion app chat URL for a human to open, inspect, or continue the run. Null for legacy jobs without a Motion agent chat."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "error": {
            "type": ["string", "null"]
          },
          "pending_user_input": {
            "type": "boolean"
          },
          "output": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/MotionJobOutput"
              },
              {
                "type": "null"
              }
            ],
            "description": "Download readiness state. There is no separate public output/download endpoint; poll this status response until output.status is completed and output.download_url is non-null."
          },
          "sources": {
            "type": "array",
            "description": "Additive source-asset audit list for media currently used in the composition. Empty when no source assets are recorded yet. Internal storage paths, filenames, and GCS URIs are not exposed.",
            "items": {
              "$ref": "#/components/schemas/MotionCompositionSource"
            }
          }
        }
      },
      "MotionCompositionSourceUsage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "start_seconds": {
            "type": ["number", "null"],
            "description": "Timeline start time in seconds when known."
          },
          "end_seconds": {
            "type": ["number", "null"],
            "description": "Timeline end time in seconds when known."
          },
          "duration_seconds": {
            "type": ["number", "null"],
            "description": "Timeline duration in seconds when known."
          },
          "scene_id": {
            "type": ["string", "null"]
          },
          "scene_index": {
            "type": ["number", "null"]
          },
          "slot_key": {
            "type": ["string", "null"]
          },
          "element_tag": {
            "type": ["string", "null"],
            "description": "Composition element tag such as img, video, audio, or source."
          },
          "composition_file": {
            "type": ["string", "null"]
          },
          "composition_id": {
            "type": ["string", "null"]
          },
          "track_index": {
            "type": ["number", "null"]
          }
        }
      },
      "MotionCompositionSource": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "source_kind",
          "provider",
          "provider_asset_id",
          "source_url",
          "display_url",
          "source_domain",
          "media_type",
          "title",
          "credit",
          "rights_status",
          "usages",
          "source_metadata",
          "rights_metadata"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "source_kind": {
            "type": "string",
            "enum": ["licensed_library", "article", "web_search", "web", "connector", "upload", "generated", "unknown"],
            "description": "How the asset was acquired."
          },
          "provider": {
            "type": "string",
            "description": "Provider or origin, such as getty, pexels, perplexity, github, or an article domain."
          },
          "provider_asset_id": {
            "type": ["string", "null"],
            "description": "Provider-specific asset ID when available."
          },
          "source_url": {
            "type": ["string", "null"],
            "format": "uri",
            "description": "Canonical public source URL when available."
          },
          "display_url": {
            "type": ["string", "null"],
            "format": "uri",
            "description": "Preview/display URL when available."
          },
          "source_domain": {
            "type": ["string", "null"]
          },
          "media_type": {
            "type": "string",
            "enum": ["image", "video", "audio", "file", "unknown"]
          },
          "title": {
            "type": ["string", "null"]
          },
          "credit": {
            "type": ["string", "null"]
          },
          "rights_status": {
            "type": "string",
            "enum": ["licensed", "public", "restricted", "user_provided", "generated", "unknown"],
            "description": "Best-known rights category for the source asset."
          },
          "usages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MotionCompositionSourceUsage"
            }
          },
          "source_metadata": {
            "type": "object",
            "description": "Provider/source-specific public metadata. Shape varies by source kind and provider.",
            "additionalProperties": true
          },
          "rights_metadata": {
            "type": "object",
            "description": "Provider/license-specific rights metadata. Shape varies by source kind and provider.",
            "additionalProperties": true
          }
        }
      },
      "MotionJobOutput": {
        "type": "object",
        "required": ["status", "download_url", "expires_at", "completed_at", "error"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["pending", "queued", "processing", "completed", "failed", "outdated"]
          },
          "download_url": {
            "type": ["string", "null"],
            "format": "uri",
            "description": "Signed MP4 download URL. Present only when status is completed."
          },
          "expires_at": {
            "type": ["string", "null"],
            "format": "date-time",
            "description": "Expiration timestamp for download_url."
          },
          "completed_at": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "error": {
            "type": ["string", "null"]
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string"
          },
          "details": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "InsufficientCreditsError": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string",
            "const": "insufficient_credits"
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "minimum_required_credits": {
            "type": "number"
          },
          "current_balance": {
            "type": "number"
          }
        },
        "description": "Returned when the API key owner's account does not have enough Mosaic Motion credits. Purchase credits or configure auto top-ups in the Motion frontend at https://motion.so."
      },
      "FollowupRequiresCompletedJobError": {
        "type": "object",
        "required": ["error", "message", "status"],
        "properties": {
          "error": {
            "type": "string",
            "const": "followup_requires_completed_job"
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        },
        "description": "Returned when creating a followup for a job that is not completed."
      }
    }
  }
}
