{
  "openapi": "3.1.0",
  "info": {
    "title": "OM Gateway API",
    "version": "0.3.3",
    "description": "OpenAI-compatible gateway with native Anthropic Messages and Gemini endpoints, cross-protocol translation, and per-token billing. Authentication: `Authorization: Bearer <API key>` on every path (Gemini also accepts `x-goog-api-key`).",
    "contact": { "name": "OM", "url": "https://omniaxis.cc/api.html" }
  },
  "servers": [{ "url": "https://omniaxis.cc" }],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "OpenAI Chat Completions (streaming supported)",
        "parameters": [{ "name": "stream", "in": "query", "schema": { "type": "boolean" }, "description": "Alternative to body-level stream flag." }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion or SSE stream (content-type text/event-stream when stream=true).",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ChatResponse" } },
              "text/event-stream": { "schema": { "type": "string" } }
            }
          },
          "4XX": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "5XX": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/completions": {
      "post": {
        "summary": "Legacy text completions (compat layer, rewritten to Chat upstream)",
        "description": "Single-element `prompt` only; `suffix`/`echo`/`logprobs` are rejected with 400.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "prompt"],
                "properties": {
                  "model": { "type": "string" },
                  "prompt": { "type": "string" },
                  "stream": { "type": "boolean" },
                  "max_tokens": { "type": "integer" },
                  "temperature": { "type": "number" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Legacy `text_completion` shape." },
          "4XX": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/embeddings": {
      "post": {
        "summary": "OpenAI-compatible embeddings",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "input"],
                "properties": {
                  "model": { "type": "string" },
                  "input": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OpenAI list shape: `data[].embedding`, `usage`." }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List models visible to this API key",
        "responses": {
          "200": {
            "description": "OpenAI list shape; entries include `context_window`, `max_tokens`, `capabilities` and `vendor`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": { "type": "string", "const": "list" },
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Model" } }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/models/{model}": {
      "get": {
        "summary": "Retrieve one model (SDK models.retrieve shape)",
        "parameters": [{ "name": "model", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Model entry.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Model" } } } },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/images/generations": {
      "post": {
        "summary": "Image generation (billed per image)",
        "description": "`n` defaults to 1, range 1-4. Not streamable. Results in `data[].url` or `data[].b64_json` depending on the upstream model.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "prompt"],
                "properties": {
                  "model": { "type": "string" },
                  "prompt": { "type": "string" },
                  "n": { "type": "integer", "minimum": 1, "maximum": 4 },
                  "size": { "type": "string", "example": "1024x1024" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "OpenAI images shape." },
          "4XX": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Anthropic Messages (native)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages", "max_tokens"],
                "properties": {
                  "model": { "type": "string" },
                  "messages": { "type": "array", "items": { "type": "object" } },
                  "max_tokens": { "type": "integer" },
                  "stream": { "type": "boolean" },
                  "system": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Anthropic message shape (SSE events when stream=true)." }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "summary": "Anthropic native token counting (no generation cost)",
        "responses": { "200": { "description": "Anthropic count shape with `input_tokens`." } }
      }
    },
    "/v1/responses": {
      "post": {
        "summary": "OpenAI Responses API (Codex-compatible, server state supported on capable channels)",
        "responses": { "200": { "description": "Responses shape; SSE `response.*` events when stream=true." } }
      }
    }
  },
  "components": {
    "schemas": {
      "ChatRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": { "type": "string" },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "role": { "type": "string", "enum": ["system", "user", "assistant", "tool"] },
                "content": {}
              }
            }
          },
          "stream": { "type": "boolean" },
          "temperature": { "type": "number" },
          "max_tokens": { "type": "integer" },
          "tools": { "type": "array", "items": { "type": "object" } },
          "reasoning_effort": { "type": "string" }
        }
      },
      "ChatResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string", "const": "chat.completion" },
          "choices": { "type": "array", "items": { "type": "object" } },
          "usage": { "type": "object" }
        }
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string", "const": "model" },
          "context_window": { "type": "integer" },
          "max_tokens": { "type": "integer" },
          "capabilities": { "type": "string" },
          "vendor": { "type": "string" }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error envelope: `{ \"error\": { \"message\": string, \"type\": string } }`. Common types: `invalid_request`, `invalid_authentication` (401), `insufficient_quota` (402), `rate_limited` (429), `no_available_channel` (503), `upstream_error` (502).",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "message": { "type": "string" },
                    "type": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
