{
  "openapi": "3.1.0",
  "info": {
    "title": "CognitionDesk API",
    "version": "3.0.0",
    "description": "Multi-tenant AI orchestration platform — AI agents, RAG, WhatsApp, social media, and billing.",
    "contact": { "name": "CognitionDesk", "url": "https://cognitiondesk.com", "email": "hello@cognitiondesk.com" },
    "license": { "name": "Proprietary" }
  },
  "servers": [
    { "url": "https://api.cognitiondesk.com", "description": "Production" }
  ],
  "components": {
    "securitySchemes": {
      "FirebaseToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Firebase ID Token",
        "description": "Firebase ID Token obtained with getIdToken() from Firebase Auth client SDK."
      },
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "API key generated via POST /apikeys/generate-api-key. Cached 10 min."
      }
    }
  },
  "paths": {
    "/health": { "get": { "summary": "Basic health check", "tags": ["Health"], "responses": { "200": { "description": "OK" } } } },
    "/health/status": { "get": { "summary": "Detailed server status", "tags": ["Health"], "responses": { "200": { "description": "OK" } } } },
    "/apikeys/generate-api-key": {
      "post": {
        "summary": "Generate API key",
        "tags": ["API Keys"],
        "security": [{ "FirebaseToken": [] }],
        "responses": { "200": { "description": "API key generated" } }
      }
    },
    "/chat-apiKeyAuth/chat": {
      "post": {
        "summary": "Send a chat message (complete response)",
        "tags": ["Chat"],
        "security": [{ "ApiKey": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["message", "assistantId"],
                "properties": {
                  "message": { "type": "string" },
                  "assistantId": { "type": "string" },
                  "threadId": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Chat response" } }
      }
    },
    "/chat-apiKeyAuth/stream": {
      "post": {
        "summary": "Stream a chat response (SSE)",
        "tags": ["Chat"],
        "security": [{ "ApiKey": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["message", "assistantId"],
                "properties": {
                  "message": { "type": "string" },
                  "assistantId": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "SSE stream" } }
      }
    },
    "/knowledge-base/search": {
      "post": {
        "summary": "Semantic search in knowledge base",
        "tags": ["Knowledge Base"],
        "security": [{ "FirebaseToken": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["query"],
                "properties": {
                  "query": { "type": "string" },
                  "limit": { "type": "integer", "default": 5 },
                  "threshold": { "type": "number", "default": 0.7 }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Search results" } }
      }
    },
    "/knowledge-base/ingest/url": {
      "post": {
        "summary": "Ingest content from URLs",
        "tags": ["Knowledge Base"],
        "security": [{ "FirebaseToken": [] }],
        "responses": { "200": { "description": "Ingestion started" } }
      }
    },
    "/billing/status": {
      "get": {
        "summary": "Get billing status and token usage",
        "tags": ["Billing"],
        "security": [{ "FirebaseToken": [] }],
        "responses": { "200": { "description": "Billing status" } }
      }
    },
    "/billing/checkout": {
      "post": {
        "summary": "Create checkout for plan upgrade",
        "tags": ["Billing"],
        "security": [{ "FirebaseToken": [] }],
        "responses": { "200": { "description": "Checkout URL" } }
      }
    }
  },
  "tags": [
    { "name": "Health", "description": "Public health and diagnostic endpoints" },
    { "name": "API Keys", "description": "API key management" },
    { "name": "Chat", "description": "AI chat with complete and streaming responses" },
    { "name": "Knowledge Base", "description": "RAG knowledge base ingestion and search" },
    { "name": "Billing", "description": "Subscription and token management" },
    { "name": "Assistants", "description": "AI assistant configuration" },
    { "name": "Workflows", "description": "LangGraph workflow management" },
    { "name": "Messaging", "description": "Messaging platform integrations" }
  ]
}
