{
  "openapi": "3.1.0",
  "info": {
    "title": "H3Gen API",
    "version": "1.0.0",
    "description": "Generate MiniMax H3 videos and H3-Image 4K images with your H3Gen credits. Create a key at https://h3gen.io/settings/apikeys. Generation needs a credit pack or subscription. Generation is asynchronous: start a task, then poll GET /api/v1/tasks/{id}. Failed tasks are refunded automatically. H3Gen is an independent service and is not affiliated with MiniMax.",
    "contact": {
      "email": "support@h3gen.io",
      "url": "https://h3gen.io"
    }
  },
  "servers": [
    {
      "url": "https://h3gen.io"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "H3Gen API key (sk_…)"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "unauthorized",
                  "payment_required",
                  "insufficient_credits",
                  "not_found",
                  "rate_limited",
                  "unavailable",
                  "internal_error"
                ]
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        }
      },
      "VideoRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string",
            "maxLength": 5000,
            "description": "Subject, action, camera move, lighting and sound."
          },
          "resolution": {
            "type": "string",
            "enum": [
              "480p",
              "768p",
              "1080p",
              "2k"
            ],
            "default": "2k"
          },
          "duration": {
            "type": "integer",
            "minimum": 4,
            "maximum": 30,
            "default": 5,
            "description": "2k allows up to 15 s. Clips above 15 s cost 2x."
          },
          "ratio": {
            "type": "string",
            "enum": [
              "16:9",
              "9:16",
              "1:1",
              "4:3",
              "3:4",
              "21:9"
            ],
            "description": "Text and reference mode; ignored with a first frame."
          },
          "image": {
            "type": "string",
            "format": "uri",
            "description": "First frame (from /api/v1/uploads)."
          },
          "image_end": {
            "type": "string",
            "format": "uri",
            "description": "Last frame; needs image."
          },
          "ref_images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 9,
            "description": "Images beyond 5 cost 1 credit each."
          },
          "ref_videos": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 3,
            "description": "2-15 s each, 15 s total; their seconds are billed. Not with frames."
          },
          "ref_audios": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 3,
            "description": "Not with frames."
          },
          "count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 4,
            "default": 1,
            "description": "Videos to make; each is a task and a charge."
          },
          "prompt_optimizer": {
            "type": "boolean",
            "default": false,
            "description": "+1 credit."
          },
          "max_credits": {
            "type": "number",
            "description": "Refuse instead of charging above this."
          },
          "image_task_id": {
            "type": "string",
            "description": "Use a finished image task of this account as the first frame."
          },
          "client_request_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,128}$",
            "description": "Optional unique id. Retrying with the same id within 24 hours returns the original tasks (replayed: true) instead of charging again. Same as the Idempotency-Key header."
          }
        }
      },
      "ImageRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string",
            "maxLength": 2000
          },
          "resolution": {
            "type": "string",
            "enum": [
              "1k",
              "2k",
              "4k"
            ],
            "default": "2k"
          },
          "ratio": {
            "type": "string",
            "enum": [
              "1:1",
              "16:9",
              "9:16",
              "4:3",
              "3:4",
              "3:2",
              "2:3",
              "21:9"
            ],
            "default": "16:9"
          },
          "ref_images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 3
          },
          "max_credits": {
            "type": "number"
          },
          "client_request_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,128}$",
            "description": "Optional unique id. Retrying with the same id within 24 hours returns the original tasks (replayed: true) instead of charging again. Same as the Idempotency-Key header."
          }
        }
      },
      "Created": {
        "type": "object",
        "properties": {
          "tasks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "video",
                    "image"
                  ]
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "processing"
                  ]
                }
              }
            }
          },
          "credits_charged": {
            "type": "integer"
          },
          "replayed": {
            "type": "boolean"
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "video",
              "image"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "succeeded",
              "failed"
            ]
          },
          "prompt": {
            "type": "string"
          },
          "credits": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "progress": {
            "type": "number"
          },
          "output": {
            "type": "object",
            "description": "Present when succeeded. Links are valid for 24 hours; fetch the task again for fresh ones.",
            "properties": {
              "url": {
                "type": "string",
                "format": "uri"
              },
              "download_url": {
                "type": "string",
                "format": "uri"
              },
              "expires_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "TIMEOUT",
                  "FAILED"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Upload": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "type": {
            "type": "string",
            "enum": [
              "image",
              "video",
              "audio"
            ]
          },
          "bytes": {
            "type": "integer"
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "Models, limits and credit prices",
        "security": [],
        "responses": {
          "200": {
            "description": "Capabilities",
            "content": {
              "application/json": {}
            }
          }
        }
      }
    },
    "/api/v1/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Credit balance and API access",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "credits": {
                      "type": "integer"
                    },
                    "api_access": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/estimate": {
      "post": {
        "operationId": "estimateCost",
        "summary": "Credits a request would cost",
        "description": "Send a video request, or an image request with \"type\": \"image\".",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "video",
                          "image"
                        ],
                        "default": "video"
                      }
                    }
                  },
                  {
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/VideoRequest"
                      },
                      {
                        "$ref": "#/components/schemas/ImageRequest"
                      }
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Estimate",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "credits": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/uploads": {
      "post": {
        "operationId": "uploadMedia",
        "summary": "Upload or import a frame / reference file",
        "description": "PNG, JPEG, WebP ≤ 20 MB; MP4/MOV ≤ 30 MB and 2-15 s; MP3/WAV ≤ 15 MB. Multipart with one \"file\", or JSON {\"url\": \"https://…\"} to import a public file.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                },
                "required": [
                  "file"
                ]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  }
                },
                "required": [
                  "url"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "411": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/videos": {
      "post": {
        "operationId": "createVideo",
        "summary": "Start MiniMax H3 video generation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VideoRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Started",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Created"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Same as client_request_id."
          }
        ]
      }
    },
    "/api/v1/images": {
      "post": {
        "operationId": "createImage",
        "summary": "Start H3-Image 4K generation or editing",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Started",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Created"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Same as client_request_id."
          }
        ]
      }
    },
    "/api/v1/tasks": {
      "get": {
        "operationId": "listTasks",
        "summary": "Recent tasks",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tasks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Task"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}": {
      "get": {
        "operationId": "getTask",
        "summary": "Task status and result",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "wait",
            "in": "query",
            "description": "Hold up to this many seconds (≤ 25) for completion.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  }
}
