{
  "openapi": "3.1.0",
  "info": {
    "title": "xrouters gateway",
    "version": "1.0.0",
    "description": "One endpoint, both wire formats. OpenAI Chat Completions and Anthropic Messages are served by the same host; billing is metered from the provider's own usage block."
  },
  "servers": [{ "url": "/", "description": "current host" }],
  "security": [{ "bearer": [] }],
  "components": {
    "securitySchemes": {
      "bearer": { "type": "http", "scheme": "bearer", "description": "API key from the dashboard, 48 hex characters, no prefix." },
      "anthropicKey": { "type": "apiKey", "in": "header", "name": "x-api-key", "description": "Anthropic-native clients may send the same key here instead." }
    },
    "schemas": {
      "Message": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["system", "user", "assistant", "tool"] },
          "content": { "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "object" } }] }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": { "type": "string" },
              "type": { "type": "string" },
              "code": { "type": "string" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "OpenAI-compatible chat completion",
        "operationId": "chatCompletions",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages"],
                "properties": {
                  "model": { "type": "string", "example": "deepseek/deepseek-v4.1-flash" },
                  "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Message" } },
                  "stream": { "type": "boolean", "default": false },
                  "temperature": { "type": "number" },
                  "max_tokens": { "type": "integer" },
                  "tools": { "type": "array", "items": { "type": "object" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Completion, or a stream of `data:` chunks when stream=true." },
          "401": { "description": "Missing or revoked key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "402": { "description": "Quota exhausted." },
          "404": { "description": "Unknown model id - see GET /api/docs/models." },
          "429": { "description": "Rate limit for the account package." },
          "502": { "description": "Upstream provider error; nothing debited." }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Anthropic-compatible messages",
        "operationId": "messages",
        "parameters": [
          { "name": "anthropic-version", "in": "header", "required": false, "schema": { "type": "string", "example": "2023-06-01" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "max_tokens", "messages"],
                "properties": {
                  "model": { "type": "string", "example": "claude-sonnet-4.5" },
                  "max_tokens": { "type": "integer" },
                  "system": { "type": "string" },
                  "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Message" } },
                  "stream": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Message response, or SSE when stream=true." },
          "401": { "description": "Missing or revoked key." },
          "429": { "description": "Rate limit." }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "Models this key can call",
        "operationId": "listModels",
        "responses": { "200": { "description": "OpenAI-shaped model list." } }
      }
    },
    "/api/docs/models": {
      "get": {
        "summary": "Public catalog with shelf price",
        "operationId": "docsModels",
        "security": [],
        "responses": { "200": { "description": "Model ids, brand, multiplier and price per 1M tokens." } }
      }
    },
    "/api/docs/insights": {
      "get": {
        "summary": "Last 30 days: success rate, error mix, p50 latency, plan rpm",
        "operationId": "docsInsights",
        "security": [],
        "responses": { "200": { "description": "Aggregated gateway health." } }
      }
    },
    "/api/docs/changelog": {
      "get": {
        "summary": "Release notes shipped with the repo",
        "operationId": "docsChangelog",
        "security": [],
        "responses": { "200": { "description": "Parsed CHANGELOG.md entries." } }
      }
    }
  }
}
