{
  "openapi": "3.0.0",
  "externalDocs": {
    "description": "MaxAI full documentation",
    "url": "https://maxai.fyi/nexus/openapi"
  },
  "info": {
    "title": "MaxAI Video API + Platform",
    "version": "3.0.0",
    "description": "Multi-model AI video generation API (OpenRouter-style) + AI video maker. POST /v1/videos routes across 15 engines with failover.",
    "contact": {
      "url": "https://maxai.fyi",
      "x-telegram": "@MaxAI_SaaS_Bot"
    }
  },
  "servers": [
    {
      "url": "https://maxai.fyi/nexus",
      "description": "Production"
    }
  ],
  "paths": {
    "/register": {
      "post": {
        "summary": "Register new client, get API key",
        "operationId": "register",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "name"
                ],
                "properties": {
                  "email": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "plan": {
                    "type": "string",
                    "enum": [
                      "starter",
                      "professional",
                      "business",
                      "enterprise"
                    ]
                  },
                  "telegram_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Client registered with API key"
          }
        }
      }
    },
    "/agents": {
      "get": {
        "summary": "List all 27 AI agents",
        "operationId": "listAgents",
        "responses": {
          "200": {
            "description": "Array of agent objects"
          }
        }
      }
    },
    "/tasks": {
      "post": {
        "summary": "Submit task to an agent",
        "operationId": "createTask",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "agent_type",
                  "task"
                ],
                "properties": {
                  "agent_type": {
                    "type": "string",
                    "enum": [
                      "coder",
                      "trader",
                      "hunter",
                      "parser",
                      "analyst",
                      "marketer",
                      "researcher",
                      "automator",
                      "designer",
                      "support",
                      "presenter",
                      "onec",
                      "legal",
                      "hr",
                      "finance"
                    ]
                  },
                  "task": {
                    "type": "string",
                    "maxLength": 10000
                  },
                  "priority": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Job ID returned, poll /tasks/{id} for result"
          }
        }
      },
      "get": {
        "summary": "List client tasks",
        "operationId": "listTasks",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of task objects"
          }
        }
      }
    },
    "/tasks/{job_id}": {
      "get": {
        "summary": "Get task result",
        "operationId": "getTask",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task with status and result"
          }
        }
      }
    },
    "/demo": {
      "post": {
        "summary": "Free demo \u2014 3 tasks/hour, no registration",
        "operationId": "runDemo",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "task": {
                    "type": "string"
                  },
                  "agent_type": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task result or job_id"
          }
        }
      }
    },
    "/workflows": {
      "get": {
        "summary": "List 7 agent workflow chains",
        "operationId": "listWorkflows",
        "responses": {
          "200": {
            "description": "Available A2A workflows"
          }
        }
      }
    },
    "/workflows/run": {
      "post": {
        "summary": "Run a multi-agent workflow chain",
        "operationId": "runWorkflow",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workflow_id",
                  "input"
                ],
                "properties": {
                  "workflow_id": {
                    "type": "string"
                  },
                  "input": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workflow job started"
          }
        }
      }
    },
    "/status": {
      "get": {
        "summary": "Public system status",
        "operationId": "getStatus",
        "responses": {
          "200": {
            "description": "System status + agent count"
          }
        }
      }
    },
    "/plans": {
      "get": {
        "summary": "Get pricing plans",
        "operationId": "getPlans",
        "responses": {
          "200": {
            "description": "Free $0, Starter $19, Professional $49, Custom"
          }
        }
      }
    },
    "/invoice/{client_id}": {
      "get": {
        "summary": "Generate invoice for client",
        "operationId": "getInvoice",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "client_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Invoice with payment details"
          }
        }
      }
    },
    "/affiliate/register": {
      "post": {
        "summary": "Register as affiliate, earn 20% commission",
        "operationId": "registerAffiliate",
        "responses": {
          "200": {
            "description": "Affiliate ID + referral link"
          }
        }
      }
    },
    "/enterprise/contact": {
      "post": {
        "summary": "Enterprise lead capture",
        "operationId": "enterpriseContact",
        "responses": {
          "200": {
            "description": "Lead received, team contacts within 2h"
          }
        }
      }
    },
    "/stream/{job_id}": {
      "get": {
        "summary": "Server-Sent Events stream for real-time results",
        "operationId": "streamResult",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "SSE stream with chunks"
          }
        }
      }
    },
    "/pricing": {
      "get": {
        "summary": "Get pricing plans",
        "operationId": "getPricing",
        "responses": {
          "200": {
            "description": "4 plans with features"
          }
        }
      }
    },
    "/analytics": {
      "get": {
        "summary": "Platform analytics (admin)",
        "operationId": "getAnalytics",
        "security": [
          {
            "AdminToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks, clients, revenue stats"
          }
        }
      }
    },
    "/market-status": {
      "get": {
        "summary": "Live crypto market data + bot status",
        "operationId": "getMarketStatus",
        "responses": {
          "200": {
            "description": "BTC/ETH/SOL prices + V4 bot status"
          }
        }
      }
    },
    "/ai/public": {
      "post": {
        "summary": "Instant AI chat (no auth - for chat widget)",
        "operationId": "publicAI",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Instant rule-based AI response"
          }
        }
      }
    },
    "/webhook/payment": {
      "post": {
        "summary": "Payment webhook - record received payment",
        "operationId": "paymentWebhook",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  },
                  "tx_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment recorded + TG notification"
          }
        }
      }
    },
    "/api/v1/guest/preview": {
      "post": {
        "summary": "Anonymous watermarked video preview (no auth, rate-limited)",
        "operationId": "guestPreview",
        "tags": [
          "guest"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 160
                  },
                  "platform": {
                    "type": "string",
                    "default": "tiktok"
                  }
                },
                "required": [
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Watermarked preview rendered (preview_url, signup_url)"
          },
          "429": {
            "description": "Rate limited \u2014 1/IP/6h or daily cap reached"
          }
        }
      }
    },
    "/v1/videos": {
      "post": {
        "operationId": "createVideo",
        "summary": "Generate a video (multi-engine, auto-routed).",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "Routing tier (eco/standard/premium/flagship) or engine id",
                    "default": "standard"
                  },
                  "prompt": {
                    "type": "string"
                  },
                  "duration": {
                    "type": "number",
                    "default": 6
                  },
                  "resolution": {
                    "type": "string",
                    "default": "720p"
                  },
                  "aspect_ratio": {
                    "type": "string",
                    "default": "9:16"
                  },
                  "image_url": {
                    "type": "string",
                    "description": "Optional: image-to-video first frame"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Job created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    },
                    "poll_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/videos/{id}": {
      "get": {
        "operationId": "getVideo",
        "summary": "Poll a video job; returns MP4 url when ready.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/videos/models": {
      "get": {
        "operationId": "listVideoModels",
        "summary": "List video engines and routing tiers.",
        "responses": {
          "200": {
            "description": "Model list"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}