{
  "openapi": "3.0.3",
  "info": {
    "title": "LoggerMan Ingest API",
    "version": "1.0.0",
    "description": "REST API for ingesting and reading project logs. Authenticate with a project Bearer token from Settings → API keys."
  },
  "servers": [{ "url": "{baseUrl}", "variables": { "baseUrl": { "default": "https://your-app.example.com" } } } }],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Project API token"
      }
    },
    "schemas": {
      "LogIngest": {
        "type": "object",
        "required": ["message"],
        "properties": {
          "message": { "type": "string", "maxLength": 8192 },
          "type": { "type": "string", "enum": ["INFO", "WARNING", "ERROR"] },
          "criticality": { "type": "string", "enum": ["LOW", "MEDIUM", "HIGH"] },
          "source": { "type": "string", "maxLength": 256 },
          "level": { "type": "string", "description": "Maps debug/info/warn/error when type omitted" },
          "metadata": { "type": "object", "additionalProperties": true }
        }
      },
      "IngestError": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "code": {
            "type": "string",
            "enum": [
              "INVALID_JSON",
              "VALIDATION_ERROR",
              "PAYLOAD_TOO_LARGE",
              "FORBIDDEN",
              "RATE_LIMITED",
              "UNAUTHORIZED",
              "PROJECT_REQUIRED"
            ]
          },
          "retryAfterSec": { "type": "integer" }
        }
      }
    }
  },
  "paths": {
    "/api/projects/{projectId}/logs": {
      "post": {
        "summary": "Create log",
        "operationId": "createLog",
        "parameters": [{ "name": "projectId", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LogIngest" } } }
        },
        "responses": {
          "201": { "description": "Log created" },
          "400": { "description": "Validation error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/IngestError" } } } },
          "401": { "description": "Missing token" },
          "403": { "description": "Forbidden" },
          "413": { "description": "Payload too large" },
          "429": { "description": "Rate limited" }
        }
      },
      "get": {
        "summary": "List logs (Scale plan)",
        "operationId": "listLogs",
        "parameters": [
          { "name": "projectId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "page", "in": "header", "schema": { "type": "integer", "default": 0 } }
        ],
        "responses": {
          "200": { "description": "Log array" },
          "403": { "description": "Forbidden or plan limit" }
        }
      }
    },
    "/api/projects/{projectId}/logs/batch": {
      "post": {
        "summary": "Batch ingest (max 100)",
        "operationId": "batchIngest",
        "parameters": [{ "name": "projectId", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  { "type": "array", "items": { "$ref": "#/components/schemas/LogIngest" } },
                  {
                    "type": "object",
                    "properties": { "logs": { "type": "array", "items": { "$ref": "#/components/schemas/LogIngest" } } }
                  }
                ]
              }
            }
          }
        },
        "responses": { "201": { "description": "Batch accepted" } }
      }
    },
    "/api/projects/{projectId}/otlp": {
      "post": {
        "summary": "OTLP JSON logs",
        "operationId": "otlpIngest",
        "parameters": [{ "name": "projectId", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "202": { "description": "Accepted" } }
      }
    },
    "/api/projects/{projectId}/hooks/{hookToken}": {
      "post": {
        "summary": "Incoming webhook",
        "operationId": "incomingWebhook",
        "security": [],
        "parameters": [
          { "name": "projectId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "hookToken", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "201": { "description": "Log created" } }
      }
    }
  }
}
