{
  "openapi": "3.0.3",
  "info": {
    "title": "Tabby Server",
    "description": "\n[![tabby stars](https://img.shields.io/github/stars/TabbyML/tabby?style=social)](https://github.com/TabbyML/tabby)\n\nOpenAPI documentation for [tabby](https://github.com/TabbyML/tabby), a self-hosted AI coding assistant.",
    "license": { "name": "Apache 2.0", "url": "https://github.com/TabbyML/tabby/blob/main/LICENSE" },
    "version": "0.1.0"
  },
  "servers": [
    { "url": "https://playground.app.tabbyml.com", "description": "Playground server" },
    { "url": "http://localhost:8080", "description": "Local server" }
  ],
  "paths": {
    "/v1/completions": {
      "post": {
        "tags": ["v1"],
        "operationId": "completion",
        "requestBody": {
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CompletionRequest" } } },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CompletionResponse" } } }
          },
          "400": { "description": "Bad Request" }
        }
      }
    },
    "/v1/events": {
      "post": {
        "tags": ["v1"],
        "operationId": "event",
        "requestBody": {
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LogEventRequest" } } },
          "required": true
        },
        "responses": { "200": { "description": "Success" }, "400": { "description": "Bad Request" } }
      }
    },
    "/v1/health": {
      "post": {
        "tags": ["v1"],
        "operationId": "health",
        "responses": {
          "200": {
            "description": "Success",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HealthState" } } }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Choice": {
        "type": "object",
        "required": ["index", "text"],
        "properties": {
          "index": { "type": "integer", "format": "int32", "minimum": 0.0 },
          "text": { "type": "string" }
        }
      },
      "CompletionRequest": {
        "type": "object",
        "properties": {
          "prompt": { "type": "string", "example": "def fib(n):", "nullable": true },
          "language": {
            "type": "string",
            "description": "Language identifier, full list is maintained at\nhttps://code.visualstudio.com/docs/languages/identifiers",
            "example": "python",
            "nullable": true
          },
          "segments": { "allOf": [{ "$ref": "#/components/schemas/Segments" }], "nullable": true },
          "user": { "type": "string", "nullable": true }
        },
        "example": {
          "language": "python",
          "segments": { "prefix": "def fib(n):\n    ", "suffix": "\n        return fib(n - 1) + fib(n - 2)" }
        }
      },
      "CompletionResponse": {
        "type": "object",
        "required": ["id", "choices"],
        "properties": {
          "id": { "type": "string" },
          "choices": { "type": "array", "items": { "$ref": "#/components/schemas/Choice" } }
        }
      },
      "HealthState": {
        "type": "object",
        "required": ["model", "device", "compute_type", "arch", "cpu_info", "cpu_count", "cuda_devices", "version"],
        "properties": {
          "model": { "type": "string" },
          "device": { "type": "string" },
          "compute_type": { "type": "string" },
          "arch": { "type": "string" },
          "cpu_info": { "type": "string" },
          "cpu_count": { "type": "integer", "minimum": 0.0 },
          "cuda_devices": { "type": "array", "items": { "type": "string" } },
          "version": { "$ref": "#/components/schemas/Version" }
        }
      },
      "LogEventRequest": {
        "type": "object",
        "required": ["type", "completion_id", "choice_index"],
        "properties": {
          "type": { "type": "string", "description": "Event type, should be `view` or `select`.", "example": "view" },
          "completion_id": { "type": "string" },
          "choice_index": { "type": "integer", "format": "int32", "minimum": 0.0 }
        }
      },
      "Segments": {
        "type": "object",
        "required": ["prefix"],
        "properties": {
          "prefix": { "type": "string", "description": "Content that appears before the cursor in the editor window." },
          "suffix": {
            "type": "string",
            "description": "Content that appears after the cursor in the editor window.",
            "nullable": true
          }
        }
      },
      "Version": {
        "type": "object",
        "required": ["build_date", "build_timestamp", "git_sha", "git_describe"],
        "properties": {
          "build_date": { "type": "string" },
          "build_timestamp": { "type": "string" },
          "git_sha": { "type": "string" },
          "git_describe": { "type": "string" }
        }
      }
    }
  }
}
