{
  "openapi": "3.0.3",
  "info": {
    "title": "Xena AI API",
    "description": "Private, OpenAI-compatible AI API by Xytro Labs. Cheap, fast, and cache-heavy: repeated queries are served instantly and billed at a fraction of the normal price. Fully customizable \u2014 use your own system prompts (`prompt` / named presets via `/v1/prompts`), structured JSON output, and function/tool calling.\n\n**Retrieval + document suite (v1.2).** Beyond chat and knowledge bases the API sells the four things a RAG application actually needs: `/v1/web/search` (our own hosted search chain, returning sources *and* their extracted text), `/v1/rerank` (cross-encoder ranking \u2014 the half a vector store cannot do), `/v1/ocr` (PDFs and images to per-page markdown) and `/v1/moderations` (the same gate the web chat uses). All four are **unit priced**, so the number in the price sheet is the number the bill charges. `GET /v1/capabilities` returns the whole catalogue with prices.",
    "version": "1.2.0",
    "contact": {
      "name": "Xytro Labs"
    }
  },
  "servers": [
    {
      "url": "https://ai.xytro.site",
      "description": "Production"
    },
    {
      "url": "http://localhost:4005",
      "description": "Local"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "Generate a chat completion (OpenAI-compatible)",
        "description": "Sends messages to a Xena model. Streaming is supported. Responses may be served from cache (`cached: true`), including near-duplicate reuse via **semantic caching** (`semantic: true` + `similarity`), at reduced cost. Rate limit: 90 req/min per key (500 req/min per account); responses carry x-ratelimit-limit, x-ratelimit-remaining and x-ratelimit-window, and a 429 carries Retry-After. Supports custom system prompts (`prompt`), JSON mode (`response_format`), and function/tool calling (`tools`).",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "xael-turbo",
                      "xael-think",
                      "xael-thinkXL",
                      "yoshi-coder",
                      "yoshi-coder-max",
                      "yoshi-vision",
                      "yoshi-voice",
                      "yoshi-imagen",
                      "xael-embed",
                      "xena",
                      "xena-overclocked"
                    ],
                    "default": "xael-turbo",
                    "description": "Model ID. Niche/agentic models use the yoshi-* prefix, the basic chat/reasoning lineup uses xael-*, and xena stands alone. `xena` is on request: it returns 503 MODEL_NOT_ENABLED until enabled for your key and is hidden from GET /v1/models while disabled. The former xael-vision / xael-voice IDs still work as aliases, and the retired xael-nano / xael-mini IDs route to xena."
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Message"
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  },
                  "temperature": {
                    "type": "number"
                  },
                  "prompt": {
                    "description": "Custom system prompt. A saved preset name (see /v1/prompts), inline text, or {content}. Overrides any system message.",
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "object",
                        "properties": {
                          "content": {
                            "type": "string"
                          }
                        }
                      }
                    ]
                  },
                  "response_format": {
                    "description": "Force JSON output.",
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "json_object",
                          "json"
                        ]
                      }
                    }
                  },
                  "tools": {
                    "description": "Function/tool definitions (OpenAI-compatible).",
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "tool_choice": {
                    "description": "Force a specific tool.",
                    "oneOf": [
                      {
                        "type": "string",
                        "enum": [
                          "auto",
                          "none"
                        ]
                      },
                      {
                        "type": "object"
                      }
                    ]
                  },
                  "rag": {
                    "description": "Attach a knowledge base (see /v1/rag/kbs). Retrieved excerpts are added to the system prompt with citations; sources are returned as `rag.sources`.",
                    "type": "object",
                    "properties": {
                      "kb": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful completion (may include `cached`/`semantic`/`similarity`, `fallback`, `injection`, or `tool_calls`)"
          },
          "400": {
            "description": "Bad request (missing messages)"
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Insufficient balance"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "AI engine unavailable"
          }
        }
      }
    },
    "/v1/embeddings": {
      "post": {
        "summary": "Generate vector embeddings (OpenAI-compatible)",
        "operationId": "createEmbedding",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "xael-embed"
                    ],
                    "default": "xael-embed"
                  },
                  "input": {
                    "description": "Text or array of texts to embed.",
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Embedding list"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List available models (chat + embedding)",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "Model list"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Get your usage stats (requests, tokens, cost, cache ratio)",
        "operationId": "getUsage",
        "responses": {
          "200": {
            "description": "Usage statistics"
          }
        }
      }
    },
    "/v1/keys": {
      "get": {
        "summary": "List your API keys",
        "operationId": "listKeys",
        "responses": {
          "200": {
            "description": "Key list"
          }
        }
      },
      "post": {
        "summary": "Create an API key",
        "operationId": "createKey",
        "responses": {
          "200": {
            "description": "New key"
          }
        }
      }
    },
    "/v1/prompts": {
      "get": {
        "summary": "List your custom prompt presets",
        "operationId": "listPrompts",
        "responses": {
          "200": {
            "description": "Prompt preset list"
          }
        }
      },
      "post": {
        "summary": "Create or update a custom prompt preset (name + system-prompt content)",
        "operationId": "savePrompt",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "content"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "content": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved"
          }
        }
      }
    },
    "/v1/prompts/{name}": {
      "delete": {
        "summary": "Delete a custom prompt preset",
        "operationId": "deletePrompt",
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/v1/logs": {
      "get": {
        "summary": "Your recent request log (last 20 requests)",
        "operationId": "getLogs",
        "responses": {
          "200": {
            "description": "Recent request entries"
          }
        }
      }
    },
    "/v1/rag/kbs": {
      "get": {
        "summary": "List your knowledge bases",
        "operationId": "listKbs",
        "responses": {
          "200": {
            "description": "Knowledge base list"
          }
        }
      },
      "post": {
        "summary": "Create a knowledge base",
        "operationId": "createKb",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created"
          }
        }
      }
    },
    "/v1/rag/kbs/{id}": {
      "delete": {
        "summary": "Delete a knowledge base",
        "operationId": "deleteKb",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/v1/rag/kbs/{id}/documents": {
      "post": {
        "summary": "Add documents to a knowledge base (plain text; auto-chunked + embedded)",
        "operationId": "addDocuments",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "documents": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string"
                        },
                        "id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ingested"
          }
        }
      }
    },
    "/v1/rag/query": {
      "post": {
        "summary": "Query a knowledge base (retrieval + generated answer with citations)",
        "operationId": "ragQuery",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "kb",
                  "query"
                ],
                "properties": {
                  "kb": {
                    "type": "string"
                  },
                  "query": {
                    "type": "string"
                  },
                  "model": {
                    "type": "string",
                    "default": "xael-turbo"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Answer + sources"
          }
        }
      }
    },
    "/v1/metrics": {
      "get": {
        "summary": "Prometheus-format aggregate metrics (no auth, no per-user data)",
        "operationId": "getMetrics",
        "security": [],
        "responses": {
          "200": {
            "description": "Metrics in Prometheus text format"
          }
        }
      }
    },
    "/v1/pricing": {
      "get": {
        "summary": "Per-model token pricing",
        "operationId": "getPricing",
        "responses": {
          "200": {
            "description": "Pricing map"
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "security": [],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/web/search": {
      "post": {
        "tags": [
          "Retrieval"
        ],
        "summary": "Web search with extracted text",
        "description": "Our own hosted search chain \u2014 self-hosted first, with a fallback chain behind it \u2014 returning ranked sources AND the page text they came from. Unit priced: `xael3-search`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebSearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ranked results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebSearchResponse"
                }
              }
            }
          },
          "404": {
            "description": "Nothing found for that query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/rerank": {
      "post": {
        "tags": [
          "Retrieval"
        ],
        "summary": "Rerank documents against a query",
        "description": "Cross-encoder ranking. A vector store finds candidates; this puts the right one first. Priced per 10 documents (rounded up), model `xael3-rerank`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RerankRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ranked results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RerankResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/ocr": {
      "post": {
        "tags": [
          "Documents"
        ],
        "summary": "OCR a PDF or image to per-page markdown",
        "description": "Synchronous document to markdown. Accepts the documented `document` shapes or the shortcuts `url` / `file_id` / `base64`. Priced per page, model `xael3-ocr`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OcrRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-page markdown",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OcrResponse"
                }
              }
            }
          },
          "400": {
            "description": "No document supplied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/moderations": {
      "post": {
        "tags": [
          "Safety"
        ],
        "summary": "Classify text against the platform's content policy",
        "description": "The same gate the web chat uses, exposed so a customer can put it in front of their own pipeline: child safety, sexual content, non-consensual imagery, illegal activity, hate, self-harm and graphic violence. Model `xael3-guard`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ModerationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Classification",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModerationResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/capabilities": {
      "get": {
        "tags": [
          "Account"
        ],
        "summary": "Everything this deployment offers, with prices",
        "description": "Read straight from the pricing table the bill uses, so the catalogue and the invoice cannot disagree.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Capability catalogue",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your API key, e.g. `Authorization: Bearer xena_...`"
      }
    },
    "schemas": {
      "Message": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              }
            }
          }
        }
      },
      "WebSearchRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string",
            "description": "What to search for."
          },
          "max_results": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 5
          },
          "include_text": {
            "type": "boolean",
            "default": true,
            "description": "Return the extracted page text (up to 12k characters). Set false when you only want the ranked URLs."
          }
        }
      },
      "WebSearchResponse": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "search.result"
            ]
          },
          "query": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "text": {
            "type": "string",
            "description": "Extracted text the results are built from."
          },
          "usage": {
            "type": "object",
            "properties": {
              "searches": {
                "type": "integer"
              },
              "usd": {
                "type": "number"
              }
            }
          },
          "ms": {
            "type": "integer"
          }
        }
      },
      "RerankRequest": {
        "type": "object",
        "required": [
          "query",
          "documents"
        ],
        "properties": {
          "model": {
            "type": "string",
            "default": "bge-reranker-v2-m3"
          },
          "query": {
            "type": "string"
          },
          "documents": {
            "type": "array",
            "maxItems": 1000,
            "items": {
              "type": "string",
              "description": "Document text."
            }
          },
          "top_n": {
            "type": "integer",
            "minimum": 1
          },
          "return_documents": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "RerankResponse": {
        "type": "object",
        "properties": {
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer",
                  "description": "Position in the request's documents array."
                },
                "relevance_score": {
                  "type": "number"
                },
                "document": {
                  "type": "object"
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "documents": {
                "type": "integer"
              },
              "usd": {
                "type": "number"
              }
            }
          },
          "ms": {
            "type": "integer"
          }
        }
      },
      "OcrRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "default": "mistral/mistral-ocr-latest"
          },
          "document": {
            "type": "object",
            "description": "Documented shape: {type: document_url|image_url|base64|file, \u2026}."
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Shortcut for a PDF or image URL (mapped to document/image_url)."
          },
          "file_id": {
            "type": "string",
            "description": "Shortcut for a stored file."
          },
          "base64": {
            "type": "string",
            "description": "Shortcut for inline bytes."
          },
          "pages": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "parameters": {
            "type": "object"
          }
        }
      },
      "OcrResponse": {
        "type": "object",
        "properties": {
          "pages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "markdown": {
                  "type": "string"
                },
                "dimensions": {
                  "type": "object"
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "pages": {
                "type": "integer"
              },
              "usd": {
                "type": "number"
              }
            }
          },
          "ms": {
            "type": "integer"
          }
        }
      },
      "ModerationRequest": {
        "type": "object",
        "required": [
          "input"
        ],
        "properties": {
          "input": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ],
            "description": "Text to classify."
          }
        }
      },
      "ModerationResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "enum": [
              "moderation"
            ]
          },
          "model": {
            "type": "string",
            "enum": [
              "xael3-guard"
            ]
          },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "flagged": {
                  "type": "boolean"
                },
                "categories": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "boolean"
                  }
                },
                "category_scores": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "number"
                  }
                },
                "label": {
                  "type": "string",
                  "nullable": true
                },
                "reason": {
                  "type": "string"
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "inputs": {
                "type": "integer"
              },
              "usd": {
                "type": "number"
              }
            }
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Retrieval",
      "description": "Search, rerank and knowledge bases \u2014 the retrieval stack."
    },
    {
      "name": "Documents",
      "description": "OCR and document ingestion."
    },
    {
      "name": "Safety",
      "description": "Content classification and policy."
    },
    {
      "name": "Account",
      "description": "Keys, usage, pricing and capabilities."
    }
  ]
}