{
  "openapi": "3.1.0",
  "info": {
    "title": "AI Chili (AIChili) Video Generation & Studio REST API",
    "version": "1.0.0",
    "summary": "Self-serve pay-as-you-go AI video generation, dry-run credit planning, and model registry API.",
    "description": "Official OpenAPI 3.1 specification for AI Chili (AIChili). Supports zero-cost dry-run credit quoting via POST /generations/plan, 5 production video and talking-avatar models (h3-vdn, wan3.0-video, seedance-2.5, minimax-h3-gmi, avatar-talk), non-expiring credit wallets, and structured JSON errors. Rate limits: 120 read requests/min and 30 generation submissions/min per API key; throttled responses return HTTP 429 with a Retry-After header.",
    "termsOfService": "https://aichili.ai/terms.html",
    "contact": {
      "name": "AI Chili Inc.",
      "url": "https://aichili.ai/developers",
      "email": "sales@aichili.ai"
    },
    "license": {
      "name": "Proprietary SaaS API (MIT CLI/MCP SDK)",
      "url": "https://aichili.ai/terms.html"
    }
  },
  "servers": [
    {
      "url": "https://aichili.ai/api/v1",
      "description": "Primary first-party JSON API gateway on aichili.ai"
    },
    {
      "url": "https://videoapi.aichili.ai/v1",
      "description": "Direct production control-plane API"
    }
  ],
  "paths": {
    "/registry": {
      "get": {
        "operationId": "listVideoModels",
        "summary": "List available AI video and talking-avatar models",
        "description": "Returns all enabled public models, workflows, supported resolutions, aspect ratios, single-call duration limits, and credit pricing rules. Requires no authentication.",
        "parameters": [
          {
            "name": "scope",
            "in": "query",
            "required": false,
            "description": "Optional registry scope ('available' default for public API models, or 'console' for full catalog).",
            "schema": {
              "type": "string",
              "enum": [
                "available",
                "console"
              ],
              "default": "available"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Active model registry and parameter constraints.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegistryResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimitedError"
          }
        }
      }
    },
    "/credits": {
      "get": {
        "operationId": "getCreditBalance",
        "summary": "Get current non-expiring credit wallet balance",
        "description": "Returns the authenticated account's spendable non-expiring credit balance, plan tier, and PAYG duration unlock state.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current wallet credit balance and tier limits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditBalanceResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          }
        }
      }
    },
    "/generations/plan": {
      "post": {
        "operationId": "planVideoGeneration",
        "summary": "Dry-run validate parameters and quote exact total_credits",
        "description": "Validates model_id, mode, workflow, duration_s, resolution, aspect ratio, and reference assets, returning exact total_credits and segment breakdown at zero cost without starting a GPU render. Always call before createVideoGeneration.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerationCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validated generation plan and exact total_credits quote.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationPlanResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/generations": {
      "post": {
        "operationId": "createVideoGeneration",
        "summary": "Submit an AI video or talking-avatar generation job",
        "description": "Deducts quoted total_credits and enqueues a generation job. Pass idempotency_key in the JSON body (or Idempotency-Key header on /api/v1) so network retries never double-charge. Failed jobs automatically refund 100% of credits.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional header bridged automatically into body.idempotency_key by the aichili.ai/api/v1 gateway.",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerationCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created generation job record.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationJobResponse"
                }
              }
            }
          },
          "200": {
            "description": "Existing generation job returned on idempotent replay.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationJobResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitedError"
          }
        }
      }
    },
    "/generations/{jobId}": {
      "get": {
        "operationId": "getVideoGeneration",
        "summary": "Get status and output asset of a generation job",
        "description": "Polls current lifecycle state ('queued', 'running', 'succeeded', 'failed', 'canceled'), credits_cost, and output_asset for a submitted job.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "description": "UUID identifier returned by createVideoGeneration.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current job state and rendered output asset when succeeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationJobResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "chili_sk_*",
        "description": "Self-serve API key prefixed with chili_sk_, created in Account Settings at https://videoplatform.aichili.ai."
      }
    },
    "responses": {
      "UnauthorizedError": {
        "description": "Missing or invalid chili_sk_* Bearer token.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Requested resource or endpoint was not found.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ValidationError": {
        "description": "Invalid model parameter, duration tier cap, or request payload.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimitedError": {
        "description": "Rate limit exceeded; honor Retry-After response header.",
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before retrying.",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "RegistryResponse": {
        "type": "object",
        "required": [
          "models",
          "max_prompt_chars"
        ],
        "properties": {
          "max_prompt_chars": {
            "type": "integer",
            "example": 20000
          },
          "models": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "model_id",
                "display_name",
                "enabled"
              ],
              "properties": {
                "model_id": {
                  "type": "string",
                  "enum": [
                    "h3-vdn",
                    "wan3.0-video",
                    "seedance-2.5",
                    "minimax-h3-gmi",
                    "avatar-talk"
                  ]
                },
                "display_name": {
                  "type": "string"
                },
                "enabled": {
                  "type": "boolean"
                },
                "single_call_durations_min": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "single_call_durations_max": {
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "CreditBalanceResponse": {
        "type": "object",
        "required": [
          "balance",
          "plan",
          "payg_unlocked"
        ],
        "properties": {
          "balance": {
            "type": "number",
            "description": "Spendable non-expiring credits (1 credit = 1s of 768p on h3-vdn).",
            "example": 460
          },
          "daily_grant_amount": {
            "type": "number",
            "example": 0
          },
          "granted_today": {
            "type": "boolean",
            "example": false
          },
          "green_balance": {
            "type": "number",
            "example": 460
          },
          "plan": {
            "type": "string",
            "example": "payg"
          },
          "max_duration_s": {
            "type": [
              "integer",
              "null"
            ],
            "example": 30
          },
          "payg_unlocked": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "GenerationParams": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 20000,
            "description": "Scene, camera motion, lighting, or spoken avatar script."
          },
          "duration_s": {
            "type": "integer",
            "minimum": 2,
            "maximum": 300,
            "default": 15,
            "description": "Target duration in seconds (5-15 on h3-vdn, 2-30 on wan3.0-video, 3-300 on avatar-talk)."
          },
          "resolution": {
            "type": "string",
            "example": "768p",
            "description": "Output resolution supported by the chosen model (e.g. 480p, 768p, 1080p, 2k, source)."
          },
          "ratio": {
            "type": "string",
            "enum": [
              "16:9",
              "9:16",
              "1:1",
              "4:3",
              "3:4",
              "21:9",
              "adaptive"
            ],
            "default": "16:9"
          },
          "ref_asset_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Optional uploaded reference image/video UUIDs for i2v."
          },
          "ref_roles": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "reference_image",
                "reference_video",
                "first_frame",
                "last_frame"
              ]
            }
          }
        }
      },
      "GenerationCreateRequest": {
        "type": "object",
        "required": [
          "mode",
          "model_id",
          "params"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "t2v",
              "i2v"
            ],
            "description": "Generation mode: text-to-video (t2v) or image/reference-to-video (i2v)."
          },
          "model_id": {
            "type": "string",
            "enum": [
              "h3-vdn",
              "wan3.0-video",
              "seedance-2.5",
              "minimax-h3-gmi",
              "avatar-talk"
            ],
            "description": "Production engine identifier."
          },
          "workflow": {
            "type": "string",
            "description": "Optional model workflow selector ('general', 'reference', 'photo', 'talk')."
          },
          "idempotency_key": {
            "type": "string",
            "maxLength": 128,
            "description": "Unique client key preventing duplicate job charges on retries."
          },
          "params": {
            "$ref": "#/components/schemas/GenerationParams"
          }
        }
      },
      "GenerationPlanResponse": {
        "type": "object",
        "required": [
          "total_credits",
          "total_duration_s",
          "segments"
        ],
        "properties": {
          "total_credits": {
            "type": "integer",
            "description": "Exact whole credits that will be deducted if submitted.",
            "example": 15
          },
          "total_duration_s": {
            "type": "integer",
            "example": 15
          },
          "segments": {
            "type": "integer",
            "example": 1
          },
          "segment_durations": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "example": [
              15
            ]
          },
          "upscale_credits": {
            "type": "integer",
            "example": 0
          },
          "estimated": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "GenerationJobResponse": {
        "type": "object",
        "required": [
          "id",
          "status",
          "credits_cost"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed",
              "canceled"
            ]
          },
          "credits_cost": {
            "type": "integer",
            "example": 15
          },
          "output_asset_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "output_asset": {
            "type": [
              "object",
              "null"
            ],
            "description": "Signed playback/download URLs and dimensions when succeeded."
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "error_message": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "resolution_hint"
            ],
            "properties": {
              "code": {
                "type": "string",
                "example": "missing_or_invalid_api_key"
              },
              "message": {
                "type": "string",
                "example": "Bearer chili_sk_* token is required for this endpoint."
              },
              "resolution_hint": {
                "type": "string",
                "example": "Create an API key at https://videoplatform.aichili.ai or call GET /api/v1/registry for public model metadata."
              }
            }
          },
          "detail": {
            "description": "Optional upstream diagnostic detail."
          }
        }
      }
    }
  }
}
