{
  "openapi": "3.1.0",
  "info": {
    "title": "Mosaic Motion",
    "version": "1.0.0",
    "description": "Create and poll Mosaic Motion video generation jobs."
  },
  "servers": [
    {
      "url": "https://api.motion.so/api/motion"
    }
  ],
  "security": [
    {
      "MotionApiKey": []
    }
  ],
  "paths": {
    "/sessions": {
      "post": {
        "summary": "Create a Mosaic Motion 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."
                  }
                },
                "withReferences": {
                  "value": {
                    "prompt": "Create a short event recap video.",
                    "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 Mosaic Motion 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 Mosaic Motion 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 Mosaic Motion 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
          },
          "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"
            }
          }
        }
      },
      "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"
          }
        }
      },
      "MotionJobStatus": {
        "type": "object",
        "required": ["job_id", "status", "created_at", "updated_at", "completed_at", "error", "pending_user_input"],
        "properties": {
          "job_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["queued", "created", "running", "awaiting_user_input", "completed", "failed"]
          },
          "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"
          }
        }
      },
      "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."
      }
    }
  }
}

