{
  "openapi": "3.0.3",
  "info": {
    "title": "CueRise API",
    "description": "CueRise is a professional AI-powered speech editor, teleprompter, audio/video recorder, and slide builder. This API allows AI assistants and third-party integrations to create, edit, and manage speeches, process AI-powered text improvements, and manage user accounts.",
    "version": "1.0.0",
    "contact": {
      "name": "SHEM LLC",
      "url": "https://qrise.ai"
    },
    "termsOfService": "https://qrise.ai/terms",
    "x-logo": {
      "url": "https://qrise.ai/CueRise_Make_Great_Speeches_For_Content_Creators.png"
    }
  },
  "servers": [
    {
      "url": "https://qrise.ai",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/api/auth/login": {
      "post": {
        "operationId": "loginUser",
        "summary": "Log in a user",
        "description": "Authenticate a user with email and password. Returns a session token for subsequent API calls.",
        "tags": ["Authentication"],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "User's email address"
                  },
                  "password": {
                    "type": "string",
                    "description": "User's password"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "user": { "$ref": "#/components/schemas/User" },
                    "sessionToken": {
                      "type": "string",
                      "description": "Bearer token for authenticated requests"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid credentials"
          }
        }
      }
    },
    "/api/auth/register": {
      "post": {
        "operationId": "registerUser",
        "summary": "Register a new user",
        "description": "Create a new CueRise account with email and password. Includes a free 7-day trial.",
        "tags": ["Authentication"],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "email", "password"],
                "properties": {
                  "name": { "type": "string", "description": "User's display name" },
                  "email": { "type": "string", "format": "email" },
                  "password": { "type": "string", "minLength": 8 }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registration successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "user": { "$ref": "#/components/schemas/User" },
                    "sessionToken": { "type": "string" }
                  }
                }
              }
            }
          },
          "400": { "description": "Validation error or email already exists" }
        }
      }
    },
    "/api/auth/logout": {
      "post": {
        "operationId": "logoutUser",
        "summary": "Log out current user",
        "description": "Invalidate the current session token.",
        "tags": ["Authentication"],
        "responses": {
          "200": { "description": "Logout successful" }
        }
      }
    },
    "/api/auth/refresh": {
      "post": {
        "operationId": "refreshUser",
        "summary": "Refresh user data",
        "description": "Get the latest user profile and subscription data for the authenticated user.",
        "tags": ["Authentication"],
        "responses": {
          "200": {
            "description": "User data refreshed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "user": { "$ref": "#/components/schemas/User" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/speech": {
      "get": {
        "operationId": "getSpeeches",
        "summary": "Get all speeches",
        "description": "Retrieve all saved speeches for the authenticated user. Speeches include title, content, and metadata.",
        "tags": ["Speeches"],
        "responses": {
          "200": {
            "description": "List of speeches",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "speeches": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Speech" }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "saveSpeech",
        "summary": "Save a speech",
        "description": "Save a new speech or update an existing one. Speeches are stored persistently and can be loaded into the teleprompter or AI editor.",
        "tags": ["Speeches"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["title", "content"],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Speech ID (omit for new speech, include to update)"
                  },
                  "title": { "type": "string", "description": "Speech title" },
                  "content": { "type": "string", "description": "Full speech text content" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Speech saved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "speech": { "$ref": "#/components/schemas/Speech" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/process": {
      "post": {
        "operationId": "processAI",
        "summary": "AI-powered speech editing",
        "description": "Submit speech text for AI-powered editing and improvement. The AI can refine tone, structure, clarity, add transitions, improve openings/conclusions, and more. Requires AI tokens (included with subscription).",
        "tags": ["AI"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["text", "action"],
                "properties": {
                  "text": { "type": "string", "description": "The speech text to process" },
                  "action": {
                    "type": "string",
                    "description": "The type of AI editing to perform",
                    "enum": [
                      "improve",
                      "shorten",
                      "expand",
                      "formalize",
                      "casualize",
                      "summarize",
                      "custom"
                    ]
                  },
                  "customPrompt": {
                    "type": "string",
                    "description": "Custom instruction for the AI (used when action is 'custom')"
                  },
                  "selectedText": {
                    "type": "string",
                    "description": "Specific portion of text to edit (optional, edits full text if omitted)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "AI processing result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "result": { "type": "string", "description": "The AI-edited text" },
                    "tokensUsed": {
                      "type": "integer",
                      "description": "Number of AI tokens consumed"
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Insufficient AI tokens" }
        }
      }
    },
    "/api/ai/estimate-cost": {
      "post": {
        "operationId": "estimateAICost",
        "summary": "Estimate AI processing cost",
        "description": "Estimate how many AI tokens a processing request will consume before submitting it.",
        "tags": ["AI"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["text"],
                "properties": {
                  "text": { "type": "string", "description": "The text to estimate cost for" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cost estimate",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "estimatedTokens": { "type": "integer" },
                    "estimatedCost": { "type": "number" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/tokens/balance/{userId}": {
      "get": {
        "operationId": "getTokenBalance",
        "summary": "Get AI token balance",
        "description": "Check the current AI token balance for the authenticated user.",
        "tags": ["AI"],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Token balance",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": { "type": "integer" },
                    "monthlyAllowance": { "type": "integer" },
                    "purchased": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/support/tickets": {
      "get": {
        "operationId": "getSupportTickets",
        "summary": "Get support tickets",
        "description": "Retrieve all support tickets for the authenticated user.",
        "tags": ["Support"],
        "responses": {
          "200": {
            "description": "List of support tickets",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "tickets": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/SupportTicket" }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createSupportTicket",
        "summary": "Create a support ticket",
        "description": "Submit a new support ticket to the CueRise team.",
        "tags": ["Support"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["subject", "message"],
                "properties": {
                  "subject": { "type": "string" },
                  "message": { "type": "string" },
                  "priority": { "type": "string", "enum": ["low", "medium", "high"] }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Ticket created successfully" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Session token obtained from the login endpoint. Pass as: Authorization: Bearer <token>"
      }
    },
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "role": { "type": "string", "enum": ["user", "admin", "superuser"] },
          "subscription_status": {
            "type": "string",
            "enum": ["active", "trialing", "canceled", "past_due", "none"]
          },
          "subscription_type": { "type": "string", "enum": ["monthly", "yearly", "none"] },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "Speech": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "title": { "type": "string" },
          "content": { "type": "string" },
          "user_id": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "SupportTicket": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "subject": { "type": "string" },
          "status": { "type": "string", "enum": ["open", "closed"] },
          "priority": { "type": "string", "enum": ["low", "medium", "high"] },
          "created_at": { "type": "string", "format": "date-time" }
        }
      }
    }
  },
  "tags": [
    { "name": "Authentication", "description": "User registration, login, and session management" },
    { "name": "Speeches", "description": "Create, read, update, and delete speeches" },
    { "name": "AI", "description": "AI-powered speech editing and text processing" },
    { "name": "Support", "description": "Customer support ticket management" }
  ]
}
