{
  "openapi": "3.1.0",
  "info": {
    "title": "AEM Intelligence API",
    "version": "1.0.0",
    "description": "API REST compatível com o formato OpenAI para integrar a inteligência e o roteamento resiliente da AEM.",
    "contact": {
      "name": "AEM Soluções",
      "email": "ai@aemsolucoes.com",
      "url": "https://ai.aemsolucoes.com/documentacao"
    }
  },
  "servers": [
    {
      "url": "https://ai.aemsolucoes.com/api",
      "description": "Produção"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/health": {
      "get": {
        "summary": "Saúde do serviço",
        "security": [],
        "responses": {
          "200": {
            "description": "Operacional"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "Modelos lógicos disponíveis",
        "responses": {
          "200": {
            "description": "Lista de modelos"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "summary": "Criar uma resposta",
        "description": "Endpoint compatível com o contrato de Chat Completions. O modelo aem-auto escolhe e alterna provedores automaticamente.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resposta concluída"
          },
          "400": {
            "description": "Requisição inválida"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "description": "Indisponibilidade temporária"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "AEM API Key"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Chave ausente ou inválida"
      }
    },
    "schemas": {
      "ChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "default": "aem-auto",
            "enum": [
              "aem-auto",
              "aem-fast",
              "aem-quality"
            ]
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "system",
                    "user",
                    "assistant"
                  ]
                },
                "content": {
                  "type": "string"
                }
              }
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          }
        }
      }
    }
  }
}