openapi: 3.0.0 info: title: AI Assistant API version: 1.0.0 description: | RAG-based policy assistant API for Caribbean government staff. ## Authentication All endpoints except `/branding` require authentication via NextAuth session cookies. ## User Roles - **admin**: Full system access - **superuser**: Manage documents/users in assigned categories - **user**: Query documents in subscribed categories contact: name: AI Assistant Support license: name: Proprietary servers: - url: https://ai.abhirup.app/api description: Production - url: http://localhost:3000/api description: Local Development tags: - name: Chat description: Send messages and receive RAG-powered responses (standard and streaming) - name: Threads description: Manage conversation threads - name: User description: User-specific endpoints - name: Admin - Categories description: Category management (admin only) - name: Admin - Documents description: Document management (admin only) - name: Admin - Users description: User management (admin only) - name: Admin - Settings description: System configuration (admin only) - name: Admin - System description: System operations (admin only) - name: Super User - Documents description: Document management for assigned categories - name: Super User - Users description: User subscription management for assigned categories - name: Super User - Categories description: Category management for superusers (view managed/subscribed, create within quota) - name: Admin - Tools description: Tool configuration management (admin only) - name: Admin - Skills description: Skills management (admin only) - name: Category Prompts description: Category-specific prompt configuration - name: Super User - Tools description: Category-level tool overrides (superuser only) - name: Admin - Data Sources description: Data source management (API and CSV) - name: Admin - Function APIs description: Function API configuration with OpenAI-format schemas - name: Branding description: Public branding endpoints - name: Admin - Agent Bots description: Agent bot management (admin/superuser) - name: Agent Bots - Public description: Agent bot invocation API (API key auth) - name: Admin - LLM description: LLM provider and model management (admin only) - name: Admin - AI & API Setup description: Consolidated organization-scoped AI providers, credentials, capabilities, membership, audit, and usage administration - name: Autonomous description: Autonomous plan control components: schemas: Thread: type: object properties: id: type: string format: uuid example: "550e8400-e29b-41d4-a716-446655440000" title: type: string example: "HR Policy Questions" createdAt: type: string format: date-time updatedAt: type: string format: date-time uploadCount: type: integer example: 1 categoryIds: type: array items: type: integer example: [1, 3] required: - id - title - createdAt - updatedAt - uploadCount - categoryIds Message: type: object properties: id: type: string example: "msg_abc123" role: type: string enum: [user, assistant] content: type: string sources: type: array items: $ref: '#/components/schemas/Source' attachments: type: array items: type: string timestamp: type: string format: date-time required: - id - role - content - timestamp Source: type: object properties: documentName: type: string example: "HR_Handbook_2024.pdf" pageNumber: type: integer example: 12 chunkText: type: string example: "Annual leave entitlement is 20 working days..." score: type: number format: float example: 0.89 isWeb: type: boolean description: True if source is from Tavily web search Document: type: object properties: id: type: integer example: 1 filename: type: string example: "HR_Handbook_2024.pdf" size: type: integer description: File size in bytes example: 1048576 chunkCount: type: integer example: 45 uploadedAt: type: string format: date-time uploadedBy: type: string format: email status: type: string enum: [processing, ready, error] errorMessage: type: string isGlobal: type: boolean categories: type: array items: $ref: '#/components/schemas/CategoryAssignment' required: - id - filename - size - uploadedAt - uploadedBy - status - isGlobal CategoryAssignment: type: object properties: categoryId: type: integer categoryName: type: string Category: type: object properties: id: type: integer example: 1 name: type: string example: "Human Resources" slug: type: string example: "human-resources" description: type: string nullable: true createdBy: type: string format: email createdAt: type: string format: date-time documentCount: type: integer superUserCount: type: integer subscriberCount: type: integer required: - id - name - slug - createdAt User: type: object properties: email: type: string format: email name: type: string role: type: string enum: [admin, superuser, user] addedAt: type: string format: date-time addedBy: type: string format: email subscriptions: type: array items: $ref: '#/components/schemas/Subscription' assignedCategories: type: array items: $ref: '#/components/schemas/CategoryRef' required: - email - role - addedAt - addedBy Subscription: type: object properties: categoryId: type: integer categoryName: type: string isActive: type: boolean CategoryRef: type: object properties: categoryId: type: integer categoryName: type: string ApiError: type: object properties: error: type: string description: Human-readable error message code: type: string enum: - AUTH_REQUIRED - ADMIN_REQUIRED - SUPERUSER_REQUIRED - NOT_FOUND - FORBIDDEN - INVALID_BODY - INVALID_ID - INVALID_DAYS - VALIDATION - VALIDATION_ERROR - FILE_TOO_LARGE - UPLOAD_LIMIT - INVALID_FILE_TYPE - DUPLICATE - INTERNAL - SERVICE_ERROR - LEGACY_WRITE_DISABLED details: type: string description: Additional context required: - error ProviderStatus: type: object properties: provider: type: string available: type: boolean configured: type: boolean error: type: string ServiceStatus: type: object properties: name: type: string model: type: string provider: type: string available: type: boolean configured: type: boolean error: type: string Tool: type: object properties: name: type: string example: "web_search" displayName: type: string example: "Web Search" description: type: string category: type: string enum: [autonomous, processor] enabled: type: boolean config: type: object hasDefinition: type: boolean updatedAt: type: string format: date-time updatedBy: type: string required: - name - displayName - category - enabled Skill: type: object properties: id: type: integer name: type: string example: "Legal Compliance" description: type: string nullable: true promptContent: type: string triggerType: type: string enum: [always, category, keyword] triggerValue: type: string nullable: true categoryRestricted: type: boolean isIndex: type: boolean priority: type: integer isActive: type: boolean isCore: type: boolean tokenEstimate: type: integer categories: type: array items: type: object properties: id: type: integer name: type: string required: - id - name - triggerType - isActive - isCore StarterPrompt: type: object properties: label: type: string maxLength: 30 example: "Leave Policy" prompt: type: string maxLength: 500 example: "What is the annual leave policy?" required: - label - prompt CategoryPrompt: type: object properties: categoryId: type: integer promptAddendum: type: string starterPrompts: type: array items: $ref: '#/components/schemas/StarterPrompt' maxCharactersAvailable: type: integer updatedAt: type: string format: date-time updatedBy: type: string AgentBot: type: object properties: id: type: string format: uuid name: type: string example: "HR Assistant" slug: type: string example: "hr-assistant" description: type: string is_active: type: boolean created_by: type: string created_at: type: string format: date-time updated_at: type: string format: date-time required: - id - name - slug - is_active - created_by - created_at AgentBotVersion: type: object properties: id: type: string format: uuid agent_bot_id: type: string format: uuid version_label: type: string example: "v1.0" is_default: type: boolean is_active: type: boolean input_schema: $ref: '#/components/schemas/InputSchema' output_config: $ref: '#/components/schemas/OutputConfig' system_prompt: type: string llm_model: type: string temperature: type: number max_tokens: type: integer include_sources: type: boolean description: Whether to include RAG source citations in the response created_by: type: string created_at: type: string format: date-time updated_at: type: string format: date-time InputSchema: type: object properties: parameters: type: array items: type: object properties: name: type: string type: type: string enum: [string, number, boolean, array] description: type: string required: type: boolean default: type: string OutputConfig: type: object properties: enabledTypes: type: array items: type: string enum: [text, json, pdf, docx, xlsx, pptx, image, podcast, md, chart, diagram] defaultType: type: string enum: [text, json, pdf, docx, xlsx, pptx, image, podcast, md, chart, diagram] required: - enabledTypes - defaultType AgentBotApiKey: type: object properties: id: type: string format: uuid agent_bot_id: type: string format: uuid name: type: string key_prefix: type: string example: "pb_abc..." permissions: type: array items: type: string rate_limit_rpm: type: integer example: 60 rate_limit_rpd: type: integer example: 1000 expires_at: type: string format: date-time last_used_at: type: string format: date-time is_active: type: boolean created_by: type: string created_at: type: string format: date-time revoked_at: type: string format: date-time InvokeRequest: type: object properties: input: type: object additionalProperties: true example: query: "What is the annual leave policy?" version: type: string description: "Version ID or 'latest'" example: "latest" outputType: type: string enum: [text, json, pdf, docx, xlsx, pptx, image, podcast, md, chart, diagram] example: "text" async: type: boolean description: "If true, returns immediately with jobId" example: false files: type: array items: type: string description: "Array of uploaded file IDs to include as context" example: ["file_abc123"] webhookUrl: type: string format: uri example: "https://your-server.com/webhook" webhookSecret: type: string example: "whsec_1234567890abcdef" fallbackType: type: string enum: [text, json, md] description: "Optional override for admin-set fallback output type" example: "text" required: - input example: input: query: "What is the annual leave policy?" outputType: "text" InvokeResponse: type: object properties: success: type: boolean example: true jobId: type: string example: "job_abc123" outputs: type: array items: $ref: '#/components/schemas/InvokeOutput' sources: type: array description: "RAG source citations (only when version.include_sources is true)" items: type: object properties: documentName: type: string example: "HR_Handbook_2024.pdf" pageNumber: type: integer example: 12 chunkText: type: string example: "Annual leave entitlement is 20 working days..." score: type: number example: 0.89 tokenUsage: $ref: '#/components/schemas/TokenUsage' processingTimeMs: type: integer example: 2340 status: type: string enum: [completed, failed] description: "Final job status (only present in sync responses)" example: "completed" usedFallback: type: boolean description: "True if the primary output type failed and fallback was used" example: false example: success: true jobId: "job_abc123" outputs: - type: "text" content: "The annual leave policy entitles employees to 20 working days per year." sources: - documentName: "HR_Handbook_2024.pdf" pageNumber: 12 chunkText: "Annual leave entitlement is 20 working days..." score: 0.89 tokenUsage: promptTokens: 500 completionTokens: 200 totalTokens: 700 processingTimeMs: 2340 InvokeOutput: type: object properties: type: type: string enum: [text, json, pdf, docx, xlsx, pptx, image, podcast, md, chart, diagram] content: type: string downloadUrl: type: string filename: type: string fileSize: type: integer mimeType: type: string TokenUsage: type: object properties: promptTokens: type: integer completionTokens: type: integer totalTokens: type: integer JobStatus: type: object properties: jobId: type: string example: "job_abc123" status: type: string enum: [pending, running, completed, failed, cancelled] example: "completed" createdAt: type: string format: date-time startedAt: type: string format: date-time completedAt: type: string format: date-time outputs: type: array items: $ref: '#/components/schemas/InvokeOutput' tokenUsage: $ref: '#/components/schemas/TokenUsage' processingTimeMs: type: integer example: 2340 error: type: object properties: message: type: string example: "Model request failed" code: type: string example: "PROCESSING_ERROR" example: jobId: "job_abc123" status: "completed" outputs: - type: "text" content: "The annual leave policy entitles employees to 20 working days per year." tokenUsage: promptTokens: 500 completionTokens: 200 totalTokens: 700 processingTimeMs: 2340 AgentBotSpec: type: object properties: name: type: string example: "HR Policy Assistant" slug: type: string example: "hr-assistant" description: type: string example: "Answers HR policy questions" baseUrl: type: string example: "https://ai.abhirup.app/api/agent-bots/hr-assistant" version: type: object properties: number: type: integer example: 3 label: type: string example: "v1.2" inputSchema: type: object properties: parameters: type: array items: type: object properties: name: type: string type: type: string description: type: string required: type: boolean default: type: object uploadConfig: type: object properties: enabled: type: boolean maxFiles: type: integer maxSizePerFileMB: type: integer allowedTypes: type: array items: type: string required: type: boolean outputConfig: type: object properties: enabledTypes: type: array items: type: string defaultType: type: string supportsFallback: type: boolean endpoints: type: array items: type: object properties: path: type: string method: type: string purpose: type: string features: type: object properties: async: type: boolean sync: type: boolean webhooks: type: boolean includeSources: type: boolean LLMProvider: type: object properties: id: type: string example: "openai" name: type: string example: "OpenAI" apiKey: type: string description: "Masked API key" apiKeyConfigured: type: boolean apiBase: type: string enabled: type: boolean createdAt: type: string format: date-time updatedAt: type: string format: date-time EnabledModel: type: object properties: id: type: string example: "gpt-4o" providerId: type: string example: "openai" displayName: type: string example: "GPT-4o" isDefault: type: boolean isActive: type: boolean toolCapable: type: boolean visionCapable: type: boolean maxInputTokens: type: integer costPer1kInput: type: number costPer1kOutput: type: number sortOrder: type: integer createdAt: type: string format: date-time updatedAt: type: string format: date-time AiSetupOrganization: type: object description: Organization visible through the consolidated AI & API Setup surface. required: - id - name - type - isDefault - credentialMode - status - isolationMode - createdAt - updatedAt properties: id: type: integer example: 42 name: type: string maxLength: 120 example: Ministry of Finance type: type: string enum: [DEFAULT, ENTITY, INDIVIDUAL] isDefault: type: boolean credentialMode: type: string enum: [PLATFORM_MANAGED, ORGANIZATION_BYOK] status: type: string example: active isolationMode: type: string example: SOFT createdAt: type: string format: date-time updatedAt: type: string format: date-time activeCredentialCount: type: integer minimum: 0 description: Included on organizations in the consolidated overview. membershipRole: type: string nullable: true enum: [org_admin, member] description: The viewer's role in this organization, if applicable. AiSetupViewer: type: object required: [role, isSuperAdmin, userId, organizationId, membershipRole] properties: role: type: string enum: [super_admin, admin] isSuperAdmin: type: boolean userId: type: integer nullable: true organizationId: type: integer nullable: true membershipRole: type: string nullable: true enum: [org_admin, member] AiSetupProvider: type: object required: [id, name, description, enabled, sortOrder] properties: id: type: string example: openai name: type: string example: OpenAI description: type: string nullable: true enabled: type: boolean sortOrder: type: integer AiSetupCapability: type: object required: [id, name, description, importance, sortOrder] properties: id: type: string example: embeddings name: type: string description: type: string nullable: true importance: type: string enum: [REQUIRED, RECOMMENDED, OPTIONAL] sortOrder: type: integer AiSetupProviderCapability: type: object required: [providerId, capabilityId, isSupported, modelOrServiceIds] properties: providerId: type: string capabilityId: type: string isSupported: type: boolean modelOrServiceIds: nullable: true description: Registry-defined model/service identifiers; shape depends on the provider catalog entry. AiSetupRegistry: type: object required: [providers, capabilities, providerCapabilities] properties: providers: type: array items: $ref: '#/components/schemas/AiSetupProvider' capabilities: type: array items: $ref: '#/components/schemas/AiSetupCapability' providerCapabilities: type: array items: $ref: '#/components/schemas/AiSetupProviderCapability' AiSetupCapabilityConfig: type: object required: [capabilityId, providerId, credentialId, modelOrServiceId, enabled] properties: capabilityId: type: string example: llm providerId: type: string description: An empty string in a capability update clears the capability configuration. example: openai credentialId: type: string nullable: true example: openai-550e8400-e29b-41d4-a716-446655440000 modelOrServiceId: type: string nullable: true example: gpt-4o enabled: type: boolean AiSetupCapabilityHealth: type: object required: [capabilityId, importance, state, providerId, warnings] properties: capabilityId: type: string importance: type: string enum: [REQUIRED, RECOMMENDED, OPTIONAL] state: type: string enum: [READY, DEGRADED, UNAVAILABLE, NOT_CONFIGURED] providerId: type: string nullable: true warnings: type: array items: type: string AiSetupHealthReport: type: object required: [capabilities, readiness, saveBlocking, warnings] properties: capabilities: type: array items: $ref: '#/components/schemas/AiSetupCapabilityHealth' readiness: type: string enum: [READY, DEGRADED, UNAVAILABLE, NOT_CONFIGURED] saveBlocking: type: boolean description: Currently always false; incomplete credentials do not block saving configuration. warnings: type: array items: type: string AiSetupRedactedCredential: type: object description: Credential metadata with secret material redacted. Raw keys are never returned. required: - credentialId - providerId - status - isDefault - credentialVersion - lastVerifiedAt - redactedDetail - createdAt - updatedAt properties: credentialId: type: string providerId: type: string status: type: string example: active isDefault: type: boolean credentialVersion: type: integer minimum: 1 lastVerifiedAt: type: string format: date-time nullable: true redactedDetail: type: string description: Bounded redaction placeholder; never contains the raw credential. example: '••••••••' createdAt: type: string format: date-time updatedAt: type: string format: date-time AiSetupMember: type: object required: [userId, email, name, role, status] properties: userId: type: integer email: type: string format: email name: type: string nullable: true role: type: string enum: [org_admin, member] status: type: string example: active AiSetupAuditEntry: type: object description: Redacted credential key-change audit entry. required: - id - organizationId - providerId - credentialId - actorUserId - actorEmail - action - redactedDetail - createdAt properties: id: type: integer organizationId: type: integer nullable: true providerId: type: string credentialId: type: string nullable: true actorUserId: type: integer nullable: true actorEmail: type: string format: email nullable: true action: type: string example: replaced redactedDetail: type: string nullable: true description: Redacted audit detail only; raw keys are never logged or returned. createdAt: type: string format: date-time AiSetupUsageByCredential: type: object required: [credentialId, providerId, totalTokens, callCount, totalCost] properties: credentialId: type: string nullable: true providerId: type: string nullable: true totalTokens: type: integer minimum: 0 callCount: type: integer minimum: 0 totalCost: type: number format: double minimum: 0 description: Zero when cost visibility is denied. AiSetupUsageSummary: type: object required: [totalTokens, totalCalls, totalCost, byCredential, costUnavailable] properties: totalTokens: type: integer minimum: 0 totalCalls: type: integer minimum: 0 totalCost: type: number format: double minimum: 0 description: Zero when cost visibility is denied. byCredential: type: array items: $ref: '#/components/schemas/AiSetupUsageByCredential' costUnavailable: type: boolean AiSetupOverview: type: object required: - flag - viewer - selectedOrgId - organizations - registry - health - credentials - activeCredentialCount - capabilityConfig properties: flag: type: object required: [aiApiSetupUiEnabled] properties: aiApiSetupUiEnabled: type: boolean viewer: $ref: '#/components/schemas/AiSetupViewer' selectedOrgId: type: integer nullable: true organizations: type: array items: $ref: '#/components/schemas/AiSetupOrganization' registry: $ref: '#/components/schemas/AiSetupRegistry' health: allOf: - $ref: '#/components/schemas/AiSetupHealthReport' nullable: true credentials: type: array items: $ref: '#/components/schemas/AiSetupRedactedCredential' activeCredentialCount: type: integer minimum: 0 capabilityConfig: type: array items: $ref: '#/components/schemas/AiSetupCapabilityConfig' AutonomousPlanResponse: type: object properties: success: type: boolean status: type: string enum: [active, paused, stopped] completed_tasks: type: integer remaining_tasks: type: integer skipped_tasks: type: integer total_tasks: type: integer message: type: string securitySchemes: sessionAuth: type: apiKey in: cookie name: next-auth.session-token description: NextAuth session cookie apiKeyAuth: type: http scheme: bearer description: API key for agent bot invocation responses: BadRequest: description: Invalid request or validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' Unauthorized: description: Authentication required content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: "Unauthorized" code: "AUTH_REQUIRED" Forbidden: description: Insufficient permissions content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: "Admin access required" code: "ADMIN_REQUIRED" NotFound: description: Resource not found content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: "Resource not found" code: "NOT_FOUND" InternalError: description: Internal server error content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: "Internal server error" code: "SERVICE_ERROR" security: - sessionAuth: [] paths: /chat: post: tags: - Chat summary: Send chat message description: Send a message and receive a RAG-powered response with document sources operationId: sendMessage requestBody: required: true content: application/json: schema: type: object properties: message: type: string description: User's question example: "What is the annual leave policy?" threadId: type: string format: uuid description: Thread ID example: "550e8400-e29b-41d4-a716-446655440000" required: - message - threadId responses: '200': description: Successful response content: application/json: schema: type: object properties: message: $ref: '#/components/schemas/Message' threadId: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /chat/stream: post: tags: - Chat summary: Send streaming chat message description: Send a message and receive a streaming RAG response over Server-Sent Events (SSE). Response style fields are optional and resolved server-side with precedence current-turn instruction > chat-input override > stored profile > default. operationId: sendStreamingMessage requestBody: required: true content: application/json: schema: type: object properties: message: type: string description: User's question threadId: type: string format: uuid description: Thread ID responseTone: type: string description: Persona/tone. Canonical values are `default`, `friendly`, `formal`, `direct`, `professional`, `custom`; legacy values `concise`, `detailed`, `explanatory`, `creative` are accepted and mapped server-side. enum: [default, friendly, formal, direct, professional, custom, concise, detailed, explanatory, creative] default: default verbosity: type: string enum: [brief, balanced, detailed] default: balanced description: Chat-input verbosity override customToneName: type: string maxLength: 60 description: Transient custom persona name (only used with `responseTone: custom`) customToneInstruction: type: string maxLength: 500 description: Transient custom persona instruction (non-empty when `responseTone: custom`) required: - message - threadId responses: '200': description: SSE stream of events (status, operation_log, message, sources, done, error) '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /threads: get: tags: - Threads summary: List threads description: List all threads for the current user operationId: listThreads parameters: - name: limit in: query schema: type: integer default: 50 minimum: 1 maximum: 100 description: Max threads to return - name: offset in: query schema: type: integer default: 0 description: Pagination offset responses: '200': description: List of threads content: application/json: schema: type: object properties: threads: type: array items: $ref: '#/components/schemas/Thread' total: type: integer '401': $ref: '#/components/responses/Unauthorized' post: tags: - Threads summary: Create thread description: Create a new conversation thread operationId: createThread requestBody: content: application/json: schema: type: object properties: title: type: string example: "HR Policy Questions" categoryIds: type: array items: type: integer example: [1, 2] responses: '201': description: Thread created content: application/json: schema: $ref: '#/components/schemas/Thread' '401': $ref: '#/components/responses/Unauthorized' /threads/{threadId}: parameters: - name: threadId in: path required: true schema: type: string format: uuid get: tags: - Threads summary: Get thread description: Get a specific thread with all messages operationId: getThread responses: '200': description: Thread details content: application/json: schema: allOf: - $ref: '#/components/schemas/Thread' - type: object properties: messages: type: array items: $ref: '#/components/schemas/Message' uploads: type: array items: type: string '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' patch: tags: - Threads summary: Update thread description: Update thread title or categories operationId: updateThread requestBody: content: application/json: schema: type: object properties: title: type: string maxLength: 100 categoryIds: type: array items: type: integer responses: '200': description: Thread updated content: application/json: schema: type: object properties: id: type: string title: type: string categoryIds: type: array items: type: integer updatedAt: type: string format: date-time '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' delete: tags: - Threads summary: Delete thread description: Delete a thread and all associated data operationId: deleteThread responses: '200': description: Thread deleted content: application/json: schema: type: object properties: success: type: boolean deleted: type: object properties: threadId: type: string messageCount: type: integer uploadCount: type: integer '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' /threads/{threadId}/upload: parameters: - name: threadId in: path required: true schema: type: string format: uuid post: tags: - Threads summary: Upload file to thread description: Upload a PDF to a thread for compliance checking operationId: uploadToThread requestBody: required: true content: multipart/form-data: schema: type: object properties: file: type: string format: binary description: PDF file (max 5MB) required: - file responses: '200': description: File uploaded content: application/json: schema: type: object properties: filename: type: string size: type: integer uploadCount: type: integer '400': description: Validation error or upload limit reached content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '413': description: File too large content: application/json: schema: $ref: '#/components/schemas/ApiError' /user/categories: get: tags: - User summary: Get accessible categories description: Get categories available to the current user based on their role operationId: getUserCategories responses: '200': description: List of categories content: application/json: schema: type: object properties: categories: type: array items: type: object properties: id: type: integer name: type: string slug: type: string description: type: string '401': $ref: '#/components/responses/Unauthorized' /user/subscriptions: get: tags: - User summary: Get subscriptions description: Get the current user's category subscriptions operationId: getUserSubscriptions responses: '200': description: List of subscriptions content: application/json: schema: type: object properties: subscriptions: type: array items: type: object properties: categoryId: type: integer categoryName: type: string categorySlug: type: string isActive: type: boolean '401': $ref: '#/components/responses/Unauthorized' /user/memory: get: tags: - User summary: Get personal memory description: Get the current user's preference profile, interests, and pending learned preferences. Rejects agent-bot and workspace surface headers. operationId: getPersonalMemory responses: '200': description: Personal memory payload content: application/json: schema: type: object properties: profile: type: object properties: tone: type: string enum: [default, friendly, formal, direct, professional, custom] customToneName: type: string nullable: true maxLength: 60 customToneInstruction: type: string nullable: true maxLength: 500 verbosity: type: string enum: [brief, balanced, detailed] interests: type: array items: type: object pendingPreferences: type: array items: type: object limits: type: object categoryMemory: type: object '401': $ref: '#/components/responses/Unauthorized' patch: tags: - User summary: Update personal memory description: Update preferences or act on interests/pending candidates. With `action: update_preferences`, pass a `preferences` object containing `tone` (`default|friendly|formal|direct|professional|custom`), `customToneName` (≤60 chars), `customToneInstruction` (≤500 chars, non-empty when `tone` is `custom`), `verbosity` (`brief|balanced|detailed`), and other preference fields. operationId: updatePersonalMemory requestBody: required: true content: application/json: schema: type: object required: - action properties: action: type: string enum: [update_preferences, set_learning, set_interest_active, accept_pending_preference, reject_pending_preference] preferences: type: object properties: tone: type: string enum: [default, friendly, formal, direct, professional, custom] customToneName: type: string maxLength: 60 customToneInstruction: type: string maxLength: 500 verbosity: type: string enum: [brief, balanced, detailed] responses: '200': description: Updated profile '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' /branding: get: tags: - Branding summary: Get branding settings description: Get branding settings (public endpoint, no authentication required) operationId: getBranding security: [] responses: '200': description: Branding settings content: application/json: schema: type: object properties: botName: type: string example: "AI Assistant" botIcon: type: string example: "policy" availableIcons: type: array items: type: object properties: key: type: string label: type: string lucideIcon: type: string /admin/categories: get: tags: - Admin - Categories summary: List all categories description: List all categories with statistics (admin only) operationId: listCategories responses: '200': description: List of categories content: application/json: schema: type: object properties: categories: type: array items: $ref: '#/components/schemas/Category' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Categories summary: Create category description: Create a new category (admin only) operationId: createCategory requestBody: required: true content: application/json: schema: type: object properties: name: type: string example: "Human Resources" description: type: string example: "HR policies and procedures" required: - name responses: '201': description: Category created content: application/json: schema: type: object properties: category: $ref: '#/components/schemas/Category' '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '409': description: Category already exists content: application/json: schema: $ref: '#/components/schemas/ApiError' /admin/categories/{id}: parameters: - name: id in: path required: true schema: type: integer get: tags: - Admin - Categories summary: Get category details description: Get category details with users and documents (admin only) operationId: getCategory responses: '200': description: Category details content: application/json: schema: type: object properties: category: $ref: '#/components/schemas/Category' superUsers: type: array items: type: object properties: userId: type: integer email: type: string name: type: string subscribers: type: array items: type: object properties: userId: type: integer email: type: string name: type: string isActive: type: boolean documentCount: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' put: tags: - Admin - Categories summary: Update category description: Update a category (admin only) operationId: updateCategory requestBody: content: application/json: schema: type: object properties: name: type: string description: type: string responses: '200': description: Category updated content: application/json: schema: type: object properties: category: type: object properties: id: type: integer name: type: string slug: type: string description: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Categories summary: Delete category description: Delete a category (admin only). Documents become unassigned. operationId: deleteCategory responses: '200': description: Category deleted content: application/json: schema: type: object properties: success: type: boolean deleted: type: object properties: id: type: integer name: type: string documentsUnassigned: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/documents: get: tags: - Admin - Documents summary: List all documents description: List all global policy documents (admin only) operationId: listDocuments responses: '200': description: List of documents content: application/json: schema: type: object properties: documents: type: array items: $ref: '#/components/schemas/Document' totalChunks: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Documents summary: Upload document description: Upload a new policy document with category assignment (admin only) operationId: uploadDocument requestBody: required: true content: multipart/form-data: schema: type: object properties: file: type: string format: binary description: PDF file (max 50MB) categoryIds: type: string description: JSON array of category IDs example: "[1, 2]" isGlobal: type: string description: '"true" to index in all categories' example: "false" required: - file responses: '202': description: Document accepted for processing content: application/json: schema: type: object properties: id: type: integer filename: type: string size: type: integer status: type: string enum: [processing] isGlobal: type: boolean categoryIds: type: array items: type: integer message: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '409': description: Document already exists content: application/json: schema: $ref: '#/components/schemas/ApiError' '413': description: File too large content: application/json: schema: $ref: '#/components/schemas/ApiError' /admin/documents/{docId}: parameters: - name: docId in: path required: true schema: type: integer get: tags: - Admin - Documents summary: Get document details description: Get details of a specific document (admin only) operationId: getDocument responses: '200': description: Document details content: application/json: schema: $ref: '#/components/schemas/Document' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' patch: tags: - Admin - Documents summary: Update document description: Update document category assignments (admin only) operationId: updateDocument requestBody: content: application/json: schema: type: object properties: categoryIds: type: array items: type: integer isGlobal: type: boolean responses: '200': description: Document updated content: application/json: schema: type: object properties: id: type: integer filename: type: string isGlobal: type: boolean categories: type: array items: $ref: '#/components/schemas/CategoryAssignment' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Documents summary: Delete document description: Delete a policy document from the global store (admin only) operationId: deleteDocument responses: '200': description: Document deleted content: application/json: schema: type: object properties: success: type: boolean deleted: type: object properties: id: type: integer filename: type: string chunksRemoved: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/users: get: tags: - Admin - Users summary: List all users description: List all users with their subscriptions/assignments (admin only) operationId: listUsers responses: '200': description: List of users content: application/json: schema: type: object properties: users: type: array items: $ref: '#/components/schemas/User' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Users summary: Add user description: Add a new user with optional subscriptions/assignments (admin only) operationId: addUser requestBody: required: true content: application/json: schema: type: object properties: email: type: string format: email role: type: string enum: [admin, superuser, user] name: type: string subscriptions: type: array items: type: integer description: Category IDs for role="user" assignedCategories: type: array items: type: integer description: Category IDs for role="superuser" required: - email - role responses: '200': description: User added content: application/json: schema: type: object properties: user: type: object properties: email: type: string name: type: string role: type: string addedAt: type: string addedBy: type: string message: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' patch: tags: - Admin - Users summary: Update user role description: Update a user's role (admin only) operationId: updateUserRole requestBody: required: true content: application/json: schema: type: object properties: email: type: string format: email role: type: string enum: [admin, superuser, user] required: - email - role responses: '200': description: Role updated content: application/json: schema: type: object properties: message: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Users summary: Remove user description: Remove a user from the allowlist (admin only) operationId: removeUser parameters: - name: email in: query required: true schema: type: string format: email responses: '200': description: User removed content: application/json: schema: type: object properties: message: type: string '400': description: Cannot remove yourself content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/users/{userId}/subscriptions: parameters: - name: userId in: path required: true schema: type: integer get: tags: - Admin - Users summary: Get user subscriptions description: Get a user's category subscriptions (admin only) operationId: getUserSubscriptions responses: '200': description: User subscriptions content: application/json: schema: type: object properties: user: type: object properties: id: type: integer email: type: string name: type: string role: type: string subscriptions: type: array items: type: object properties: categoryId: type: integer categoryName: type: string categorySlug: type: string isActive: type: boolean '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' post: tags: - Admin - Users summary: Add subscription description: Add a subscription for a user (admin only) operationId: addUserSubscription requestBody: required: true content: application/json: schema: type: object properties: categoryId: type: integer required: - categoryId responses: '201': description: Subscription added content: application/json: schema: type: object properties: success: type: boolean subscription: type: object properties: userId: type: integer categoryId: type: integer categoryName: type: string isActive: type: boolean '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '409': description: User already subscribed content: application/json: schema: $ref: '#/components/schemas/ApiError' put: tags: - Admin - Users summary: Toggle subscription description: Toggle subscription active status (admin only) operationId: toggleUserSubscription requestBody: required: true content: application/json: schema: type: object properties: categoryId: type: integer isActive: type: boolean required: - categoryId - isActive responses: '200': description: Subscription toggled content: application/json: schema: type: object properties: success: type: boolean subscription: type: object properties: userId: type: integer categoryId: type: integer isActive: type: boolean '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Users summary: Remove subscription description: Remove a subscription from a user (admin only) operationId: removeUserSubscription parameters: - name: categoryId in: query required: true schema: type: integer responses: '200': description: Subscription removed content: application/json: schema: type: object properties: success: type: boolean removed: type: object properties: userId: type: integer categoryId: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/documents/text: post: tags: - Admin - Documents summary: Upload text content description: Upload text content directly as a document (bypasses OCR) operationId: uploadTextDocument requestBody: required: true content: application/json: schema: type: object properties: name: type: string maxLength: 255 description: Document name content: type: string minLength: 10 description: Text content (max 10MB) categoryIds: type: array items: type: integer description: Category IDs to assign isGlobal: type: boolean description: Index in all categories required: - name - content responses: '202': description: Document accepted for processing content: application/json: schema: type: object properties: id: type: string filename: type: string size: type: integer status: type: string enum: [processing] message: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '409': description: Document already exists content: application/json: schema: $ref: '#/components/schemas/ApiError' '413': description: Content too large content: application/json: schema: $ref: '#/components/schemas/ApiError' /admin/documents/{docId}/reindex: parameters: - name: docId in: path required: true schema: type: integer post: tags: - Admin - Documents summary: Reindex document description: Reindex an existing document (re-extract and re-embed) operationId: reindexDocument responses: '202': description: Reindex started content: application/json: schema: type: object properties: id: type: integer filename: type: string status: type: string enum: [processing] message: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/settings: get: tags: - Admin - Settings summary: Get all settings description: Get all configurable settings (admin only) operationId: getSettings responses: '200': description: All settings content: application/json: schema: type: object properties: rag: type: object properties: chunkSize: type: integer chunkOverlap: type: integer topK: type: integer cacheTTLSeconds: type: integer llm: type: object properties: model: type: string temperature: type: number maxTokens: type: integer acronyms: type: object properties: mappings: type: object additionalProperties: type: string tavily: type: object properties: enabled: type: boolean cacheTTLSeconds: type: integer branding: type: object properties: botName: type: string botIcon: type: string embedding: type: object properties: model: type: string dimensions: type: integer reranker: type: object properties: enabled: type: boolean providers: type: array items: type: object properties: provider: type: string enum: [bge-large, cohere, bge-base, local] enabled: type: boolean cohereApiKey: type: string topKForReranking: type: integer minRerankerScore: type: number uploadLimits: type: object properties: maxFilesPerThread: type: integer maxFileSizeMB: type: integer allowedTypes: type: array items: type: string availableModels: type: array items: type: string modelPresets: type: array items: type: object brandingIcons: type: array items: type: object '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' put: tags: - Admin - Settings summary: Update settings description: | Update settings by type (admin only). While the consolidated AI & API Setup feature is enabled, writes for `llm`, `embedding`, `reranker`, `ocr`, and `tavily` settings are legacy writes and return `409 LEGACY_WRITE_DISABLED`; use `/admin/ai-setup` instead. Other settings types remain writable. operationId: updateSettings requestBody: required: true content: application/json: schema: type: object properties: type: type: string enum: - rag - llm - acronyms - tavily - uploadLimits - retention - preset - branding - embedding - reranker - restoreAllDefaults settings: type: object description: Settings object (varies by type) required: - type responses: '200': description: Settings updated content: application/json: schema: type: object properties: success: type: boolean settings: type: object '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '409': description: A consolidated AI/provider setting can no longer be written through this legacy route content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: This legacy settings page is read-only. Configure provider keys and AI/API capabilities from the consolidated AI & API Setup page. code: LEGACY_WRITE_DISABLED /admin/system-prompt: get: tags: - Admin - Settings summary: Get system prompt description: Get the current system prompt with metadata (admin only) operationId: getSystemPrompt responses: '200': description: System prompt content: application/json: schema: type: object properties: systemPrompt: type: string updatedAt: type: string format: date-time updatedBy: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' put: tags: - Admin - Settings summary: Update system prompt description: Update the system prompt (admin only) operationId: updateSystemPrompt requestBody: required: true content: application/json: schema: type: object properties: systemPrompt: type: string minLength: 10 required: - systemPrompt responses: '200': description: System prompt updated content: application/json: schema: type: object properties: success: type: boolean systemPrompt: type: string updatedAt: type: string format: date-time updatedBy: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/refresh: post: tags: - Admin - System summary: Reindex all documents description: Reindex all documents and clear cache (admin only) operationId: refreshAll responses: '202': description: Reindex started content: application/json: schema: type: object properties: success: type: boolean message: type: string documentsQueued: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/stats: get: tags: - Admin - System summary: Get system statistics description: Get system statistics for the admin dashboard (admin only) operationId: getStats responses: '200': description: System statistics content: application/json: schema: type: object properties: database: type: object properties: users: type: integer categories: type: integer documents: type: integer threads: type: integer messages: type: integer vectorStore: type: object properties: collections: type: integer totalVectors: type: integer storage: type: object properties: totalBytes: type: integer documentsBytes: type: integer threadsBytes: type: integer percentUsed: type: number recentActivity: type: array items: type: object properties: type: type: string description: type: string timestamp: type: string format: date-time '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/providers: get: tags: - Admin - System summary: Check provider status description: Check the status and availability of configured LLM providers (admin only) operationId: getProviders responses: '200': description: Provider status content: application/json: schema: type: object properties: providers: type: object properties: openai: $ref: '#/components/schemas/ProviderStatus' mistral: $ref: '#/components/schemas/ProviderStatus' ollama: $ref: '#/components/schemas/ProviderStatus' azure: $ref: '#/components/schemas/ProviderStatus' services: type: object properties: embedding: $ref: '#/components/schemas/ServiceStatus' ocr: $ref: '#/components/schemas/ServiceStatus' audio: $ref: '#/components/schemas/ServiceStatus' usingProxy: type: boolean proxyUrl: type: string nullable: true '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/reranker-status: get: tags: - Admin - System summary: Check reranker status description: Check reranker availability (BGE cross-encoder, Cohere API, and local bi-encoder) operationId: getRerankerStatus responses: '200': description: Reranker status content: application/json: schema: type: object properties: cohere: type: object properties: available: type: boolean configured: type: boolean error: type: string local: type: object properties: available: type: boolean model: type: string error: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /superuser/documents: get: tags: - Super User - Documents summary: List assigned documents description: Get documents in super user's assigned categories operationId: getSuperuserDocuments responses: '200': description: Documents list content: application/json: schema: type: object properties: assignedCategories: type: array items: type: object properties: categoryId: type: integer categoryName: type: string categorySlug: type: string documents: type: array items: type: object properties: id: type: integer filename: type: string size: type: integer status: type: string enum: [processing, ready, error] uploadedBy: type: string uploadedAt: type: string format: date-time categories: type: array items: $ref: '#/components/schemas/CategoryAssignment' '401': $ref: '#/components/responses/Unauthorized' '403': description: Super user access required content: application/json: schema: $ref: '#/components/schemas/ApiError' post: tags: - Super User - Documents summary: Upload document description: Upload a document to one of super user's assigned categories operationId: uploadSuperuserDocument requestBody: required: true content: multipart/form-data: schema: type: object properties: file: type: string format: binary description: PDF file (max 50MB) categoryId: type: string description: Category ID (must be assigned to super user) required: - file - categoryId responses: '202': description: Document accepted for processing content: application/json: schema: type: object properties: id: type: integer filename: type: string size: type: integer status: type: string enum: [processing] message: type: string category: type: object properties: categoryId: type: integer categoryName: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': description: No access to this category content: application/json: schema: $ref: '#/components/schemas/ApiError' '413': description: File too large content: application/json: schema: $ref: '#/components/schemas/ApiError' /superuser/documents/text: post: tags: - Super User - Documents summary: Upload text content description: Upload text content directly to one of super user's assigned categories operationId: uploadSuperuserTextDocument requestBody: required: true content: application/json: schema: type: object properties: name: type: string maxLength: 255 description: Document name content: type: string minLength: 10 description: Text content (max 10MB) categoryId: type: integer description: Category ID (must be assigned to super user) required: - name - content - categoryId responses: '202': description: Document accepted for processing content: application/json: schema: type: object properties: id: type: string filename: type: string size: type: integer status: type: string enum: [processing] message: type: string category: type: object properties: categoryId: type: integer categoryName: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': description: No access to this category content: application/json: schema: $ref: '#/components/schemas/ApiError' /superuser/documents/{docId}: parameters: - name: docId in: path required: true schema: type: integer delete: tags: - Super User - Documents summary: Delete document description: Delete a document (only if uploaded by this super user) operationId: deleteSuperuserDocument responses: '200': description: Document deleted content: application/json: schema: type: object properties: success: type: boolean deleted: type: object properties: id: type: integer filename: type: string chunksRemoved: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': description: Cannot delete this document content: application/json: schema: $ref: '#/components/schemas/ApiError' '404': $ref: '#/components/responses/NotFound' /superuser/users: get: tags: - Super User - Users summary: List category users description: Get users subscribed to super user's assigned categories operationId: getSuperuserUsers responses: '200': description: Users list content: application/json: schema: type: object properties: assignedCategories: type: array items: type: object properties: categoryId: type: integer categoryName: type: string categorySlug: type: string users: type: array items: type: object properties: id: type: integer email: type: string name: type: string nullable: true subscriptions: type: array items: type: object properties: categoryId: type: integer categoryName: type: string isActive: type: boolean '401': $ref: '#/components/responses/Unauthorized' '403': description: Super user access required content: application/json: schema: $ref: '#/components/schemas/ApiError' post: tags: - Super User - Users summary: Add subscription description: Add subscription for a user to one of super user's categories operationId: addSuperuserSubscription requestBody: required: true content: application/json: schema: type: object properties: userEmail: type: string format: email categoryId: type: integer required: - userEmail - categoryId responses: '201': description: Subscription added content: application/json: schema: type: object properties: success: type: boolean subscription: type: object properties: userId: type: integer categoryId: type: integer categoryName: type: string isActive: type: boolean '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': description: No access to this category content: application/json: schema: $ref: '#/components/schemas/ApiError' '404': $ref: '#/components/responses/NotFound' '409': description: User already subscribed content: application/json: schema: $ref: '#/components/schemas/ApiError' delete: tags: - Super User - Users summary: Remove subscription description: Remove subscription from one of super user's categories operationId: removeSuperuserSubscription parameters: - name: userEmail in: query required: true schema: type: string format: email - name: categoryId in: query required: true schema: type: integer responses: '200': description: Subscription removed content: application/json: schema: type: object properties: success: type: boolean removed: type: object properties: userId: type: integer categoryId: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': description: No access to this category content: application/json: schema: $ref: '#/components/schemas/ApiError' '404': $ref: '#/components/responses/NotFound' /superuser/categories: get: tags: - Super User - Categories summary: Get accessible categories description: | Get super user's accessible categories including: - Managed categories (from super_user_categories - full control) - Subscribed categories (from user_subscriptions - read-only access) - Category creation quota information operationId: getSuperuserCategories responses: '200': description: Categories and quota content: application/json: schema: type: object properties: managedCategories: type: array description: Categories the superuser can manage (upload docs, manage users) items: type: object properties: id: type: integer name: type: string slug: type: string description: type: string nullable: true documentCount: type: integer subscriberCount: type: integer createdByMe: type: boolean description: Whether this superuser created the category subscribedCategories: type: array description: Categories the superuser has read-only access to (for chat) items: type: object properties: id: type: integer name: type: string slug: type: string description: type: string nullable: true isActive: type: boolean quota: type: object description: Category creation quota for this superuser properties: used: type: integer description: Categories already created by this superuser limit: type: integer description: Maximum categories this superuser can create canCreate: type: boolean description: Whether the superuser can create more categories '401': $ref: '#/components/responses/Unauthorized' '403': description: Super user access required content: application/json: schema: $ref: '#/components/schemas/ApiError' post: tags: - Super User - Categories summary: Create category description: Create a new category (within superuser's quota). The category is automatically assigned to the superuser. operationId: createSuperuserCategory requestBody: required: true content: application/json: schema: type: object properties: name: type: string maxLength: 100 description: Category name description: type: string description: Optional category description required: - name responses: '201': description: Category created content: application/json: schema: type: object properties: success: type: boolean category: type: object properties: id: type: integer name: type: string slug: type: string description: type: string nullable: true createdBy: type: string createdAt: type: string format: date-time quota: type: object properties: used: type: integer limit: type: integer '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': description: Super user access required or quota exceeded content: application/json: schema: $ref: '#/components/schemas/ApiError' '409': description: Category already exists content: application/json: schema: $ref: '#/components/schemas/ApiError' delete: tags: - Super User - Categories summary: Delete category description: Delete a category created by this super user. Also deletes all documents and vector store data. operationId: deleteSuperuserCategory parameters: - name: categoryId in: query required: true schema: type: integer description: Category ID to delete responses: '200': description: Category deleted content: application/json: schema: type: object properties: success: type: boolean deleted: type: object properties: categoryId: type: integer categoryName: type: string documentsDeleted: type: integer deleteErrors: type: array items: type: string description: Any failed document deletions '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': description: Can only delete categories you created content: application/json: schema: $ref: '#/components/schemas/ApiError' '404': $ref: '#/components/responses/NotFound' /admin/tools: get: tags: - Admin - Tools summary: List all tools description: List all tools with their configurations (admin only) operationId: listTools responses: '200': description: List of tools content: application/json: schema: type: object properties: tools: type: array items: $ref: '#/components/schemas/Tool' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Tools summary: Initialize tools description: Initialize all tools to default configurations (admin only) operationId: initializeTools responses: '200': description: Tools initialized content: application/json: schema: type: object properties: message: type: string tools: type: array items: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/tools/{toolName}: parameters: - name: toolName in: path required: true schema: type: string example: "web_search" get: tags: - Admin - Tools summary: Get tool configuration description: Get specific tool configuration with audit history (admin only) operationId: getToolConfig responses: '200': description: Tool configuration content: application/json: schema: type: object properties: tool: $ref: '#/components/schemas/Tool' configSchema: type: object defaultConfig: type: object auditHistory: type: array items: type: object properties: operation: type: string enum: [create, update, delete] oldConfig: type: object newConfig: type: object changedBy: type: string changedAt: type: string format: date-time '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' patch: tags: - Admin - Tools summary: Update tool configuration description: Update tool configuration (admin only) operationId: updateToolConfig requestBody: content: application/json: schema: type: object properties: enabled: type: boolean config: type: object reset: type: boolean description: Reset to defaults responses: '200': description: Tool updated content: application/json: schema: type: object properties: tool: type: object properties: name: type: string enabled: type: boolean config: type: object updatedAt: type: string format: date-time updatedBy: type: string '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/tools/{toolName}/test: parameters: - name: toolName in: path required: true schema: type: string post: tags: - Admin - Tools summary: Test tool description: Test tool connectivity and configuration (admin only) operationId: testTool responses: '200': description: Test result content: application/json: schema: type: object properties: tool: type: string success: type: boolean message: type: string latency: type: number testedAt: type: string format: date-time testedBy: type: string '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/skills: get: tags: - Admin - Skills summary: List all skills description: List all skills with settings (admin only) operationId: listSkills responses: '200': description: List of skills content: application/json: schema: type: object properties: skills: type: array items: $ref: '#/components/schemas/Skill' settings: type: object properties: enabled: type: boolean maxTotalTokens: type: integer debugMode: type: boolean '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Skills summary: Create skill description: Create a new custom skill (admin only) operationId: createSkill requestBody: required: true content: application/json: schema: type: object properties: name: type: string description: type: string promptContent: type: string triggerType: type: string enum: [always, category, keyword] triggerValue: type: string categoryRestricted: type: boolean isIndex: type: boolean priority: type: integer categoryIds: type: array items: type: integer required: - name - promptContent - triggerType responses: '201': description: Skill created content: application/json: schema: type: object properties: skill: $ref: '#/components/schemas/Skill' '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '409': description: Skill already exists content: application/json: schema: $ref: '#/components/schemas/ApiError' delete: tags: - Admin - Skills summary: Reset core skills description: Reset all core skills to their defaults (admin only) operationId: resetCoreSkills responses: '200': description: Core skills reset content: application/json: schema: type: object properties: message: type: string restoredCount: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/skills/{skillId}: parameters: - name: skillId in: path required: true schema: type: integer put: tags: - Admin - Skills summary: Update skill description: Update an existing skill (admin only) operationId: updateSkill requestBody: content: application/json: schema: type: object properties: name: type: string description: type: string promptContent: type: string triggerType: type: string enum: [always, category, keyword] triggerValue: type: string categoryRestricted: type: boolean isIndex: type: boolean priority: type: integer isActive: type: boolean categoryIds: type: array items: type: integer responses: '200': description: Skill updated content: application/json: schema: type: object properties: skill: $ref: '#/components/schemas/Skill' '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Skills summary: Delete skill description: Delete a skill (core skills cannot be deleted) (admin only) operationId: deleteSkill responses: '200': description: Skill deleted content: application/json: schema: type: object properties: success: type: boolean deleted: type: object properties: id: type: integer name: type: string '400': description: Cannot delete core skill content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /admin/skills/preview: get: tags: - Admin - Skills summary: Preview skill activation description: Preview which skills would activate for a test message (admin only) operationId: previewSkillActivation parameters: - name: message in: query required: true schema: type: string - name: categoryIds in: query schema: type: string description: Comma-separated category IDs responses: '200': description: Skill activation preview content: application/json: schema: type: object properties: activatedSkills: type: array items: type: object properties: id: type: integer name: type: string triggerType: type: string triggerReason: type: string totalTokens: type: integer budgetRemaining: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/skills/settings: patch: tags: - Admin - Skills summary: Update skills settings description: Update skills system settings (admin only) operationId: updateSkillsSettings requestBody: content: application/json: schema: type: object properties: enabled: type: boolean maxTotalTokens: type: integer debugMode: type: boolean responses: '200': description: Settings updated content: application/json: schema: type: object properties: settings: type: object properties: enabled: type: boolean maxTotalTokens: type: integer debugMode: type: boolean '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /categories/{id}/prompt: parameters: - name: id in: path required: true schema: type: integer get: tags: - Category Prompts summary: Get category prompt description: Get category-specific prompt configuration operationId: getCategoryPrompt responses: '200': description: Category prompt content: application/json: schema: $ref: '#/components/schemas/CategoryPrompt' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' put: tags: - Category Prompts summary: Update category prompt description: Update category-specific prompt configuration operationId: updateCategoryPrompt requestBody: content: application/json: schema: type: object properties: promptAddendum: type: string starterPrompts: type: array maxItems: 6 items: $ref: '#/components/schemas/StarterPrompt' responses: '200': description: Category prompt updated content: application/json: schema: $ref: '#/components/schemas/CategoryPrompt' '400': description: Validation error (forbidden phrases, length limits) content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' delete: tags: - Category Prompts summary: Reset category prompt description: Reset category prompt to global system prompt only operationId: resetCategoryPrompt responses: '200': description: Category prompt reset content: application/json: schema: type: object properties: success: type: boolean categoryId: type: integer '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /superuser/tools: get: tags: - Super User - Tools summary: List tools with overrides description: View tools with category-level overrides for assigned categories operationId: getSuperuserTools responses: '200': description: Tools with category overrides content: application/json: schema: type: object properties: tools: type: array items: type: object properties: name: type: string displayName: type: string description: type: string category: type: string globalEnabled: type: boolean categories: type: array items: type: object properties: categoryId: type: integer categoryName: type: string isEnabled: type: boolean nullable: true effectiveEnabled: type: boolean branding: type: object assignedCategories: type: array items: type: object properties: id: type: integer name: type: string slug: type: string '401': $ref: '#/components/responses/Unauthorized' '403': description: Superuser access required content: application/json: schema: $ref: '#/components/schemas/ApiError' /superuser/tools/{toolName}: parameters: - name: toolName in: path required: true schema: type: string post: tags: - Super User - Tools summary: Set category tool override description: Create or update category-level tool override operationId: setCategoryToolOverride requestBody: required: true content: application/json: schema: type: object properties: categoryId: type: integer isEnabled: type: boolean nullable: true description: null to inherit from global branding: type: object properties: enabled: type: boolean logoUrl: type: string organizationName: type: string primaryColor: type: string required: - categoryId responses: '200': description: Override set content: application/json: schema: type: object properties: categoryId: type: integer toolName: type: string isEnabled: type: boolean nullable: true branding: type: object effectiveEnabled: type: boolean '400': description: Validation error content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': description: No access to this category content: application/json: schema: $ref: '#/components/schemas/ApiError' '404': $ref: '#/components/responses/NotFound' # ========== Admin - Data Sources ========== /admin/data-sources: get: tags: - Admin - Data Sources summary: List all data sources description: Get all API and CSV data sources operationId: listDataSources parameters: - name: type in: query schema: type: string enum: [api, csv] - name: categoryId in: query schema: type: integer responses: '200': description: Data sources list content: application/json: schema: type: object properties: apis: type: array items: type: object csvs: type: array items: type: object counts: type: object '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Data Sources summary: Create API data source operationId: createDataSource requestBody: required: true content: application/json: schema: type: object required: [name, endpoint] responses: '200': description: Data source created '400': description: Validation error '401': $ref: '#/components/responses/Unauthorized' /admin/data-sources/{id}: parameters: - name: id in: path required: true schema: type: string get: tags: - Admin - Data Sources summary: Get data source operationId: getDataSource responses: '200': description: Data source details '404': $ref: '#/components/responses/NotFound' put: tags: - Admin - Data Sources summary: Update data source operationId: updateDataSource responses: '200': description: Data source updated '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Data Sources summary: Delete data source operationId: deleteDataSource parameters: - name: type in: query required: true schema: type: string enum: [api, csv] responses: '200': description: Data source deleted '404': $ref: '#/components/responses/NotFound' /admin/data-sources/{id}/test: post: tags: - Admin - Data Sources summary: Test data source operationId: testDataSource parameters: - name: id in: path required: true schema: type: string responses: '200': description: Test results /admin/data-sources/upload-csv: post: tags: - Admin - Data Sources summary: Upload CSV data source operationId: uploadCSVDataSource requestBody: required: true content: multipart/form-data: schema: type: object required: [file, name] responses: '200': description: CSV uploaded /admin/data-sources/parse-openapi: post: tags: - Admin - Data Sources summary: Parse OpenAPI spec operationId: parseOpenAPISpec responses: '200': description: Parsed endpoints # ========== Admin - Function APIs ========== /admin/function-apis: get: tags: - Admin - Function APIs summary: List Function APIs operationId: listFunctionAPIs parameters: - name: categoryId in: query schema: type: integer responses: '200': description: Function APIs list '401': $ref: '#/components/responses/Unauthorized' post: tags: - Admin - Function APIs summary: Create Function API operationId: createFunctionAPI requestBody: required: true content: application/json: schema: type: object required: [name, baseUrl, toolsSchema, endpointMappings] responses: '200': description: Function API created '400': description: Validation error /admin/function-apis/{id}: parameters: - name: id in: path required: true schema: type: string get: tags: - Admin - Function APIs summary: Get Function API operationId: getFunctionAPI responses: '200': description: Function API details '404': $ref: '#/components/responses/NotFound' put: tags: - Admin - Function APIs summary: Update Function API operationId: updateFunctionAPI responses: '200': description: Function API updated '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Function APIs summary: Delete Function API operationId: deleteFunctionAPI responses: '200': description: Function API deleted '404': $ref: '#/components/responses/NotFound' /admin/function-apis/{id}/test: post: tags: - Admin - Function APIs summary: Test Function API operationId: testFunctionAPI parameters: - name: id in: path required: true schema: type: string responses: '200': description: Test results # ======================================== # Agent Bots Admin APIs # ======================================== /admin/agent-bots: get: tags: - Admin - Agent Bots summary: List all agent bots operationId: listAgentBots security: - sessionAuth: [] responses: '200': description: List of agent bots content: application/json: schema: type: object properties: agentBots: type: array items: $ref: '#/components/schemas/AgentBot' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - Agent Bots summary: Create agent bot operationId: createAgentBot security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [name] properties: name: type: string minLength: 2 maxLength: 100 slug: type: string description: type: string responses: '201': description: Agent bot created content: application/json: schema: type: object properties: agentBot: $ref: '#/components/schemas/AgentBot' '400': $ref: '#/components/responses/BadRequest' '409': description: Name or slug already exists /admin/agent-bots/{id}: parameters: - name: id in: path required: true schema: type: string format: uuid get: tags: - Admin - Agent Bots summary: Get agent bot details operationId: getAgentBot security: - sessionAuth: [] responses: '200': description: Agent bot details with versions and API keys content: application/json: schema: type: object properties: agentBot: $ref: '#/components/schemas/AgentBot' versions: type: array items: $ref: '#/components/schemas/AgentBotVersion' apiKeys: type: array items: $ref: '#/components/schemas/AgentBotApiKey' '404': $ref: '#/components/responses/NotFound' patch: tags: - Admin - Agent Bots summary: Update agent bot operationId: updateAgentBot security: - sessionAuth: [] requestBody: content: application/json: schema: type: object properties: name: type: string slug: type: string description: type: string is_active: type: boolean responses: '200': description: Agent bot updated '404': $ref: '#/components/responses/NotFound' '409': description: Name or slug already exists delete: tags: - Admin - Agent Bots summary: Delete agent bot operationId: deleteAgentBot security: - sessionAuth: [] responses: '200': description: Agent bot deleted '404': $ref: '#/components/responses/NotFound' /admin/agent-bots/{id}/versions: parameters: - name: id in: path required: true schema: type: string format: uuid get: tags: - Admin - Agent Bots summary: List versions operationId: listAgentBotVersions security: - sessionAuth: [] responses: '200': description: List of versions content: application/json: schema: type: object properties: versions: type: array items: $ref: '#/components/schemas/AgentBotVersion' '404': $ref: '#/components/responses/NotFound' post: tags: - Admin - Agent Bots summary: Create version operationId: createAgentBotVersion security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [input_schema, output_config] properties: version_label: type: string is_default: type: boolean input_schema: $ref: '#/components/schemas/InputSchema' output_config: $ref: '#/components/schemas/OutputConfig' system_prompt: type: string llm_model: type: string temperature: type: number max_tokens: type: integer category_ids: type: array items: type: integer skill_ids: type: array items: type: integer responses: '201': description: Version created '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' /admin/agent-bots/{id}/versions/{versionId}: parameters: - name: id in: path required: true schema: type: string format: uuid - name: versionId in: path required: true schema: type: string format: uuid get: tags: - Admin - Agent Bots summary: Get version details operationId: getAgentBotVersion security: - sessionAuth: [] responses: '200': description: Version details with relations '404': $ref: '#/components/responses/NotFound' patch: tags: - Admin - Agent Bots summary: Update version operationId: updateAgentBotVersion security: - sessionAuth: [] requestBody: content: application/json: schema: type: object properties: version_label: type: string is_default: type: boolean is_active: type: boolean input_schema: $ref: '#/components/schemas/InputSchema' output_config: $ref: '#/components/schemas/OutputConfig' system_prompt: type: string llm_model: type: string temperature: type: number max_tokens: type: integer responses: '200': description: Version updated '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - Agent Bots summary: Delete version operationId: deleteAgentBotVersion security: - sessionAuth: [] responses: '200': description: Version deleted '400': description: Cannot delete default version '404': $ref: '#/components/responses/NotFound' /admin/agent-bots/{id}/api-keys: parameters: - name: id in: path required: true schema: type: string format: uuid get: tags: - Admin - Agent Bots summary: List API keys operationId: listAgentBotApiKeys security: - sessionAuth: [] responses: '200': description: List of API keys content: application/json: schema: type: object properties: apiKeys: type: array items: $ref: '#/components/schemas/AgentBotApiKey' '404': $ref: '#/components/responses/NotFound' post: tags: - Admin - Agent Bots summary: Create API key description: The full key is only returned once in the response operationId: createAgentBotApiKey security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [name] properties: name: type: string minLength: 2 maxLength: 100 permissions: type: array items: type: string rate_limit_rpm: type: integer minimum: 1 maximum: 1000 default: 60 rate_limit_rpd: type: integer minimum: 1 maximum: 100000 default: 1000 expires_in_days: type: integer responses: '201': description: API key created content: application/json: schema: type: object properties: apiKey: $ref: '#/components/schemas/AgentBotApiKey' fullKey: type: string description: The full API key - only shown once '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' /admin/agent-bots/{id}/api-keys/{keyId}: parameters: - name: id in: path required: true schema: type: string format: uuid - name: keyId in: path required: true schema: type: string format: uuid delete: tags: - Admin - Agent Bots summary: Revoke API key operationId: revokeAgentBotApiKey security: - sessionAuth: [] responses: '200': description: API key revoked '400': description: API key already revoked '404': $ref: '#/components/responses/NotFound' /admin/agent-bots/{id}/analytics: parameters: - name: id in: path required: true schema: type: string format: uuid get: tags: - Admin - Agent Bots summary: Get usage analytics operationId: getAgentBotAnalytics security: - sessionAuth: [] parameters: - name: days in: query schema: type: integer default: 30 responses: '200': description: Usage analytics content: application/json: schema: type: object properties: summary: type: object properties: totalRequests: type: integer totalTokens: type: integer totalErrors: type: integer successRate: type: number avgProcessingTimeMs: type: integer dailyStats: type: array items: type: object byOutputType: type: object byStatus: type: object recentJobs: type: array items: type: object '404': $ref: '#/components/responses/NotFound' # ======================================== # Agent Bots Public API (API Key Auth) # ======================================== /agent-bots/spec: get: tags: - Agent Bots - Public summary: Discover agent bot metadata description: | Returns simplified metadata JSON for the agent bot associated with the provided API key. The API key itself identifies the bot — no slug or prior knowledge is required. Useful for external systems to auto-configure agent bot registration. operationId: discoverAgentBot security: - apiKeyAuth: [] responses: '200': description: Agent bot metadata content: application/json: schema: $ref: '#/components/schemas/AgentBotSpec' '401': description: Invalid or missing API key '404': description: Agent bot or version not found '429': description: Rate limit exceeded /agent-bots/{slug}/invoke: post: tags: - Agent Bots - Public summary: Invoke agent bot description: Execute an agent bot with provided input. Supports sync and async modes. operationId: invokeAgentBot security: - apiKeyAuth: [] parameters: - name: slug in: path required: true schema: type: string example: "hr-assistant" requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/InvokeRequest' responses: '200': description: Synchronous execution result content: application/json: schema: $ref: '#/components/schemas/InvokeResponse' headers: X-RateLimit-Limit-RPM: schema: type: integer X-RateLimit-Remaining-RPM: schema: type: integer X-RateLimit-Limit-RPD: schema: type: integer X-RateLimit-Remaining-RPD: schema: type: integer '202': description: Async job accepted content: application/json: schema: type: object properties: jobId: type: string status: type: string enum: [pending] '401': description: Invalid or missing API key '404': description: Agent bot or version not found '422': description: Input validation error '429': description: Rate limit exceeded /agent-bots/{slug}/upload: post: tags: - Agent Bots - Public summary: Upload file description: Upload a file to be used in an agent bot invocation. File must be referenced by ID in the invoke request. operationId: uploadAgentBotFile security: - apiKeyAuth: [] parameters: - name: slug in: path required: true schema: type: string example: "hr-assistant" requestBody: required: true content: multipart/form-data: schema: type: object properties: file: type: string format: binary description: "File to upload" responses: '200': description: File uploaded successfully content: application/json: schema: type: object properties: fileId: type: string example: "file_abc123" filename: type: string example: "document.pdf" mimeType: type: string example: "application/pdf" fileSize: type: integer example: 1048576 '400': description: Invalid file or upload disabled '401': description: Invalid or missing API key '404': description: Agent bot not found /agent-bots/{slug}/jobs/{jobId}: get: tags: - Agent Bots - Public summary: Get job status description: Get the status and results of an async job operationId: getAgentBotJob security: - apiKeyAuth: [] parameters: - name: slug in: path required: true schema: type: string example: "hr-assistant" - name: jobId in: path required: true schema: type: string example: "job_abc123" responses: '200': description: Job status content: application/json: schema: $ref: '#/components/schemas/JobStatus' '404': description: Job not found /agent-bots/{slug}/jobs/{jobId}/outputs/{outputId}/download: get: tags: - Agent Bots - Public summary: Download output description: Download a generated output file. Supports API key auth or admin session cookie (for Test tab downloads). operationId: downloadAgentBotOutput security: - apiKeyAuth: [] - sessionAuth: [] parameters: - name: slug in: path required: true schema: type: string example: "hr-assistant" - name: jobId in: path required: true schema: type: string example: "job_abc123" - name: outputId in: path required: true schema: type: string example: "out_xyz789" responses: '200': description: Binary file content content: application/octet-stream: schema: type: string format: binary '404': description: Output not found # ======================================== # Consolidated AI & API Setup APIs # ======================================== /admin/ai-setup: get: tags: - Admin - AI & API Setup summary: Get the consolidated AI and API setup overview description: | Returns the viewer and server-enforced organization scope, provider/capability registry, selected organization, health, redacted credentials, active credential count, and capability configuration. Raw credential values are never returned. Requires a global `super_admin` or `admin` role. A `super_admin` may select any visible organization with `orgId`; an `admin` is constrained to the organization resolved from the session and membership records. A client-supplied organization identifier is a display hint and never grants access. operationId: getAiSetupOverview security: - sessionAuth: [] parameters: - name: orgId in: query required: false description: Requested organization selection. Revalidated against the viewer's server-side scope. schema: type: integer responses: '200': description: Consolidated setup overview content: application/json: schema: $ref: '#/components/schemas/AiSetupOverview' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations: post: tags: - Admin - AI & API Setup summary: Create an organization description: | Creates an `ENTITY` or `INDIVIDUAL` organization. `DEFAULT` is rejected. The first member is automatically assigned `org_admin`; an `INDIVIDUAL` organization has exactly one member. `adminEmail` optionally delegates the initial `org_admin` role to an existing user. operationId: createAiSetupOrganization security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [name, type, credentialMode] properties: name: type: string minLength: 1 maxLength: 120 type: type: string enum: [ENTITY, INDIVIDUAL] description: "`DEFAULT` cannot be created through this API." credentialMode: type: string enum: [PLATFORM_MANAGED, ORGANIZATION_BYOK] adminEmail: type: string format: email description: "Existing user to make the first and active `org_admin`; defaults to the creator." responses: '201': description: Organization created and first member promoted content: application/json: schema: type: object required: [id, memberships] properties: id: type: integer memberships: type: array items: type: object required: [userId, role] properties: userId: type: integer role: type: string enum: [org_admin] '400': description: Invalid body, organization type, credential mode, name, or delegated user content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer patch: tags: - Admin - AI & API Setup summary: Update an organization description: | Updates the name and/or credential mode. Requires `super_admin`, or a global `admin` whose server-resolved membership is `org_admin` for this organization. operationId: updateAiSetupOrganization security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object minProperties: 1 properties: name: type: string minLength: 1 maxLength: 120 credentialMode: type: string enum: [PLATFORM_MANAGED, ORGANIZATION_BYOK] responses: '200': description: Updated organization content: application/json: schema: $ref: '#/components/schemas/AiSetupOrganization' '400': description: Invalid ID, body, name, credential mode, or empty update content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/capabilities: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer put: tags: - Admin - AI & API Setup summary: Save organization capability configuration description: | Upserts capability-to-provider/model/credential mappings for an organization. An item with an empty `providerId` clears that capability row. Provider IDs are validated against the server registry. Requires `super_admin` or the organization's server-resolved `org_admin`. operationId: putAiSetupCapabilities security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [capabilities] properties: capabilities: type: array items: $ref: '#/components/schemas/AiSetupCapabilityConfig' responses: '200': description: Capability configuration saved content: application/json: schema: type: object required: [ok, saved, cleared] properties: ok: type: boolean example: true saved: type: integer minimum: 0 cleared: type: integer minimum: 0 '400': description: Invalid ID/body, malformed capability, or unknown provider content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/credentials: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer get: tags: - Admin - AI & API Setup summary: List redacted organization credentials description: | Lists credential metadata for a visible organization. Secret ciphertext is not selected and raw credential values are never returned. Requires `super_admin`, or a global `admin` with a membership in its own organization. operationId: listAiSetupCredentials security: - sessionAuth: [] responses: '200': description: Redacted credential list content: application/json: schema: type: object required: [credentials] properties: credentials: type: array items: $ref: '#/components/schemas/AiSetupRedactedCredential' '400': description: Invalid organization ID content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' post: tags: - Admin - AI & API Setup summary: Create or replace an organization credential description: | Creates a credential when `credentialId` is omitted, or replaces an existing credential for the same organization and provider when it is supplied. The submitted `secret` is encrypted by the credential vault and is never returned. Requires `super_admin` or the organization's server-resolved `org_admin`. operationId: upsertAiSetupCredential security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [providerId, secret] properties: providerId: type: string secret: type: string format: password writeOnly: true minLength: 1 description: Raw credential accepted only on write; never echoed, logged, or returned. isDefault: type: boolean default: false credentialId: type: string description: Existing credential ID to replace. Omit to create a server-generated ID. responses: '200': description: Existing credential replaced content: application/json: schema: type: object required: [ok, action, credentialId, providerId] properties: ok: type: boolean example: true action: type: string enum: [replaced] credentialId: type: string providerId: type: string '201': description: Credential created content: application/json: schema: type: object required: [ok, action, credentialId, providerId] properties: ok: type: boolean example: true action: type: string enum: [created] credentialId: type: string providerId: type: string '400': description: Invalid ID/body, missing secret/provider, or unknown provider content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/credentials/{credentialId}: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer - name: credentialId in: path required: true schema: type: string post: tags: - Admin - AI & API Setup summary: Perform a credential action description: | Performs `test`, `replace`, `disable`, `enable`, or envelope-key `rotate`. Testing requires view access; all mutations require `super_admin` or the organization's server-resolved `org_admin`. Testing decrypts/resolves only on the server and returns availability, never the raw key. `replace` requires `secret`. operationId: actOnAiSetupCredential security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [action] properties: action: type: string enum: [test, replace, disable, enable, rotate] secret: type: string format: password writeOnly: true description: "Required only when `action` is `replace`; never returned." responses: '200': description: Action result. Test responses include provider and availability message; mutation responses include the action. content: application/json: schema: oneOf: - type: object required: [ok, providerId, message] properties: ok: type: boolean providerId: type: string message: type: string - type: object required: [ok, action] properties: ok: type: boolean example: true action: type: string enum: [replace, disable, enable, rotate] '400': description: Invalid ID, unknown action, or missing replacement secret content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/members: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer get: tags: - Admin - AI & API Setup summary: List organization members description: "Requires `super_admin` or a global `admin` with access to its own organization." operationId: listAiSetupMembers security: - sessionAuth: [] responses: '200': description: Organization member list content: application/json: schema: type: object required: [members] properties: members: type: array items: $ref: '#/components/schemas/AiSetupMember' '400': description: Invalid organization ID content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' post: tags: - Admin - AI & API Setup summary: Add a member or delegate organization administration description: | Adds/reactivates a user by numeric `userId` or existing-user `email`. Setting `role` to `org_admin` delegates administration and demotes the prior active administrator so exactly one remains. `INDIVIDUAL` organizations reject additional members, and the last active administrator cannot be silently demoted. Requires `super_admin` or the organization's server-resolved `org_admin`. operationId: addAiSetupMember security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object properties: userId: type: integer email: type: string format: email role: type: string enum: [org_admin, member] default: member description: "Supply `userId` or `email`. If both are supplied, `userId` is used." responses: '201': description: Member added/reactivated and role assigned content: application/json: schema: type: object required: [ok, userId, role] properties: ok: type: boolean example: true userId: type: integer role: type: string enum: [org_admin, member] '400': description: Invalid input, individual-organization member constraint, or last-admin invariant violation content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/members/{userId}: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer - name: userId in: path required: true schema: type: integer patch: tags: - Admin - AI & API Setup summary: Change an organization member role description: | Promoting a member delegates `org_admin` and demotes the previous active administrator. Demoting the last active `org_admin` is blocked. Requires `super_admin` or the organization's server-resolved `org_admin`. operationId: updateAiSetupMember security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [role] properties: role: type: string enum: [org_admin, member] responses: '200': description: Member role changed content: application/json: schema: type: object required: [ok, userId, role] properties: ok: type: boolean example: true userId: type: integer role: type: string enum: [org_admin, member] '400': description: Invalid ID/role or attempt to demote the last active administrator content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' delete: tags: - Admin - AI & API Setup summary: Remove an organization member description: | Removes a member. Removing the last active `org_admin` is blocked until a successor is assigned. Requires `super_admin` or the organization's server-resolved `org_admin`. operationId: deleteAiSetupMember security: - sessionAuth: [] responses: '200': description: Member removed content: application/json: schema: type: object required: [ok] properties: ok: type: boolean example: true '400': description: Invalid ID or attempt to remove the last active administrator content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/audit: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer get: tags: - Admin - AI & API Setup summary: Get an organization's credential audit log description: | Returns up to 500 newest credential audit entries for the organization. Entries contain redacted detail only. Requires `super_admin`, or a global `admin` scoped to its own organization. operationId: getAiSetupOrganizationAudit security: - sessionAuth: [] responses: '200': description: Redacted organization credential audit content: application/json: schema: type: object required: [entries] properties: entries: type: array maxItems: 500 items: $ref: '#/components/schemas/AiSetupAuditEntry' '400': description: Invalid organization ID content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/audit: get: tags: - Admin - AI & API Setup summary: Get the global credential audit log description: | Returns up to 500 newest organization credential audit entries across the platform. Every entry is redacted. This route requires global `super_admin`; a regular `admin`, including an `org_admin`, receives `403 FORBIDDEN`. operationId: getAiSetupGlobalAudit security: - sessionAuth: [] responses: '200': description: Redacted global credential audit content: application/json: schema: type: object required: [entries] properties: entries: type: array maxItems: 500 items: $ref: '#/components/schemas/AiSetupAuditEntry' '401': $ref: '#/components/responses/Unauthorized' '403': description: Global super administrator role required content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: Super admin access required for the global audit code: FORBIDDEN '500': $ref: '#/components/responses/InternalError' /admin/ai-setup/organizations/{id}/usage: parameters: - name: id in: path required: true description: Numeric organization ID. Server-side organization scope is always enforced. schema: type: integer get: tags: - Admin - AI & API Setup summary: Get organization-scoped token usage and cost description: | Returns usage attributed to the organization and credential for the selected interval. `days` defaults to 30, rejects non-numeric input, and clamps numeric values to 1–365. Visibility is server-enforced: `super_admin` can view all costs; an `org_admin` can view cost only for its own `ORGANIZATION_BYOK` organization with an active credential. Otherwise cost values are zeroed and `cost.reason` explains the denial or missing credential. operationId: getAiSetupOrganizationUsage security: - sessionAuth: [] parameters: - name: days in: query required: false description: Number of trailing days. Numeric values are clamped to 1–365. schema: type: integer default: 30 responses: '200': description: Organization usage and visibility-filtered cost content: application/json: schema: type: object required: [org, cost, usage] properties: org: $ref: '#/components/schemas/AiSetupOrganization' cost: type: object required: [canView, reason] properties: canView: type: boolean reason: type: string enum: [platform, org, denied, byok_missing_credential] usage: $ref: '#/components/schemas/AiSetupUsageSummary' '400': description: "Invalid organization ID or non-numeric `days`" content: application/json: schema: $ref: '#/components/schemas/ApiError' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' # ======================================== # LLM Management APIs # ======================================== /admin/llm/providers: get: tags: - Admin - LLM summary: List LLM providers operationId: listLLMProviders security: - sessionAuth: [] responses: '200': description: List of providers content: application/json: schema: type: object properties: providers: type: array items: $ref: '#/components/schemas/LLMProvider' '403': $ref: '#/components/responses/Forbidden' post: tags: - Admin - LLM summary: Create LLM provider description: | Legacy provider write. While the consolidated AI & API Setup feature is enabled, this route returns `409 LEGACY_WRITE_DISABLED`; create organization credentials through `/admin/ai-setup/organizations/{id}/credentials` instead. operationId: createLLMProvider security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [id, name] properties: id: type: string name: type: string apiKey: type: string apiBase: type: string enabled: type: boolean responses: '201': description: Provider created '409': description: Provider already exists, or this legacy write is disabled in favor of AI & API Setup content: application/json: schema: $ref: '#/components/schemas/ApiError' examples: legacyWriteDisabled: value: error: This legacy settings page is read-only. Configure provider keys and AI/API capabilities from the consolidated AI & API Setup page. code: LEGACY_WRITE_DISABLED /admin/llm/providers/{id}: parameters: - name: id in: path required: true schema: type: string get: tags: - Admin - LLM summary: Get provider details operationId: getLLMProvider security: - sessionAuth: [] responses: '200': description: Provider details '404': $ref: '#/components/responses/NotFound' put: tags: - Admin - LLM summary: Update provider description: | Legacy provider write. While the consolidated AI & API Setup feature is enabled, this route returns `409 LEGACY_WRITE_DISABLED`; replace organization credentials through `/admin/ai-setup/organizations/{id}/credentials` instead. operationId: updateLLMProvider security: - sessionAuth: [] requestBody: content: application/json: schema: type: object properties: name: type: string apiKey: type: string apiBase: type: string enabled: type: boolean responses: '200': description: Provider updated '404': $ref: '#/components/responses/NotFound' '409': description: Legacy provider writes are disabled in favor of AI & API Setup content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: This legacy settings page is read-only. Configure provider keys and AI/API capabilities from the consolidated AI & API Setup page. code: LEGACY_WRITE_DISABLED delete: tags: - Admin - LLM summary: Delete or clear provider description: | Core providers are cleared rather than deleted. While the consolidated AI & API Setup feature is enabled, this legacy write returns `409 LEGACY_WRITE_DISABLED`; use the organization credential actions instead. operationId: deleteLLMProvider security: - sessionAuth: [] responses: '200': description: Provider deleted or cleared '404': $ref: '#/components/responses/NotFound' '409': description: Legacy provider writes are disabled in favor of AI & API Setup content: application/json: schema: $ref: '#/components/schemas/ApiError' example: error: This legacy settings page is read-only. Configure provider keys and AI/API capabilities from the consolidated AI & API Setup page. code: LEGACY_WRITE_DISABLED /admin/llm/providers/{id}/test: post: tags: - Admin - LLM summary: Test provider connection operationId: testLLMProvider security: - sessionAuth: [] parameters: - name: id in: path required: true schema: type: string responses: '200': description: Test results content: application/json: schema: type: object properties: provider: type: string success: type: boolean message: type: string models: type: array items: type: string error: type: string /admin/llm/models: get: tags: - Admin - LLM summary: List enabled models operationId: listEnabledModels security: - sessionAuth: [] parameters: - name: active in: query schema: type: boolean description: If true, only return active models responses: '200': description: List of enabled models content: application/json: schema: type: object properties: models: type: array items: $ref: '#/components/schemas/EnabledModel' post: tags: - Admin - LLM summary: Enable models (batch) operationId: enableModels security: - sessionAuth: [] requestBody: required: true content: application/json: schema: type: object required: [models] properties: models: type: array items: type: object required: [id, providerId, displayName] properties: id: type: string providerId: type: string displayName: type: string isDefault: type: boolean isActive: type: boolean toolCapable: type: boolean visionCapable: type: boolean responses: '200': description: Models enabled content: application/json: schema: type: object properties: message: type: string models: type: array items: $ref: '#/components/schemas/EnabledModel' skipped: type: integer /admin/llm/models/{id}: parameters: - name: id in: path required: true schema: type: string get: tags: - Admin - LLM summary: Get model details operationId: getEnabledModel security: - sessionAuth: [] responses: '200': description: Model details '404': $ref: '#/components/responses/NotFound' put: tags: - Admin - LLM summary: Update model operationId: updateEnabledModel security: - sessionAuth: [] requestBody: content: application/json: schema: type: object properties: displayName: type: string isDefault: type: boolean isActive: type: boolean toolCapable: type: boolean visionCapable: type: boolean maxInputTokens: type: integer sortOrder: type: integer responses: '200': description: Model updated '404': $ref: '#/components/responses/NotFound' delete: tags: - Admin - LLM summary: Remove model operationId: removeEnabledModel security: - sessionAuth: [] responses: '200': description: Model removed '404': $ref: '#/components/responses/NotFound' /admin/llm/models/refresh: post: tags: - Admin - LLM summary: Refresh model capabilities operationId: refreshModelCapabilities security: - sessionAuth: [] responses: '200': description: Capabilities refreshed content: application/json: schema: type: object properties: success: type: boolean updated: type: integer models: type: array items: $ref: '#/components/schemas/EnabledModel' /admin/llm/discover: get: tags: - Admin - LLM summary: Discover available models operationId: discoverModels security: - sessionAuth: [] parameters: - name: provider in: query schema: type: string description: Specific provider ID, or omit for all providers responses: '200': description: Discovered models content: application/json: schema: type: object properties: success: type: boolean provider: type: string models: type: array items: type: string results: type: array items: type: object properties: provider: type: string success: type: boolean models: type: array items: type: string # ======================================== # Autonomous Plan Control APIs # ======================================== /autonomous/{planId}/pause: post: tags: - Autonomous summary: Pause autonomous plan description: Pause an active plan after the current task completes operationId: pauseAutonomousPlan security: - sessionAuth: [] parameters: - name: planId in: path required: true schema: type: string requestBody: content: application/json: schema: type: object properties: reason: type: string responses: '200': description: Plan paused content: application/json: schema: $ref: '#/components/schemas/AutonomousPlanResponse' '400': description: Cannot pause plan with current status '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /autonomous/{planId}/resume: post: tags: - Autonomous summary: Resume paused plan operationId: resumeAutonomousPlan security: - sessionAuth: [] parameters: - name: planId in: path required: true schema: type: string responses: '200': description: Plan resumed content: application/json: schema: $ref: '#/components/schemas/AutonomousPlanResponse' '400': description: Cannot resume plan with current status '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /autonomous/{planId}/stop: post: tags: - Autonomous summary: Stop autonomous plan description: Gracefully stop a plan, keeping all completed work operationId: stopAutonomousPlan security: - sessionAuth: [] parameters: - name: planId in: path required: true schema: type: string requestBody: content: application/json: schema: type: object properties: reason: type: string responses: '200': description: Plan stopped content: application/json: schema: $ref: '#/components/schemas/AutonomousPlanResponse' '400': description: Cannot stop plan with current status '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /autonomous/{planId}/tasks/{taskId}/skip: post: tags: - Autonomous summary: Skip task in plan operationId: skipAutonomousTask security: - sessionAuth: [] parameters: - name: planId in: path required: true schema: type: string - name: taskId in: path required: true schema: type: integer requestBody: content: application/json: schema: type: object properties: reason: type: string responses: '200': description: Task skipped content: application/json: schema: type: object properties: success: type: boolean task_id: type: integer status: type: string message: type: string '400': description: Cannot skip task with current status '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound'