{
  "openapi": "3.0.3",
  "info": {
    "title": "Minglyph API",
    "version": "1.0.0-alpha",
    "description": "Create accurate, meaning-led glyph artwork through asynchronous generation jobs."
  },
  "servers": [{ "url": "https://minglyph.vod-mates.workers.dev" }],
  "paths": {
    "/v1/styles": {
      "get": {
        "summary": "List active styles",
        "responses": {
          "200": {
            "description": "Active style recipes",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/StyleList" } } }
          }
        }
      }
    },
    "/v1/generations": {
      "post": {
        "summary": "Create a generation job",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{
          "name": "Idempotency-Key",
          "in": "header",
          "required": true,
          "schema": { "type": "string", "maxLength": 128 }
        }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreateGeneration" } } }
        },
        "responses": {
          "202": {
            "description": "Job accepted",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Generation" } } }
          },
          "401": {
            "description": "Invalid or missing API key",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "Minglyph API Key" }
    },
    "schemas": {
      "CreateGeneration": {
        "type": "object",
        "required": ["text", "style"],
        "properties": {
          "text": { "type": "string", "minLength": 1, "maxLength": 40 },
          "meaning": { "type": "string", "maxLength": 160 },
          "format": { "type": "string", "enum": ["letter", "word", "doodle", "story"], "default": "word" },
          "style": { "type": "string", "enum": ["semantic-glyph", "editorial-line", "letter-variant", "minimal-doodle", "organic-nature", "graphic-poster", "soft-3d", "editorial-poster"] },
          "reuse_mode": { "type": "string", "enum": ["workspace", "public", "never"], "default": "workspace" },
          "visibility": { "type": "string", "enum": ["private", "public"], "default": "private" },
          "output": {
            "type": "object",
            "properties": {
              "size": { "type": "string", "enum": ["1024x1024"] },
              "format": { "type": "string", "enum": ["png", "webp"] }
            }
          }
        }
      },
      "Generation": {
        "type": "object",
        "required": ["id", "status", "reused", "credits_reserved", "status_url"],
        "properties": {
          "id": { "type": "string", "example": "gen_01J..." },
          "status": { "type": "string", "enum": ["queued", "preparing", "generating", "validating", "storing", "completed", "failed"] },
          "reused": { "type": "boolean" },
          "credits_reserved": { "type": "integer", "minimum": 0 },
          "status_url": { "type": "string", "format": "uri" }
        }
      },
      "StyleList": {
        "type": "object",
        "properties": {
          "data": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "recipe_version": { "type": "integer" }, "active": { "type": "boolean" } } } }
        }
      },
      "Error": {
        "type": "object",
        "required": ["code", "message", "request_id"],
        "properties": {
          "code": { "type": "string" },
          "message": { "type": "string" },
          "request_id": { "type": "string" },
          "details": { "type": "object", "nullable": true, "additionalProperties": true }
        }
      }
    }
  }
}
