{
  "openapi": "3.1.0",
  "info": {
    "title": "OpenGeteWay Gateway API",
    "version": "1.0.0",
    "description": "OpenAI- and Anthropic-compatible gateway for DeepSeek, GLM and Kimi models. Gateway routes live under /v1/* and authenticate with a Bearer API key (or x-api-key for /v1/messages). Requests are forwarded transparently to the upstream provider and responses are relayed verbatim."
  },
  "servers": [
    { "url": "https://www.opengeteway.com", "description": "OpenGeteWay gateway" }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "Create a chat completion (OpenAI-compatible)",
        "description": "OpenAI-compatible chat endpoint. The gateway resolves the model slug and forwards the request transparently to the upstream provider, returning the response verbatim (including reasoning_content and tool_calls).",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatCompletionRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A chat completion, or a text/event-stream when stream is true.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChatCompletion" }
              },
              "text/event-stream": {
                "schema": { "type": "string" },
                "example": "data: {\"id\":\"chatcmpl_...\",\"object\":\"chat.completion.chunk\",\"choices\":[{\"delta\":{\"role\":\"assistant\"},\"index\":0}]}\n\ndata: {\"id\":\"chatcmpl_...\",\"object\":\"chat.completion.chunk\",\"choices\":[{\"delta\":{\"content\":\"Hello\"},\"index\":0}]}\n\ndata: {\"id\":\"chatcmpl_...\",\"object\":\"chat.completion.chunk\",\"choices\":[{\"delta\":{},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]"
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "402": {
            "description": "Insufficient balance.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "429": {
            "description": "Rate limit exhausted.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "5xx": {
            "description": "Upstream provider failure.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Create a message (Anthropic-compatible)",
        "description": "Anthropic-compatible Messages endpoint. Same models and transparent passthrough, in Anthropic message format. Authenticate with x-api-key (or Authorization: Bearer).",
        "operationId": "createMessage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AnthropicMessageRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An Anthropic Message, or a text/event-stream when stream is true.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AnthropicMessage" }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "402": {
            "description": "Insufficient balance.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "429": {
            "description": "Rate limit exhausted.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          },
          "5xx": {
            "description": "Upstream provider failure.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List available models",
        "description": "Returns the currently enabled model IDs: deepseek-v4-pro-0813, deepseek-v4.1-flash-1017, glm-5.3-flash, kimi-k3, kimi-k3.1-pro.",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "A list of enabled models.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GatewayModelList" }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key sent as Authorization: Bearer <api_key>."
      },
      "xApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "API key sent as x-api-key: <api_key> (Anthropic-compatible authentication)."
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["messages"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model slug, or \"auto\" for platform routing.",
            "examples": ["deepseek-v4-pro-0813", "deepseek-v4.1-flash-1017", "glm-5.3-flash", "auto"]
          },
          "messages": {
            "type": "array",
            "description": "OpenAI-style role/content messages.",
            "items": { "$ref": "#/components/schemas/ChatMessage" }
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2,
            "description": "No default is applied; when omitted it is not sent upstream."
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "description": "When omitted or below 1, the gateway reserves balance against the model's full context window."
          },
          "stream": {
            "type": "boolean",
            "default": false,
            "description": "When true, returns Server-Sent Events terminated by data: [DONE]."
          },
          "tools": {
            "description": "Tool definitions, forwarded to the upstream provider as-is.",
            "type": "array",
            "items": { "type": "object" }
          }
        }
      },
      "ChatMessage": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["system", "user", "assistant", "tool"] },
          "content": { "type": ["string", "null"] },
          "reasoning_content": { "type": "string", "description": "The model's reasoning chain (DeepSeek reasoning models)." },
          "tool_calls": { "type": "array", "items": { "type": "object" } },
          "tool_call_id": { "type": "string" }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string", "const": "chat.completion" },
          "created": { "type": "integer" },
          "model": { "type": "string" },
          "choices": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ChatChoice" }
          },
          "usage": { "$ref": "#/components/schemas/Usage" },
          "system_fingerprint": { "type": ["string", "null"] }
        }
      },
      "ChatChoice": {
        "type": "object",
        "properties": {
          "index": { "type": "integer" },
          "message": { "$ref": "#/components/schemas/ChatMessage" },
          "finish_reason": { "type": "string" },
          "logprobs": { "type": ["object", "null"] }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": { "type": "integer" },
          "completion_tokens": { "type": "integer" },
          "total_tokens": { "type": "integer" },
          "completion_tokens_details": { "type": "object" },
          "prompt_tokens_details": { "type": "object" }
        }
      },
      "AnthropicMessageRequest": {
        "type": "object",
        "required": ["model", "max_tokens", "messages"],
        "properties": {
          "model": { "type": "string", "description": "Model slug, or \"auto\" for platform routing." },
          "max_tokens": { "type": "integer", "minimum": 1 },
          "system": { "type": "string" },
          "messages": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/AnthropicMessageInput" }
          },
          "stream": { "type": "boolean", "default": false },
          "temperature": { "type": "number" }
        }
      },
      "AnthropicMessageInput": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["user", "assistant"] },
          "content": { "type": ["string", "array"] }
        }
      },
      "AnthropicMessage": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "type": { "type": "string", "const": "message" },
          "role": { "type": "string", "const": "assistant" },
          "model": { "type": "string" },
          "content": {
            "type": "array",
            "items": { "type": "object" }
          },
          "stop_reason": { "type": ["string", "null"] },
          "stop_sequence": { "type": ["string", "null"] },
          "usage": { "$ref": "#/components/schemas/AnthropicUsage" }
        }
      },
      "AnthropicUsage": {
        "type": "object",
        "properties": {
          "input_tokens": { "type": "integer" },
          "output_tokens": { "type": "integer" },
          "cache_creation_input_tokens": { "type": "integer" },
          "cache_read_input_tokens": { "type": "integer" }
        }
      },
      "GatewayModelList": {
        "type": "object",
        "required": ["object", "data"],
        "properties": {
          "object": { "type": "string", "const": "list" },
          "data": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/GatewayModel" }
          }
        }
      },
      "GatewayModel": {
        "type": "object",
        "required": ["id", "object", "owned_by"],
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string", "const": "model" },
          "owned_by": { "type": "string", "const": "token" }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "request_id": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
