{
  "openapi": "3.1.0",
  "info": {
    "title": "Gonka Network API",
    "description": "OpenAI-compatible AI inference API. Up to 6,351x cheaper than GPT-4o. Drop-in replacement — change only base_url and api_key.",
    "version": "1.0.0",
    "contact": { "email": "info@gogonka.com", "url": "https://gogonka.com" }
  },
  "servers": [
    { "url": "https://gate.joingonka.ai/v1", "description": "Gonka Gateway (OpenAI-compatible)" }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/chat/completions": {
      "post": {
        "summary": "Chat Completions",
        "description": "OpenAI-compatible chat completions endpoint. Works with OpenAI SDK, LangChain, LlamaIndex and any tool that supports a custom base_url.",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages"],
                "properties": {
                  "model":       { "type": "string", "example": "moonshotai/Kimi-K2.6", "description": "Model ID from /models" },
                  "messages":    { "type": "array", "items": { "$ref": "#/components/schemas/Message" } },
                  "stream":      { "type": "boolean", "default": false },
                  "max_tokens":  { "type": "integer", "example": 1024 },
                  "temperature": { "type": "number", "minimum": 0, "maximum": 2, "default": 1 },
                  "top_p":       { "type": "number", "minimum": 0, "maximum": 1 },
                  "stop":        { "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion response",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChatCompletionResponse" }
              }
            }
          },
          "401": { "description": "Invalid or missing API key" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/models": {
      "get": {
        "summary": "List Models",
        "description": "Returns all available models with live pricing per 1M tokens.",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "List of available models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": { "type": "string", "example": "list" },
                    "data":   { "type": "array", "items": { "$ref": "#/components/schemas/Model" } }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Gonka API key. Get a free trial key at https://gogonka.com or register at https://gate.joingonka.ai"
      }
    },
    "schemas": {
      "Message": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role":    { "type": "string", "enum": ["system", "user", "assistant"] },
          "content": { "type": "string" }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id":      { "type": "string" },
          "object":  { "type": "string", "example": "chat.completion" },
          "created": { "type": "integer" },
          "model":   { "type": "string" },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index":         { "type": "integer" },
                "message":       { "$ref": "#/components/schemas/Message" },
                "finish_reason": { "type": "string", "enum": ["stop", "length", "tool_calls"] }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens":     { "type": "integer" },
              "completion_tokens": { "type": "integer" },
              "total_tokens":      { "type": "integer" }
            }
          }
        }
      },
      "Model": {
        "type": "object",
        "properties": {
          "id":         { "type": "string", "example": "moonshotai/Kimi-K2.6" },
          "object":     { "type": "string", "example": "model" },
          "owned_by":   { "type": "string", "example": "gonka-network" },
          "pricing": {
            "type": "object",
            "properties": {
              "prompt":     { "type": "string", "description": "Cost per token (prompt)" },
              "completion": { "type": "string", "description": "Cost per token (completion)" }
            }
          }
        }
      }
    }
  }
}
