{
  "openapi": "3.1.0",
  "info": {
    "title": "Muntrume AI API",
    "version": "1.0.0",
    "description": "Technical assistant, vision analysis, and published Artifacts API for Muntrume AI Studio (https://ai.muntru.me/). Inference endpoints require verified Muntrume Motorsport team JWT authentication; documentation and public artifacts are openly accessible.",
    "license": { "name": "MIT", "url": "https://opensource.org/licenses/MIT" },
    "contact": { "name": "Muntrume Motorsport", "email": "admin@muntru.me", "url": "https://muntru.me/ai-docs/" }
  },
  "servers": [
    { "url": "https://ai.muntru.me", "description": "Production Edge Custom Domain" },
    { "url": "https://muntrume.atrumin16.workers.dev", "description": "Cloudflare Workers Origin" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Active Muntrume Motorsport team session JWT issued by the Setup Vault."
      }
    }
  },
  "paths": {
    "/api/ai": {
      "post": {
        "operationId": "runMuntrumeAI",
        "summary": "Query Muntrume AI (Team-authenticated, JSON or SSE streaming)",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": { "type": "string", "description": "User question or instruction (max 8000 chars)" },
                  "tier": { "type": "string", "enum": ["lite", "pro", "ultra_max"], "default": "pro" },
                  "mode": { "type": "string", "enum": ["team", "general", "ai_setup"], "default": "team" },
                  "skill": { "type": "string", "enum": ["", "setup", "strategy", "code", "slides", "doc"] },
                  "lang": { "type": "string", "enum": ["es", "ca", "en", "fr"], "default": "es" },
                  "stream": { "type": "boolean", "default": false },
                  "web_search": { "type": "boolean", "default": false },
                  "image": { "type": "string", "description": "Optional base64 data URL (png/jpeg/webp) for Vision analysis" },
                  "github_url": { "type": "string", "description": "Optional public GitHub repo or blob URL for code context" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Markdown answer payload (JSON) or Server-Sent Events stream" },
          "401": { "description": "Unauthorized — verified Muntrume Motorsport team JWT required" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/api/ai/artifacts/get/{slug}": {
      "get": {
        "operationId": "getPublicArtifact",
        "summary": "Fetch a published public artifact by slug (no auth required for public artifacts)",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Artifact metadata and source code" },
          "404": { "description": "Artifact not found or private" }
        }
      }
    }
  }
}
