{
  "openapi": "3.1.0",
  "info": {
    "title": "Open4X API",
    "version": "2026.08.15",
    "description": "Versioned contract for the Open4X API gateway and its AI, Webhook Push, TRON Energy and SocialOps services. API keys are scoped per service; sandbox environments return dry-run results for external side effects. Service terms and public policy links are published separately before P3 launch."
  },
  "servers": [
    {
      "url": "https://api.open4x.com",
      "description": "Production API (use a separately configured staging URL for internal testing)"
    }
  ],
  "tags": [
    { "name": "Health" },
    { "name": "Auth" },
    { "name": "AI" },
    { "name": "Webhook Push" },
    { "name": "TRON" },
    { "name": "SocialOps" },
    { "name": "Bot" },
    { "name": "File" },
    { "name": "Billing" },
    { "name": "Jobs" },
    { "name": "Operations" },
    { "name": "Conversation Hub" }
  ],
  "security": [
    { "apiKeyAuth": [] },
    { "bearerAuth": [] }
  ],
  "paths": {
    "/v1/conversations/credentials/status": {
      "get": {
        "operationId": "getConversationCredentialStatus",
        "tags": ["Conversation Hub"],
        "responses": {
          "200": {
            "description": "Redacted API key policy metadata; secret material is never returned",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/conversations": {
      "get": {
        "operationId": "listConversations",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/Limit" }],
        "responses": { "200": { "description": "Tenant conversations" }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      },
      "post": {
        "operationId": "createConversation",
        "tags": ["Conversation Hub"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationCreateRequest" } } } },
        "responses": { "201": { "description": "Conversation created" }, "200": { "description": "Conversation upserted" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/inbox": {
      "get": {
        "operationId": "listConversationInbox",
        "tags": ["Conversation Hub"],
        "parameters": [
          { "$ref": "#/components/parameters/Limit" },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["open", "pending", "resolved", "closed", "archived"] } },
          { "name": "priority", "in": "query", "schema": { "type": "string", "enum": ["low", "normal", "high", "urgent"] } },
          { "name": "assignee_external_id", "in": "query", "schema": { "type": "string", "maxLength": 200 } }
        ],
        "responses": { "200": { "description": "Conversation queue for a custom workbench" } }
      }
    },
    "/v1/conversations/{id}": {
      "get": {
        "operationId": "getConversation",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "responses": { "200": { "description": "Conversation with channels and participants" }, "404": { "$ref": "#/components/responses/NotFound" } }
      },
      "patch": {
        "operationId": "updateConversation",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationPatchRequest" } } } },
        "responses": { "200": { "description": "Conversation state updated" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/{id}/assignments": {
      "get": {
        "operationId": "listConversationAssignments",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "responses": { "200": { "description": "Conversation assignees" } }
      },
      "post": {
        "operationId": "assignConversation",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationAssignmentRequest" } } } },
        "responses": { "201": { "description": "Conversation assigned" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/{id}/assignments/{assignmentId}": {
      "delete": {
        "operationId": "unassignConversation",
        "tags": ["Conversation Hub"],
        "parameters": [
          { "$ref": "#/components/parameters/ConversationId" },
          { "$ref": "#/components/parameters/AssignmentId" }
        ],
        "responses": { "200": { "description": "Conversation assignment ended" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/v1/conversations/{id}/presence": {
      "get": {
        "operationId": "listConversationPresence",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "responses": { "200": { "description": "Current participant presence" } }
      },
      "post": {
        "operationId": "updateConversationPresence",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationPresenceRequest" } } } },
        "responses": { "200": { "description": "Presence updated" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/{id}/channels": {
      "post": {
        "operationId": "linkConversationChannel",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationChannelRequest" } } } },
        "responses": { "201": { "description": "Channel linked" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/{id}/messages": {
      "get": {
        "operationId": "listConversationMessages",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }, { "$ref": "#/components/parameters/Limit" }, { "$ref": "#/components/parameters/Cursor" }],
        "responses": { "200": { "description": "Conversation messages" }, "404": { "$ref": "#/components/responses/NotFound" } }
      },
      "post": {
        "operationId": "createConversationMessage",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }, { "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationMessageRequest" } } } },
        "responses": { "201": { "description": "Message accepted" }, "200": { "description": "Idempotent replay" }, "409": { "$ref": "#/components/responses/Conflict" } }
      }
    },
    "/v1/conversations/{id}/deliveries": {
      "get": {
        "operationId": "listConversationDeliveries",
        "tags": ["Conversation Hub"],
        "parameters": [
          { "$ref": "#/components/parameters/ConversationId" },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["pending", "processing", "retrying", "delivered", "dead_letter"] } }
        ],
        "responses": { "200": { "description": "Channel delivery attempts" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/v1/conversations/{id}/messages/{messageId}/receipts": {
      "get": {
        "operationId": "listConversationMessageReceipts",
        "tags": ["Conversation Hub"],
        "parameters": [
          { "$ref": "#/components/parameters/ConversationId" },
          { "$ref": "#/components/parameters/ConversationMessageId" }
        ],
        "responses": { "200": { "description": "Message delivery and read receipts" }, "404": { "$ref": "#/components/responses/NotFound" } }
      },
      "post": {
        "operationId": "createConversationMessageReceipt",
        "tags": ["Conversation Hub"],
        "parameters": [
          { "$ref": "#/components/parameters/ConversationId" },
          { "$ref": "#/components/parameters/ConversationMessageId" }
        ],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationReceiptRequest" } } } },
        "responses": { "200": { "description": "Receipt accepted" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/{id}/widget-session": {
      "post": {
        "operationId": "createConversationWidgetSession",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/ConversationId" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WidgetSessionRequest" } } } },
        "responses": { "201": { "description": "Short-lived Widget session" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/events": {
      "get": {
        "operationId": "listConversationEvents",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/Limit" }, { "$ref": "#/components/parameters/Cursor" }],
        "responses": { "200": { "description": "Tenant event feed with an opaque cursor" } }
      }
    },
    "/v1/conversations/events/{eventId}/replay": {
      "post": {
        "operationId": "replayConversationEvent",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/EventId" }],
        "responses": { "200": { "description": "Event replay queued" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/v1/conversations/webhooks": {
      "get": { "operationId": "listConversationWebhooks", "tags": ["Conversation Hub"], "responses": { "200": { "description": "Registered event webhooks" } } },
      "post": {
        "operationId": "registerConversationWebhook",
        "tags": ["Conversation Hub"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversationWebhookRequest" } } } },
        "responses": { "201": { "description": "Webhook registered" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/webhooks/{id}": {
      "delete": {
        "operationId": "revokeConversationWebhook",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/WebhookId" }],
        "responses": { "200": { "description": "Webhook revoked" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/v1/conversations/telegram/identities": {
      "get": { "operationId": "listTelegramIdentities", "tags": ["Conversation Hub"], "responses": { "200": { "description": "Tenant Telegram identities" } } }
    },
    "/v1/conversations/telegram/identities/bind": {
      "post": {
        "operationId": "createTelegramBinding",
        "tags": ["Conversation Hub"],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TelegramBindingRequest" } } } },
        "responses": { "201": { "description": "One-time Telegram binding link" }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/conversations/telegram/identities/{id}": {
      "delete": {
        "operationId": "unbindTelegramIdentity",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/IdentityId" }],
        "responses": { "200": { "description": "Telegram identity unbound" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/v1/conversations/attachments/{attachmentId}/scan-result": {
      "post": {
        "operationId": "updateConversationAttachmentScanResult",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/AttachmentId" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AttachmentScanResultRequest" } } } },
        "responses": { "200": { "description": "Attachment scan state updated" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/v1/conversations/deliveries/{deliveryId}/retry": {
      "post": {
        "operationId": "retryConversationDelivery",
        "tags": ["Conversation Hub"],
        "parameters": [{ "$ref": "#/components/parameters/DeliveryId" }],
        "responses": { "200": { "description": "Dead-letter delivery queued for retry" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "security": [],
        "responses": {
          "200": {
            "description": "Gateway and database health",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Health" }
              }
            }
          },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/auth/login": {
      "post": {
        "operationId": "login",
        "tags": ["Auth"],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/LoginRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authenticated session",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuthResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/auth/refresh": {
      "post": {
        "operationId": "refreshSession",
        "tags": ["Auth"],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["refresh_token"],
                "properties": {
                  "refresh_token": { "type": "string", "minLength": 1 }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rotated session tokens",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuthResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/apps/bot": {
      "post": {
        "operationId": "sendBotMessage",
        "tags": ["Bot"],
        "description": "Send a Telegram bot message or interactive card. API keys require bot:send. Sandbox environments return a dry-run response without provider side effects.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BotSendRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Message accepted", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "202": { "description": "Sandbox dry-run accepted", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMutationResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/bot/actions": {
      "get": {
        "operationId": "listBotActions",
        "tags": ["Bot"],
        "responses": {
          "200": { "description": "Available bot actions", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotActionsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/bot/execute": {
      "post": {
        "operationId": "executeBotAction",
        "tags": ["Bot"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BotExecuteRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Action result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/apps/bot/chats": {
      "get": {
        "operationId": "listBotChats",
        "tags": ["Bot"],
        "parameters": [
          { "$ref": "#/components/parameters/Cursor" },
          { "$ref": "#/components/parameters/Limit" }
        ],
        "responses": {
          "200": { "description": "Tenant-scoped Telegram and widget chats", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotChatsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/bot/chats/{chatId}/messages": {
      "get": {
        "operationId": "listBotChatMessages",
        "tags": ["Bot"],
        "parameters": [
          { "$ref": "#/components/parameters/ChatId" },
          { "$ref": "#/components/parameters/Limit" },
          { "$ref": "#/components/parameters/BeforeId" }
        ],
        "responses": {
          "200": { "description": "Chat messages in chronological order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMessagesResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/bot/messages/{id}": {
      "patch": {
        "operationId": "editBotMessage",
        "tags": ["Bot"],
        "parameters": [{ "$ref": "#/components/parameters/MessageId" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMessagePatch" } } }
        },
        "responses": {
          "200": { "description": "Assistant message updated", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMutationResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      },
      "delete": {
        "operationId": "deleteBotMessage",
        "tags": ["Bot"],
        "parameters": [{ "$ref": "#/components/parameters/MessageId" }],
        "responses": {
          "200": { "description": "Assistant message deleted", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMutationResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/apps/bot/messages/reply": {
      "post": {
        "operationId": "replyToBotMessage",
        "tags": ["Bot"],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotReplyRequest" } } }
        },
        "responses": {
          "200": { "description": "Reply sent", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotReplyResponse" } } } },
          "202": { "description": "Sandbox dry-run reply", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotReplyResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/bot/messages/send-file": {
      "post": {
        "operationId": "sendBotFile",
        "tags": ["Bot"],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["chat_id", "file"],
                "properties": {
                  "chat_id": { "type": "string", "minLength": 1 },
                  "caption": { "type": "string", "maxLength": 1024 },
                  "file": { "type": "string", "format": "binary" }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "File message sent", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotSendFileResponse" } } } },
          "202": { "description": "Sandbox dry-run", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMutationResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/bot/files/{fileId}": {
      "get": {
        "operationId": "downloadBotFile",
        "tags": ["Bot"],
        "parameters": [{ "$ref": "#/components/parameters/FileId" }],
        "responses": {
          "200": { "description": "File stream", "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } } },
          "202": { "description": "Sandbox cache-miss response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/bot/interactions": {
      "get": {
        "operationId": "listBotInteractions",
        "tags": ["Bot"],
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/Limit" },
          { "$ref": "#/components/parameters/InteractionStatus" },
          { "$ref": "#/components/parameters/Since" }
        ],
        "responses": {
          "200": { "description": "Tenant-scoped interaction records", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotInteractionsResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      },
      "post": {
        "operationId": "createBotInteraction",
        "tags": ["Bot"],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotInteractionRequest" } } }
        },
        "responses": {
          "200": { "description": "Interactive message created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMutationResponse" } } } },
          "202": { "description": "Sandbox dry-run", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BotMutationResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/bot/interactions/{id}": {
      "get": {
        "operationId": "getBotInteraction",
        "tags": ["Bot"],
        "parameters": [{ "$ref": "#/components/parameters/ResourceId" }],
        "responses": {
          "200": { "description": "Tenant-owned interaction", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/apps/file/upload": {
      "put": {
        "operationId": "uploadFile",
        "tags": ["File"],
        "description": "Upload raw bytes to the configured file service. The canonical method is PUT; the gateway also accepts POST for legacy clients. API keys require file:read.",
        "parameters": [
          { "$ref": "#/components/parameters/ExpiresIn" },
          { "$ref": "#/components/parameters/MaxDownloads" },
          { "$ref": "#/components/parameters/FileName" }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } }
        },
        "responses": {
          "200": { "description": "File uploaded", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FileUploadResponse" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/v1/apps/file/list": {
      "get": {
        "operationId": "listFiles",
        "tags": ["File"],
        "responses": {
          "200": { "description": "Tenant-owned file metadata", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FileListResponse" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/v1/apps/file/download/{file_id}": {
      "get": {
        "operationId": "downloadFile",
        "tags": ["File"],
        "security": [],
        "description": "Public download endpoint. Anonymous access is allowed for public files; an optional valid JWT is used to authorize private files. Client-supplied identity headers are never trusted.",
        "parameters": [{ "$ref": "#/components/parameters/FileIdPath" }],
        "responses": {
          "200": { "description": "File stream", "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "410": { "description": "File expired", "content": { "text/plain": { "schema": { "type": "string" } } } },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/v1/apps/file/share/{file_id}": {
      "get": {
        "operationId": "shareFile",
        "tags": ["File"],
        "security": [],
        "description": "Public HTML share page. An optional valid JWT is used to authorize private files.",
        "parameters": [{ "$ref": "#/components/parameters/FileIdPath" }],
        "responses": {
          "200": { "description": "HTML share page", "content": { "text/html": { "schema": { "type": "string" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/console/keys": {
      "get": {
        "operationId": "listApiKeys",
        "tags": ["Auth"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/Limit" }
        ],
        "responses": {
          "200": {
            "description": "API key metadata without plaintext secrets",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiKeyListResponse" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "operationId": "createApiKey",
        "tags": ["Auth"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateApiKeyRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created key; plaintext is returned once",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreateApiKeyResponse" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/console/keys/{id}/rotate": {
      "post": {
        "operationId": "rotateApiKey",
        "tags": ["Auth"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "$ref": "#/components/parameters/ResourceId" }],
        "responses": {
          "201": {
            "description": "Replacement key; plaintext is returned once",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreateApiKeyResponse" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      }
    },
    "/console/keys/{id}": {
      "delete": {
        "operationId": "revokeApiKey",
        "tags": ["Auth"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "$ref": "#/components/parameters/ResourceId" }],
        "responses": {
          "200": { "description": "API key revoked", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      }
    },
    "/console/billing/checkout": {
      "post": {
        "operationId": "createPaymentIntent",
        "tags": ["Billing"],
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PaymentCheckoutRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Payment intent created",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaymentIntentResponse" } } }
          },
          "200": {
            "description": "Existing intent reused for the idempotency key",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaymentIntentResponse" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/console/billing/payment-intents/{id}": {
      "get": {
        "operationId": "getPaymentIntent",
        "tags": ["Billing"],
        "parameters": [{ "$ref": "#/components/parameters/ResourceId" }],
        "responses": {
          "200": {
            "description": "Tenant-owned payment intent",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PaymentIntentResponse" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/payments/webhooks/{provider}": {
      "post": {
        "operationId": "receivePaymentWebhook",
        "tags": ["Billing"],
        "security": [],
        "parameters": [{ "$ref": "#/components/parameters/Provider" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PaymentWebhook" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed payment event accepted or deduplicated",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/v1/apps/ai/{alias}/chat": {
      "post": {
        "operationId": "chat",
        "tags": ["AI"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible chat response",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChatResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/chat/stream": {
      "post": {
        "operationId": "chatStream",
        "tags": ["AI"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Server-sent OpenAI-compatible stream",
            "content": {
              "text/event-stream": {
                "schema": { "type": "string" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/embeddings": {
      "post": {
        "operationId": "createEmbeddings",
        "tags": ["AI"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EmbeddingRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible embeddings response",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/models": {
      "get": {
        "operationId": "listModels",
        "tags": ["AI"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "responses": {
          "200": {
            "description": "Available models without provider credentials",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/v1/chat/completions": {
      "post": {
        "operationId": "openAiChatCompletions",
        "tags": ["AI"],
        "description": "OpenAI-compatible alias for chat. Set stream=true for text/event-stream output.",
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatRequest" } } }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible JSON or SSE response",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ChatResponse" } },
              "text/event-stream": { "schema": { "type": "string" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/chat/completions": {
      "post": {
        "operationId": "openAiChatCompletionsLegacy",
        "tags": ["AI"],
        "description": "Legacy OpenAI-compatible alias for chat. Prefer /v1/chat/completions for new integrations.",
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatRequest" } } }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible JSON or SSE response",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ChatResponse" } },
              "text/event-stream": { "schema": { "type": "string" } }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/v1/embeddings": {
      "post": {
        "operationId": "openAiEmbeddings",
        "tags": ["AI"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EmbeddingRequest" } } }
        },
        "responses": {
          "200": { "description": "OpenAI-compatible embeddings response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/ai/{alias}/v1/models": {
      "get": {
        "operationId": "openAiListModels",
        "tags": ["AI"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "responses": {
          "200": { "description": "OpenAI-compatible model list", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/webhook-push/{alias}/send": {
      "post": {
        "operationId": "sendWebhookPush",
        "tags": ["Webhook Push"],
        "parameters": [{ "$ref": "#/components/parameters/Alias" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/WebhookPushRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All enabled targets succeeded or sandbox dry-run completed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WebhookPushResponse" }
              }
            }
          },
          "207": {
            "description": "Some targets succeeded",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WebhookPushResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    },
    "/v1/apps/tron/quote": {
      "post": {
        "operationId": "quoteTronLease",
        "tags": ["TRON"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/TronLeaseRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Price quote valid for a short period",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/TronQuoteResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/tron/lease": {
      "post": {
        "operationId": "createTronLease",
        "tags": ["TRON"],
        "parameters": [{ "$ref": "#/components/parameters/TronIdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  { "$ref": "#/components/schemas/TronLeaseRequest" },
                  {
                    "type": "object",
                    "properties": {
                      "quote_id": { "type": "string" },
                      "max_cost": { "type": "number", "minimum": 0 }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Lease accepted or sandbox dry-run completed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/TronLeaseResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientBalance" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      }
    },
    "/v1/apps/tron/leases": {
      "get": {
        "operationId": "listTronLeases",
        "tags": ["TRON"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 }
          }
        ],
        "responses": {
          "200": {
            "description": "Lease orders for the authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/TronLease" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/tron/leases/{id}": {
      "get": {
        "operationId": "getTronLease",
        "tags": ["TRON"],
        "parameters": [{ "$ref": "#/components/parameters/ResourceId" }],
        "responses": {
          "200": {
            "description": "Lease order",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/TronLease" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/jobs": {
      "get": {
        "operationId": "listAsyncJobs",
        "tags": ["Jobs"],
        "parameters": [
          { "$ref": "#/components/parameters/Limit" },
          {
            "name": "status",
            "in": "query",
            "schema": { "type": "string", "enum": ["pending", "running", "succeeded", "failed", "canceled", "expired"] }
          }
        ],
        "responses": {
          "200": {
            "description": "Asynchronous jobs owned by the authenticated tenant",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AsyncJobListResponse" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/jobs/{id}": {
      "get": {
        "operationId": "getAsyncJob",
        "tags": ["Jobs"],
        "parameters": [{ "$ref": "#/components/parameters/JobId" }],
        "responses": {
          "200": {
            "description": "Asynchronous job status",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AsyncJobResponse" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/console/requests/{request_id}": {
      "get": {
        "operationId": "getRequestTrace",
        "tags": ["Operations"],
        "parameters": [{ "$ref": "#/components/parameters/RequestId" }],
        "responses": {
          "200": {
            "description": "Owner-scoped operational metadata for a gateway request",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RequestTraceResponse" } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/apps/socialops/providers": {
      "get": {
        "operationId": "listSocialOpsProviderCapabilities",
        "tags": ["SocialOps"],
        "responses": {
          "200": {
            "description": "Provider capability and rollout status catalog",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenericObject" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/socialops/{alias}/webhook/{provider}": {
      "post": {
        "operationId": "ingestSocialOpsEvent",
        "tags": ["SocialOps"],
        "parameters": [
          { "$ref": "#/components/parameters/Alias" },
          { "$ref": "#/components/parameters/Provider" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SocialOpsEvent" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event accepted or deduplicated",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/socialops/{alias}/inbox": {
      "get": {
        "operationId": "listSocialOpsInbox",
        "tags": ["SocialOps"],
        "parameters": [
          { "$ref": "#/components/parameters/Alias" },
          {
            "name": "page",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "default": 1 }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 }
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped SocialOps inbox",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/v1/apps/socialops/{alias}/threads": {
      "get": {
        "operationId": "listSocialOpsThreads",
        "tags": ["SocialOps"],
        "parameters": [
          { "$ref": "#/components/parameters/Alias" },
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/Limit" },
          { "$ref": "#/components/parameters/SocialOpsStatus" },
          { "$ref": "#/components/parameters/SocialOpsPriority" },
          { "$ref": "#/components/parameters/ProviderFilter" },
          { "$ref": "#/components/parameters/Search" }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped SocialOps threads with pagination and optional filters",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/apps/socialops/{alias}/threads/{thread_id}/messages": {
      "get": {
        "operationId": "listSocialOpsMessages",
        "tags": ["SocialOps"],
        "parameters": [
          { "$ref": "#/components/parameters/Alias" },
          { "$ref": "#/components/parameters/ThreadId" }
        ],
        "responses": {
          "200": {
            "description": "Messages belonging to the tenant-scoped thread",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/apps/socialops/{alias}/threads/{thread_id}/replies": {
      "post": {
        "operationId": "replyToSocialOpsThread",
        "tags": ["SocialOps"],
        "parameters": [
          { "$ref": "#/components/parameters/Alias" },
          { "$ref": "#/components/parameters/ThreadId" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["text"],
                "properties": {
                  "text": { "type": "string", "minLength": 1, "maxLength": 4000 }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Reply accepted or recorded as a sandbox dry-run",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenericObject" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "502": { "$ref": "#/components/responses/UpstreamFailed" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "A tenant API key with the scope required by the endpoint. The same key may be supplied as a Bearer API key for OpenAI-compatible clients."
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "parameters": {
      "Alias": {
        "name": "alias",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,80}$" }
      },
      "Provider": {
        "name": "provider",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^[a-z0-9-]{1,40}$" }
      },
      "ResourceId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "minLength": 1, "maxLength": 160 }
      },
      "JobId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^job_[A-Za-z0-9-]{20,100}$" }
      },
      "RequestId": {
        "name": "request_id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      },
      "ThreadId": {
        "name": "thread_id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "minLength": 1, "maxLength": 160 }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": { "type": "string", "pattern": "^[A-Za-z0-9._:-]{8,128}$" },
        "description": "Stable per-client payment attempt key. Reusing it with different amount/currency returns 409."
      },
      "TronIdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": { "type": "string", "pattern": "^[A-Za-z0-9._:-]{8,128}$" },
        "description": "Optional stable lease request key. Reusing it with different lease parameters returns 409; a matching retry replays the existing order."
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "schema": { "type": "string", "format": "date-time" },
        "description": "Return chats older than this ISO timestamp."
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 }
      },
      "Page": {
        "name": "page",
        "in": "query",
        "schema": { "type": "integer", "minimum": 1, "default": 1 }
      },
      "BeforeId": {
        "name": "before_id",
        "in": "query",
        "schema": { "type": "string", "minLength": 1, "maxLength": 160 }
      },
      "ChatId": {
        "name": "chatId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "minLength": 1, "maxLength": 200 }
      },
      "MessageId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "minLength": 1, "maxLength": 160 }
      },
      "ConversationId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^conv_[A-Za-z0-9-]{20,100}$" }
      },
      "ConversationMessageId": {
        "name": "messageId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^msg_[A-Za-z0-9-]{20,100}$" }
      },
      "AssignmentId": {
        "name": "assignmentId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^assign_[A-Za-z0-9-]{20,100}$" }
      },
      "AttachmentId": {
        "name": "attachmentId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^att_[A-Za-z0-9-]{20,100}$" }
      },
      "DeliveryId": {
        "name": "deliveryId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^cmdel_[A-Za-z0-9-]{20,100}$" }
      },
      "EventId": {
        "name": "eventId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^evt_[A-Za-z0-9-]{20,100}$" }
      },
      "WebhookId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^cwh_[A-Za-z0-9-]{20,100}$" }
      },
      "IdentityId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^tid_[A-Za-z0-9-]{20,100}$" }
      },
      "ConversationIdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": { "type": "string", "minLength": 8, "maxLength": 128 },
        "description": "Optional transport idempotency key. Message-level retries should also send client_message_id."
      },
      "FileId": {
        "name": "fileId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{10,256}$" }
      },
      "FileIdPath": {
        "name": "file_id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "minLength": 1, "maxLength": 512 },
        "description": "URL-encoded file identifier; identifiers containing a slash must be percent-encoded."
      },
      "InteractionStatus": {
        "name": "status",
        "in": "query",
        "schema": { "type": "string", "enum": ["pending", "delivered", "replied", "failed"] }
      },
      "SocialOpsStatus": {
        "name": "status",
        "in": "query",
        "schema": { "type": "string", "enum": ["open", "pending", "resolved", "archived"] }
      },
      "SocialOpsPriority": {
        "name": "priority",
        "in": "query",
        "schema": { "type": "string", "enum": ["low", "normal", "high", "urgent"] }
      },
      "ProviderFilter": {
        "name": "provider",
        "in": "query",
        "schema": { "type": "string", "enum": ["generic-webhook", "telegram", "github", "discord", "slack", "teams", "whatsapp", "line", "instagram"] }
      },
      "Search": {
        "name": "q",
        "in": "query",
        "schema": { "type": "string", "maxLength": 120 }
      },
      "Since": {
        "name": "since",
        "in": "query",
        "schema": { "type": "string", "format": "date-time" }
      },
      "ExpiresIn": {
        "name": "x-expires-in",
        "in": "header",
        "schema": { "type": "integer", "minimum": 1 },
        "description": "Optional file lifetime in seconds."
      },
      "MaxDownloads": {
        "name": "x-max-downloads",
        "in": "header",
        "schema": { "type": "integer", "minimum": 1 },
        "description": "Optional maximum number of downloads."
      },
      "FileName": {
        "name": "x-filename",
        "in": "header",
        "schema": { "type": "string", "maxLength": 255 },
        "description": "Optional original filename."
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Request validation failed",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Unauthorized": {
        "description": "Missing or invalid authentication",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Forbidden": {
        "description": "Credential is not allowed to use this endpoint",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "InsufficientBalance": {
        "description": "Tenant balance is insufficient",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "NotFound": {
        "description": "Resource was not found",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Conflict": {
        "description": "Request conflicts with an idempotency key, quote or resource state",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "UpstreamFailed": {
        "description": "Configured provider failed or returned an invalid response",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "ServiceUnavailable": {
        "description": "Gateway dependency is unavailable",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "ConversationCreateRequest": {
        "type": "object",
        "required": ["external_conversation_id"],
        "properties": {
          "external_conversation_id": { "type": "string", "maxLength": 240 },
          "conversation_type": { "type": "string", "default": "general_support" },
          "context_type": { "type": ["string", "null"], "maxLength": 64 },
          "context_id": { "type": ["string", "null"], "maxLength": 240 },
          "priority": { "type": "string", "enum": ["low", "normal", "high", "urgent"], "default": "normal" },
          "locale": { "type": ["string", "null"], "maxLength": 32 },
          "metadata": { "type": "object", "additionalProperties": true },
          "participants": { "type": "array", "maxItems": 50, "items": { "type": "object", "additionalProperties": true } }
        },
        "additionalProperties": false
      },
      "ConversationChannelRequest": {
        "type": "object",
        "required": ["channel_type", "provider", "external_channel_id"],
        "properties": {
          "channel_type": { "type": "string", "maxLength": 64 },
          "provider": { "type": "string", "maxLength": 64 },
          "external_channel_id": { "type": "string", "maxLength": 240 },
          "connected_account_id": { "type": ["string", "null"] },
          "metadata": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": false
      },
      "ConversationPatchRequest": {
        "type": "object",
        "minProperties": 1,
        "properties": {
          "status": { "type": "string", "enum": ["open", "pending", "resolved", "closed", "archived"] },
          "priority": { "type": "string", "enum": ["low", "normal", "high", "urgent"] },
          "locale": { "type": ["string", "null"], "maxLength": 32 }
        },
        "additionalProperties": false
      },
      "ConversationAssignmentRequest": {
        "type": "object",
        "required": ["assignee_external_id", "assignee_role"],
        "properties": {
          "assignee_external_id": { "type": "string", "maxLength": 200 },
          "assignee_role": { "type": "string", "enum": ["creator", "support_agent"] },
          "assigned_by": { "type": ["string", "null"], "maxLength": 200 },
          "replace_active_role": { "type": "boolean", "default": false },
          "metadata": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": false
      },
      "ConversationPresenceRequest": {
        "type": "object",
        "required": ["external_participant_id", "role", "status"],
        "properties": {
          "external_participant_id": { "type": "string", "maxLength": 200 },
          "role": { "type": "string", "enum": ["customer", "creator", "support_agent", "ai_assistant", "system"] },
          "status": { "type": "string", "enum": ["online", "away", "offline", "typing"] },
          "ttl_seconds": { "type": "integer", "minimum": 5, "maximum": 120 },
          "metadata": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": false
      },
      "ConversationReceiptRequest": {
        "type": "object",
        "required": ["external_participant_id", "status"],
        "properties": {
          "external_participant_id": { "type": "string", "maxLength": 200 },
          "status": { "type": "string", "enum": ["sent", "delivered", "read"] },
          "metadata": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": false
      },
      "ConversationAttachment": {
        "type": "object",
        "required": ["filename", "mime_type", "byte_size"],
        "properties": {
          "storage_key": { "type": ["string", "null"], "maxLength": 512 },
          "download_url": { "type": ["string", "null"], "format": "uri", "pattern": "^https://" },
          "filename": { "type": "string", "maxLength": 255 },
          "mime_type": { "type": "string", "maxLength": 128 },
          "byte_size": { "type": "integer", "minimum": 0, "maximum": 26214400 },
          "expires_at": { "type": ["string", "null"] },
          "metadata": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": false,
        "description": "Tenant-owned storage reference. Open4X never fetches arbitrary URLs; new attachments start in pending scan state."
      },
      "AttachmentScanResultRequest": {
        "type": "object",
        "required": ["scan_status"],
        "properties": {
          "scan_status": { "type": "string", "enum": ["pending", "clean", "blocked"] }
        },
        "additionalProperties": false
      },
      "ConversationMessageRequest": {
        "type": "object",
        "required": ["channel_type", "text"],
        "properties": {
          "channel_type": { "type": "string", "maxLength": 64 },
          "sender_role": { "type": "string", "enum": ["customer", "creator", "support_agent", "ai_assistant", "system", "internal_note"] },
          "visibility": { "type": "string", "enum": ["public", "internal"] },
          "direction": { "type": "string", "enum": ["inbound", "outbound"] },
          "text": { "type": "string", "maxLength": 8000 },
          "client_message_id": { "type": ["string", "null"], "maxLength": 200 },
          "reply_to_message_id": { "type": ["string", "null"], "maxLength": 240 },
          "source_channel_id": { "type": ["string", "null"] },
          "sender_participant_id": { "type": ["string", "null"] },
          "attachments": { "type": "array", "maxItems": 10, "items": { "$ref": "#/components/schemas/ConversationAttachment" } },
          "metadata": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": false
      },
      "WidgetSessionRequest": {
        "type": "object",
        "required": ["external_user_id"],
        "properties": {
          "external_user_id": { "type": "string", "maxLength": 200 },
          "user_name": { "type": "string", "maxLength": 200 },
          "chat_id": { "type": "string", "maxLength": 240 },
          "ttl_seconds": { "type": "integer", "minimum": 900, "maximum": 3600 }
        },
        "additionalProperties": false
      },
      "ConversationWebhookRequest": {
        "type": "object",
        "required": ["url", "secret"],
        "properties": {
          "url": { "type": "string", "format": "uri", "pattern": "^https://" },
          "secret": { "type": "string", "minLength": 16, "maxLength": 256 },
          "event_types": { "type": "array", "maxItems": 50, "items": { "type": "string" } }
        },
        "additionalProperties": false
      },
      "TelegramBindingRequest": {
        "type": "object",
        "required": ["external_user_id"],
        "properties": {
          "external_user_id": { "type": "string", "maxLength": 200 },
          "participant_id": { "type": ["string", "null"] },
          "bot_username": { "type": "string" },
          "ttl_seconds": { "type": "integer", "minimum": 300, "maximum": 86400 }
        },
        "additionalProperties": false
      },
      "BotSendRequest": {
        "type": "object",
        "properties": {
          "platform": { "type": "string", "enum": ["telegram"] },
          "chat_id": { "type": ["string", "integer"] },
          "text": { "type": "string", "maxLength": 10000 },
          "type": { "type": "string" },
          "card": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": true,
        "description": "Bot payload. The service configuration supplies the bot credential; clients must never send a provider token."
      },
      "BotActionsResponse": {
        "type": "object",
        "required": ["actions"],
        "properties": {
          "actions": { "type": "array", "items": { "type": "object", "additionalProperties": true } }
        }
      },
      "BotExecuteRequest": {
        "type": "object",
        "required": ["action_id"],
        "properties": {
          "action_id": { "type": "string", "minLength": 1 },
          "params": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": true
      },
      "BotChat": {
        "type": "object",
        "required": ["chat_id", "platform"],
        "properties": {
          "chat_id": { "type": "string" },
          "sender_name": { "type": ["string", "null"] },
          "last_message": { "type": ["string", "null"] },
          "last_message_at": { "type": ["string", "null"] },
          "service_alias": { "type": ["string", "null"] },
          "platform": { "type": "string", "enum": ["telegram", "widget"] }
        },
        "additionalProperties": true
      },
      "BotChatsResponse": {
        "type": "object",
        "required": ["chats", "has_more", "next_cursor"],
        "properties": {
          "chats": { "type": "array", "items": { "$ref": "#/components/schemas/BotChat" } },
          "has_more": { "type": "boolean" },
          "next_cursor": { "type": ["string", "null"] }
        }
      },
      "BotMessage": {
        "type": "object",
        "required": ["id", "chat_id", "message_text", "role", "created_at"],
        "properties": {
          "id": { "type": "string" },
          "chat_id": { "type": "string" },
          "sender_name": { "type": ["string", "null"] },
          "message_text": { "type": ["string", "null"] },
          "role": { "type": "string", "enum": ["user", "assistant"] },
          "reply_to_message_id": { "type": ["string", "null"] },
          "raw_payload": { "type": ["string", "null"], "description": "Provider payload retained for message rendering; provider credentials are redacted." },
          "created_at": { "type": "string" }
        },
        "additionalProperties": true
      },
      "BotMessagesResponse": {
        "type": "object",
        "required": ["messages", "has_more", "next_cursor"],
        "properties": {
          "messages": { "type": "array", "items": { "$ref": "#/components/schemas/BotMessage" } },
          "has_more": { "type": "boolean" },
          "next_cursor": { "type": ["string", "null"] }
        }
      },
      "BotMessagePatch": {
        "type": "object",
        "required": ["text"],
        "properties": { "text": { "type": "string", "minLength": 1, "maxLength": 10000 } },
        "additionalProperties": false
      },
      "BotReplyRequest": {
        "type": "object",
        "required": ["chat_id", "text"],
        "properties": {
          "chat_id": { "type": ["string", "integer"] },
          "text": { "type": "string", "minLength": 1, "maxLength": 10000 },
          "reply_to_message_id": { "type": ["string", "integer", "null"] },
          "service_alias": { "type": "string", "maxLength": 80 }
        },
        "additionalProperties": false
      },
      "BotReplyResponse": {
        "type": "object",
        "required": ["success", "message_id"],
        "properties": {
          "success": { "type": "boolean" },
          "message_id": { "type": ["string", "integer"] },
          "dry_run": { "type": "boolean" }
        },
        "additionalProperties": true
      },
      "BotMutationResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "interaction_id": { "type": "string" },
          "message_id": { "type": "string" },
          "dry_run": { "type": "boolean" }
        },
        "additionalProperties": true
      },
      "BotSendFileResponse": {
        "type": "object",
        "required": ["success", "message_id"],
        "properties": {
          "success": { "type": "boolean" },
          "message_id": { "type": "string" },
          "summary": { "type": "string" },
          "raw_payload": { "type": "string" }
        },
        "additionalProperties": true
      },
      "BotInteractionRequest": {
        "type": "object",
        "required": ["chat_id"],
        "properties": {
          "chat_id": { "type": ["string", "integer"] },
          "text": { "type": "string", "maxLength": 10000 },
          "type": { "type": "string" },
          "options": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "actions": { "type": "array", "items": { "type": "object", "additionalProperties": true } }
        },
        "additionalProperties": true
      },
      "BotInteractionsResponse": {
        "type": "object",
        "required": ["data", "pagination"],
        "properties": {
          "data": { "type": "array", "items": { "$ref": "#/components/schemas/GenericObject" } },
          "pagination": {
            "type": "object",
            "required": ["page", "limit", "total", "totalPages"],
            "properties": {
              "page": { "type": "integer" },
              "limit": { "type": "integer" },
              "total": { "type": "integer" },
              "totalPages": { "type": "integer" }
            }
          }
        }
      },
      "FileUploadResponse": {
        "type": "object",
        "required": ["success", "file_id"],
        "properties": {
          "success": { "type": "boolean" },
          "file_id": { "type": "string" },
          "resource_id": { "type": "string" },
          "resource_name": { "type": "string" },
          "filename": { "type": "string" },
          "message": { "type": "string" }
        },
        "additionalProperties": true
      },
      "FileMetadata": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "user_id": { "type": ["string", "integer"] },
          "filename": { "type": "string" },
          "size": { "type": "integer", "minimum": 0 },
          "mime_type": { "type": "string" },
          "expires_at": { "type": ["string", "null"], "format": "date-time" },
          "max_downloads": { "type": ["integer", "null"] },
          "download_count": { "type": "integer", "minimum": 0 },
          "public_access": { "type": "integer", "enum": [0, 1] }
        },
        "additionalProperties": true
      },
      "FileListResponse": {
        "type": "object",
        "required": ["files"],
        "properties": {
          "files": { "type": "array", "items": { "$ref": "#/components/schemas/FileMetadata" } }
        }
      },
      "ApiKeyPolicy": {
        "type": "object",
        "properties": {
          "scopes": { "type": "array", "items": { "type": "string" } },
          "service_aliases": { "type": "array", "items": { "type": "string" } },
          "allowed_ips": { "type": "array", "items": { "type": "string" } },
          "daily_quota": { "type": ["integer", "null"], "minimum": 1 },
          "rate_limit_per_minute": { "type": ["integer", "null"], "minimum": 1, "maximum": 100000 },
          "concurrency_limit": { "type": ["integer", "null"], "minimum": 1, "maximum": 1000 },
          "expires_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "CreateApiKeyRequest": {
        "allOf": [
          { "$ref": "#/components/schemas/ApiKeyPolicy" },
          {
            "type": "object",
            "properties": {
              "name": { "type": "string", "minLength": 1, "maxLength": 120 }
            }
          }
        ]
      },
      "ApiKey": {
        "allOf": [
          { "$ref": "#/components/schemas/ApiKeyPolicy" },
          {
            "type": "object",
            "required": ["id", "key_prefix", "status"],
            "properties": {
              "id": { "type": ["integer", "string"] },
              "name": { "type": "string" },
              "key_prefix": { "type": "string" },
              "last_used_at": { "type": ["string", "null"], "format": "date-time" },
              "rotated_at": { "type": ["string", "null"], "format": "date-time" },
              "revoked_at": { "type": ["string", "null"], "format": "date-time" },
              "status": { "type": "string", "enum": ["active", "expired", "revoked"] },
              "created_at": { "type": ["string", "null"], "format": "date-time" }
            }
          }
        ]
      },
      "ApiKeyListResponse": {
        "type": "object",
        "required": ["data", "pagination"],
        "properties": {
          "data": { "type": "array", "items": { "$ref": "#/components/schemas/ApiKey" } },
          "pagination": { "$ref": "#/components/schemas/GenericObject" }
        }
      },
      "CreateApiKeyResponse": {
        "type": "object",
        "required": ["key", "warning"],
        "properties": {
          "key": { "type": "string", "pattern": "^sk_" },
          "key_id": { "type": ["integer", "null"] },
          "warning": { "type": "string" }
        }
      },
      "GenericObject": {
        "type": "object",
        "additionalProperties": true
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "oneOf": [
              { "type": "string" },
              {
                "type": "object",
                "required": ["code", "message"],
                "properties": {
                  "code": { "type": "string" },
                  "message": { "type": "string" },
                  "request_id": { "type": ["string", "null"] },
                  "details": { "type": "array", "items": { "type": "object" } }
                }
              }
            ]
          }
        }
      },
      "Health": {
        "type": "object",
        "required": ["status", "db"],
        "properties": {
          "status": { "type": "string", "enum": ["ok", "degraded"] },
          "db": { "type": "string", "enum": ["ok", "error"] },
          "ts": { "type": "string", "format": "date-time" }
        }
      },
      "LoginRequest": {
        "type": "object",
        "required": ["email", "password"],
        "properties": {
          "email": { "type": "string", "format": "email" },
          "password": { "type": "string", "minLength": 8, "maxLength": 128 }
        }
      },
      "AuthResponse": {
        "type": "object",
        "properties": {
          "token": { "type": "string" },
          "access_token": { "type": "string" },
          "refresh_token": { "type": "string" },
          "user": { "$ref": "#/components/schemas/GenericObject" }
        },
        "additionalProperties": true
      },
      "ChatMessage": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["system", "user", "assistant", "tool"] },
          "content": { "oneOf": [{ "type": "string" }, { "type": "array" }, { "type": "null" }] }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": ["messages"],
        "properties": {
          "messages": { "type": "array", "minItems": 1, "items": { "$ref": "#/components/schemas/ChatMessage" } },
          "model": { "type": "string" },
          "temperature": { "type": "number", "minimum": 0, "maximum": 2 },
          "top_p": { "type": "number", "minimum": 0, "maximum": 1 },
          "max_tokens": { "type": "integer", "minimum": 1 },
          "max_completion_tokens": { "type": "integer", "minimum": 1 },
          "stream": { "type": "boolean" },
          "max_cost": { "type": "number", "minimum": 0 }
        },
        "additionalProperties": true
      },
      "ChatResponse": {
        "type": "object",
        "required": ["choices"],
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string" },
          "model": { "type": "string" },
          "choices": { "type": "array", "items": { "type": "object" } },
          "usage": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": true
      },
      "EmbeddingRequest": {
        "type": "object",
        "required": ["input"],
        "properties": {
          "input": { "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] },
          "model": { "type": "string" }
        }
      },
      "WebhookPushRequest": {
        "type": "object",
        "properties": {
          "title": { "type": "string", "maxLength": 500 },
          "text": { "type": "string", "maxLength": 10000 },
          "markdown": { "type": "string", "maxLength": 10000 },
          "payload": {}
        },
        "minProperties": 1,
        "additionalProperties": true
      },
      "WebhookPushResponse": {
        "type": "object",
        "required": ["ok", "dry_run", "success_count", "failure_count", "results"],
        "properties": {
          "ok": { "type": "boolean" },
          "dry_run": { "type": "boolean" },
          "success_count": { "type": "integer", "minimum": 0 },
          "failure_count": { "type": "integer", "minimum": 0 },
          "results": { "type": "array", "items": { "type": "object" } }
        }
      },
      "TronLeaseRequest": {
        "type": "object",
        "required": ["receiver", "energy"],
        "properties": {
          "receiver": { "type": "string", "pattern": "^T[1-9A-HJ-NP-Za-km-z]{33}$" },
          "energy": { "type": "integer", "minimum": 1000, "maximum": 5000000 },
          "duration_seconds": { "type": "integer", "minimum": 300, "maximum": 86400, "default": 3600 }
          ,"callback_url": { "type": "string", "format": "uri", "description": "HTTPS callback URL for job.updated events." }
          ,"callback_secret": { "type": "string", "minLength": 16, "maxLength": 256, "writeOnly": true }
        }
      },
      "TronQuoteResponse": {
        "type": "object",
        "required": ["quote_id", "receiver", "energy", "pricing"],
        "properties": {
          "quote_id": { "type": "string" },
          "receiver": { "type": "string" },
          "energy": { "type": "integer" },
          "duration_seconds": { "type": "integer" },
          "pricing": { "type": "object", "additionalProperties": true },
          "expires_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "TronLease": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "job_id": { "type": ["string", "null"] },
          "receiver": { "type": "string" },
          "energy": { "type": "integer" },
          "duration_seconds": { "type": "integer" },
          "status": { "type": "string", "enum": ["pending", "accepted", "completed", "failed", "expired", "dry_run"] },
          "provider_id": { "type": ["string", "null"] },
          "txid": { "type": ["string", "null"] },
          "cost": { "type": "number" },
          "refund_status": { "type": ["string", "null"] },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        },
        "additionalProperties": true
      },
      "TronLeaseResponse": {
        "oneOf": [
          { "$ref": "#/components/schemas/TronLease" },
          {
            "type": "object",
            "required": ["status", "dry_run", "receiver", "energy", "pricing"],
            "properties": {
              "status": { "const": "dry_run" },
              "dry_run": { "const": true },
              "receiver": { "type": "string" },
              "energy": { "type": "integer" },
              "duration_seconds": { "type": "integer" },
              "pricing": { "type": "object", "additionalProperties": true }
            }
          }
        ]
      },
      "AsyncJob": {
        "type": "object",
        "required": ["id", "service", "resource_type", "resource_id", "status", "callback"],
        "properties": {
          "id": { "type": "string", "pattern": "^job_" },
          "service": { "type": "string" },
          "resource_type": { "type": "string" },
          "resource_id": { "type": "string" },
          "request_id": { "type": ["string", "null"], "format": "uuid" },
          "status": { "type": "string", "enum": ["pending", "running", "succeeded", "failed", "canceled", "expired"] },
          "result": { "type": ["object", "null"], "additionalProperties": true },
          "error": { "type": ["object", "null"], "additionalProperties": true },
          "callback": { "type": "object", "properties": { "configured": { "type": "boolean" }, "status": { "type": "string" }, "attempts": { "type": "integer" } } },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "completed_at": { "type": ["string", "null"], "format": "date-time" },
          "expires_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "AsyncJobResponse": {
        "type": "object",
        "required": ["job"],
        "properties": { "job": { "$ref": "#/components/schemas/AsyncJob" } }
      },
      "AsyncJobListResponse": {
        "type": "object",
        "required": ["data"],
        "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/AsyncJob" } } }
      },
      "RequestTraceResponse": {
        "type": "object",
        "required": ["request_id", "ai", "api_key_events"],
        "properties": {
          "request_id": { "type": "string", "format": "uuid" },
          "ai": { "type": "array", "items": { "$ref": "#/components/schemas/GenericObject" } },
          "api_key_events": { "type": "array", "items": { "$ref": "#/components/schemas/GenericObject" } }
        }
      },
      "PaymentCheckoutRequest": {
        "type": "object",
        "required": ["amount", "currency"],
        "properties": {
          "amount": { "type": "number", "exclusiveMinimum": 0, "maximum": 10000, "multipleOf": 0.01 },
          "currency": { "type": "string", "const": "USD" }
        },
        "additionalProperties": false
      },
      "PaymentIntent": {
        "type": "object",
        "required": ["id", "provider", "provider_intent_id", "amount", "currency", "status"],
        "properties": {
          "id": { "type": "string", "pattern": "^pi_[A-Za-z0-9._:-]+$" },
          "provider": { "type": "string", "enum": ["mock", "stripe"] },
          "provider_intent_id": { "type": "string" },
          "amount": { "type": "number", "minimum": 0.01, "maximum": 10000 },
          "currency": { "type": "string", "const": "USD" },
          "status": { "type": "string", "enum": ["pending", "succeeded", "failed"] },
          "provider_checkout_url": { "type": ["string", "null"] },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "PaymentIntentResponse": {
        "type": "object",
        "required": ["data"],
        "properties": {
          "data": { "$ref": "#/components/schemas/PaymentIntent" },
          "reused": { "type": "boolean" }
        }
      },
      "PaymentWebhook": {
        "description": "Sandbox mock envelope. Stripe requests use Stripe's signed raw Event envelope and the stripe-signature header.",
        "type": "object",
        "required": ["event_id", "type", "payment_intent_id", "amount", "currency"],
        "properties": {
          "event_id": { "type": "string", "pattern": "^[A-Za-z0-9._:-]{1,128}$" },
          "type": { "type": "string", "enum": ["payment.succeeded", "payment.failed"] },
          "payment_intent_id": { "type": "string", "pattern": "^[A-Za-z0-9._:-]{1,128}$" },
          "amount": { "type": "number", "exclusiveMinimum": 0, "maximum": 10000, "multipleOf": 0.01 },
          "currency": { "type": "string", "const": "USD" }
        },
        "additionalProperties": false
      },
      "SocialOpsEvent": {
        "type": "object",
        "properties": {
          "event_id": { "type": "string", "maxLength": 200 },
          "thread_id": { "type": "string", "maxLength": 200 },
          "message_id": { "type": "string", "maxLength": 200 },
          "text": { "type": "string", "maxLength": 10000 },
          "payload": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": true
      }
    }
  }
}
