{
  "openapi": "3.1.0",
  "info": {
    "title": "TokenRecarga API",
    "version": "1.0.0",
    "description": "API compatível com OpenAI. Aponte seu SDK para a baseURL e use sua chave mt_live_. O corpo da requisição é repassado ao provedor do modelo; campos além dos listados são aceitos conforme o modelo suportar."
  },
  "servers": [{ "url": "https://www.tokenrecarga.com.br/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/chat/completions": {
      "post": {
        "summary": "Chat completions (compatível com OpenAI)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages"],
                "properties": {
                  "model": { "type": "string", "description": "Código do modelo, ver GET /models" },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["role", "content"],
                      "properties": {
                        "role": { "type": "string", "enum": ["system", "user", "assistant", "tool"] },
                        "content": { "type": "string" }
                      }
                    }
                  },
                  "stream": { "type": "boolean", "default": false },
                  "temperature": { "type": "number" },
                  "max_tokens": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resposta no formato OpenAI. Cabeçalhos: x-mt-data-region (país de destino dos dados, LGPD), x-mt-vendor, x-mt-supplier, e em respostas não-stream x-mt-cost-brl / x-mt-balance-brl.",
            "content": {
              "application/json": { "schema": { "type": "object" } },
              "text/event-stream": { "schema": { "type": "string", "description": "SSE quando stream: true" } }
            }
          },
          "401": { "description": "Chave inválida ou revogada" },
          "402": { "description": "Saldo insuficiente" },
          "429": { "description": "Limite mensal da chave excedido" },
          "502": { "description": "Falha do provedor upstream" }
        }
      }
    },
    "/models": {
      "get": {
        "summary": "Modelos disponíveis para a sua chave",
        "responses": {
          "200": {
            "description": "Lista no formato OpenAI (object=list). Cada item traz id, owned_by (fabricante) e a região de dados.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          },
          "401": { "description": "Chave inválida ou revogada" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "Authorization: Bearer mt_live_..." }
    }
  }
}
