{
 "openapi": "3.0.3",
 "info": {
  "title": "Mooniris API",
  "version": "1.0",
  "description": "Dub talking-head videos into another language from your own product.\n\nBilling: API jobs use the same seconds balance as the Mooniris studio. A job uses 1 second of balance per second of video (rounded up to a whole second) for each target language. Voice cloning and lip-sync are included. There is no separate API charge. A failed or cancelled job returns its seconds.\n\nAuthentication: create a key in Studio \u203a Settings \u203a API keys and send it as `Authorization: Bearer <key>` or `X-Api-Key: <key>` (the X-Api-Key header works on /v1/developer/* routes; use the Authorization header for /v1/webhooks).",
  "contact": {
   "email": "support@mooniris.com",
   "url": "https://mooniris.com/developers/"
  }
 },
 "servers": [
  {
   "url": "https://api.mooniris.com"
  }
 ],
 "security": [
  {
   "bearer": []
  },
  {
   "apiKey": []
  }
 ],
 "paths": {
  "/v1/developer/quotes": {
   "post": {
    "summary": "Check how many seconds a job will use",
    "operationId": "quote",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "mode",
         "durationMs"
        ],
        "properties": {
         "mode": {
          "type": "string",
          "enum": [
           "dub",
           "lip_sync"
          ]
         },
         "durationMs": {
          "type": "integer",
          "minimum": 1,
          "description": "Video length in milliseconds"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Seconds needed and seconds available",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Quote"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Rate limit: 60 requests each 60 seconds per key",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/developer/jobs": {
   "post": {
    "summary": "Create a dubbing job",
    "operationId": "createJob",
    "description": "The job starts right away and holds the seconds it needs. Repeat the call once per target language.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/CreateJob"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The new job",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Job"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "402": {
      "description": "Not enough seconds in the balance (shortfallMs says how many are missing)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Rate limit: 60 requests each 60 seconds per key",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/developer/jobs/{id}": {
   "get": {
    "summary": "Read a job's status, step and progress",
    "operationId": "getJob",
    "parameters": [
     {
      "$ref": "#/components/parameters/JobId"
     }
    ],
    "responses": {
     "200": {
      "description": "The job",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Job"
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/developer/jobs/{id}/cancel": {
   "post": {
    "summary": "Cancel a running job",
    "operationId": "cancelJob",
    "description": "The seconds held for the job return to your balance.",
    "parameters": [
     {
      "$ref": "#/components/parameters/JobId"
     }
    ],
    "responses": {
     "200": {
      "description": "Cancelled",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string"
          },
          "status": {
           "type": "string",
           "enum": [
            "cancelled"
           ]
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/developer/jobs/{id}/result": {
   "get": {
    "summary": "Get the finished video",
    "operationId": "getResult",
    "parameters": [
     {
      "$ref": "#/components/parameters/JobId"
     }
    ],
    "responses": {
     "200": {
      "description": "Result links",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "projectId": {
           "type": "string"
          },
          "url": {
           "type": "string"
          },
          "downloadUrl": {
           "type": "string",
           "nullable": true
          },
          "beforeUrl": {
           "type": "string",
           "nullable": true
          },
          "durationMs": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "The render is not ready yet",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/webhooks": {
   "get": {
    "summary": "List webhook endpoints",
    "operationId": "listWebhooks",
    "responses": {
     "200": {
      "description": "Endpoints",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhooks": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Webhook"
           }
          }
         }
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add a webhook endpoint",
    "operationId": "createWebhook",
    "description": "Mooniris POSTs JSON `{event, createdAt, data}` to your URL when a job finishes. Each request carries `X-Mooniris-Event` and `X-Mooniris-Signature`, the hex HMAC-SHA256 of the raw body using the endpoint secret.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "url"
        ],
        "properties": {
         "url": {
          "type": "string",
          "description": "Public HTTPS URL"
         },
         "events": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "default": [
           "job.completed",
           "job.failed"
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The endpoint and its signing secret (shown once)",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Webhook"
          },
          {
           "type": "object",
           "properties": {
            "secret": {
             "type": "string"
            }
           }
          }
         ]
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/webhooks/{id}": {
   "delete": {
    "summary": "Remove a webhook endpoint",
    "operationId": "deleteWebhook",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "204": {
      "description": "Removed"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer"
   },
   "apiKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key"
   }
  },
  "parameters": {
   "JobId": {
    "name": "id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string"
    }
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string"
     },
     "message": {
      "type": "string"
     },
     "shortfallMs": {
      "type": "integer"
     }
    }
   },
   "Quote": {
    "type": "object",
    "properties": {
     "durationMs": {
      "type": "integer"
     },
     "billedSeconds": {
      "type": "integer",
      "description": "Seconds this job uses, per target language"
     },
     "creditMsRequired": {
      "type": "integer"
     },
     "creditMsAvailable": {
      "type": "integer"
     },
     "affordable": {
      "type": "boolean"
     },
     "shortfallMs": {
      "type": "integer"
     },
     "creditHoldMs": {
      "type": "integer",
      "description": "Seconds held when the job starts, in milliseconds"
     },
     "mode": {
      "type": "string"
     }
    }
   },
   "CreateJob": {
    "type": "object",
    "required": [
     "title",
     "mode",
     "sourceLanguage",
     "targetLanguage",
     "durationMs",
     "consent",
     "videoUrl"
    ],
    "properties": {
     "title": {
      "type": "string",
      "maxLength": 120
     },
     "mode": {
      "type": "string",
      "enum": [
       "dub"
      ],
      "description": "dub: translate the speech, clone the speaker's voice and lip-sync the result"
     },
     "sourceLanguage": {
      "type": "string",
      "description": "Language code of the speech in the video, e.g. en or en-US"
     },
     "targetLanguage": {
      "type": "string",
      "description": "Language code to dub into, e.g. hi or es-ES"
     },
     "durationMs": {
      "type": "integer",
      "minimum": 1,
      "description": "Video length in milliseconds. This is what the job is billed on."
     },
     "videoUrl": {
      "type": "string",
      "description": "Public HTTPS URL of the source video"
     },
     "consent": {
      "type": "boolean",
      "enum": [
       true
      ],
      "description": "Confirms you have permission from the people whose face and voice appear in the video"
     },
     "keepMusic": {
      "type": "boolean",
      "default": true
     },
     "style": {
      "type": "string",
      "enum": [
       "casual",
       "formal"
      ],
      "default": "casual"
     }
    }
   },
   "Job": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "mode": {
      "type": "string"
     },
     "sourceLanguage": {
      "type": "string"
     },
     "targetLanguage": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "draft",
       "scripting",
       "queued",
       "processing",
       "completed",
       "failed",
       "cancelled"
      ]
     },
     "step": {
      "type": "string",
      "nullable": true
     },
     "progress": {
      "type": "number"
     },
     "durationMs": {
      "type": "integer"
     },
     "chargedMs": {
      "type": "integer",
      "description": "Seconds held or used, in milliseconds"
     },
     "trial": {
      "type": "boolean"
     },
     "watermark": {
      "type": "boolean"
     },
     "errorMessage": {
      "type": "string",
      "nullable": true
     },
     "etaSeconds": {
      "type": "integer",
      "nullable": true
     },
     "resultUrl": {
      "type": "string",
      "nullable": true
     },
     "downloadUrl": {
      "type": "string",
      "nullable": true
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     },
     "updatedAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Webhook": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "url": {
      "type": "string"
     },
     "events": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   }
  }
 }
}