{
  "openapi": "3.0.3",
  "info": { "title": "Alpiko API", "version": "1.0.0", "description": "AI customer-messaging platform API: AI chat answers, knowledge base search, appointments, SMS OTP. Sign up at https://panel.alpiko.com.tr (7-day / 50-reply free trial), create a key in the panel." },
  "servers": [{ "url": "https://rbtugfywsrhfxjeiffes.supabase.co/functions/v1/public-api" }],
  "security": [{ "bearer": [] }],
  "components": {
    "securitySchemes": { "bearer": { "type": "http", "scheme": "bearer", "description": "API key starting with alp_live_ (create in panel)" } },
    "schemas": { "Error": { "type": "object", "properties": { "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" } } } } } }
  },
  "paths": {
    "/v1/chat": { "post": { "summary": "Get an AI reply grounded in the business knowledge base (scope chat:write)",
      "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["user_id", "message"], "properties": { "user_id": { "type": "string", "maxLength": 64, "description": "Your end-user id; same id continues the conversation" }, "message": { "type": "string", "maxLength": 1000 } } } } } },
      "responses": { "200": { "description": "Reply", "content": { "application/json": { "schema": { "type": "object", "properties": { "replies": { "type": "array", "items": { "type": "string" } }, "handoff": { "type": "boolean" }, "appointment": { "type": "boolean" } } } } } }, "402": { "description": "Trial or credit exhausted" }, "429": { "description": "Rate or daily limit" } } } },
    "/v1/knowledge": { "get": { "summary": "Search the knowledge base (scope knowledge:read)",
      "parameters": [{ "name": "q", "in": "query", "schema": { "type": "string" } }],
      "responses": { "200": { "description": "Top 10 matching entries" } } } },
    "/v1/availability": { "get": { "summary": "Free appointment slots (scope availability:read)",
      "parameters": [{ "name": "date", "in": "query", "required": true, "schema": { "type": "string", "format": "date" } }, { "name": "duration", "in": "query", "schema": { "type": "integer", "minimum": 5, "maximum": 600 } }],
      "responses": { "200": { "description": "Slots in UTC" } } } },
    "/v1/appointments": {
      "get": { "summary": "List appointments (scope appointments:read)", "parameters": [{ "name": "from", "in": "query", "schema": { "type": "string" } }, { "name": "to", "in": "query", "schema": { "type": "string" } }, { "name": "status", "in": "query", "schema": { "type": "string" } }], "responses": { "200": { "description": "Appointments" } } },
      "post": { "summary": "Create appointment (scope appointments:write)", "responses": { "200": { "description": "Created" }, "409": { "description": "Slot unavailable" } } } },
    "/v1/otp/send": { "post": { "summary": "Send an SMS verification code (scope otp:send)", "responses": { "200": { "description": "Sent" } } } },
    "/v1/otp/verify": { "post": { "summary": "Verify an SMS code (scope otp:send)", "responses": { "200": { "description": "Result" } } } }
  }
}
