{
  "openapi": "3.1.0",
  "info": {
    "title": "MandAPI",
    "version": "1.0.0",
    "description": "MandAPI is an OpenAI-compatible, multi-model AI developer API. A single API key can access available GPT, Claude, Gemini, DeepSeek and other models. Model availability and supported parameters depend on the model and account; retrieve the current list with GET /v1/models before sending a request.",
    "termsOfService": "https://mandapi.com/terms",
    "contact": {"url": "https://mandapi.com/contact"}
  },
  "externalDocs": {"description": "MandAPI developer documentation", "url": "https://mandapi.com/docs"},
  "servers": [
    {"url": "https://api.mandapi.com", "description": "MandAPI production API"}
  ],
  "tags": [
    {"name": "Models", "description": "Available AI models"},
    {"name": "Chat", "description": "OpenAI-compatible chat completions"}
  ],
  "security": [{"BearerAuth": []}],
  "paths": {
    "/v1/models": {
      "get": {
        "tags": ["Models"],
        "operationId": "listModels",
        "summary": "List available models",
        "description": "List models currently available through the MandAPI OpenAI-compatible API for this API key. The list can change and may differ by account.",
        "responses": {
          "200": {
            "description": "OpenAI-compatible model list",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ModelList"}}}
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "429": {"$ref": "#/components/responses/RateLimited"},
          "500": {"$ref": "#/components/responses/ServerError"}
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "tags": ["Chat"],
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "description": "Create an OpenAI-compatible chat completion using a model available to this API key. When stream is true, the response is a Server-Sent Events stream (text/event-stream) with data chunks and a terminal [DONE] marker. Streaming and optional parameter support vary by model; check the model's current capabilities.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/ChatCompletionRequest"},
              "example": {
                "model": "deepseek-v4.1-flash",
                "messages": [{"role": "user", "content": "Hello!"}],
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A completion object, or SSE events when stream is true",
            "content": {
              "application/json": {"schema": {"$ref": "#/components/schemas/ChatCompletion"}},
              "text/event-stream": {"schema": {"type": "string", "description": "SSE data frames containing chat completion chunks, followed by data: [DONE]."}}
            }
          },
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "429": {"$ref": "#/components/responses/RateLimited"},
          "500": {"$ref": "#/components/responses/ServerError"}
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Authenticate with a MandAPI API key: Authorization: Bearer YOUR_MANDAPI_API_KEY"
      }
    },
    "schemas": {
      "Model": {
        "type": "object",
        "required": ["id", "object"],
        "properties": {
          "id": {"type": "string", "description": "Model ID to send in a completion request"},
          "object": {"type": "string", "example": "model"},
          "owned_by": {"type": "string"}
        },
        "additionalProperties": true
      },
      "ModelList": {
        "type": "object",
        "required": ["object", "data"],
        "properties": {
          "object": {"type": "string", "example": "list"},
          "data": {"type": "array", "items": {"$ref": "#/components/schemas/Model"}}
        },
        "additionalProperties": true
      },
      "Message": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": {"type": "string", "enum": ["system", "developer", "user", "assistant", "tool"]},
          "content": {"type": "string", "description": "Text content for the basic chat request"}
        },
        "additionalProperties": true
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {"type": "string", "description": "A model ID returned by GET /v1/models for this API key"},
          "messages": {"type": "array", "minItems": 1, "items": {"$ref": "#/components/schemas/Message"}},
          "stream": {"type": "boolean", "default": false},
          "temperature": {"type": "number"},
          "max_tokens": {"type": "integer", "minimum": 0},
          "max_completion_tokens": {"type": "integer", "minimum": 0},
          "top_p": {"type": "number"},
          "stop": {"oneOf": [{"type": "string"}, {"type": "array", "items": {"type": "string"}}]}
        },
        "additionalProperties": true
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {"type": "integer"},
          "completion_tokens": {"type": "integer"},
          "total_tokens": {"type": "integer"}
        },
        "additionalProperties": true
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "object": {"type": "string", "example": "chat.completion"},
          "model": {"type": "string"},
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {"type": "integer"},
                "message": {"type": "object", "properties": {"role": {"type": "string"}, "content": {"type": ["string", "null"]}}, "additionalProperties": true},
                "finish_reason": {"type": ["string", "null"]}
              },
              "additionalProperties": true
            }
          },
          "usage": {"$ref": "#/components/schemas/Usage"}
        },
        "additionalProperties": true
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["message", "type"],
            "properties": {
              "message": {"type": "string"},
              "type": {"type": "string", "example": "new_api_error"},
              "code": {"type": ["string", "null"]},
              "param": {"type": ["string", "null"]}
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      }
    },
    "responses": {
      "BadRequest": {"description": "Invalid request body or parameters", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "Unauthorized": {"description": "Missing or invalid API key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "Forbidden": {"description": "The API key cannot access the requested model", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "RateLimited": {"description": "Rate or quota limit reached", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "ServerError": {"description": "Server or upstream failure", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}
    }
  }
}
