{
  "openapi": "3.0.3",
  "info": {
    "title": "Nodaryx API",
    "version": "1.0.0",
    "description": "The Nodaryx public API is OpenAI-compatible. Point any OpenAI SDK at the base URL below and authenticate with a Nodaryx API key. The stable major version is v1 (part of the base URL path).",
    "x-api-version": "v1"
  },
  "servers": [
    {
      "url": "https://api.moyuncourse.site/v1",
      "description": "Nodaryx OpenAI-compatible endpoint (v1)"
    }
  ],
  "security": [{ "bearerAuth": [] }],
  "tags": [
    { "name": "Chat", "description": "Chat completions" },
    { "name": "Models", "description": "Model discovery" }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "tags": ["Chat"],
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "description": "OpenAI-compatible chat completion. Set \"stream\": true to receive server-sent events.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatCompletionRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A chat completion (or an SSE stream when stream=true).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/models": {
      "get": {
        "tags": ["Models"],
        "operationId": "listModels",
        "summary": "List available models",
        "description": "Returns the models your API key is allowed to call.",
        "responses": {
          "200": {
            "description": "The list of available models.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ModelList" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "A Nodaryx API key, sent as `Authorization: Bearer sk-nodaryx-...`."
      }
    },
    "responses": {
      "Error": {
        "description": "An error response. The body carries an error object with a machine-readable code.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" }
          }
        }
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {
            "type": "string",
            "description": "The model id to call, e.g. \"gemini-flash\".",
            "example": "gemini-flash"
          },
          "messages": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Message" }
          },
          "max_tokens": {
            "type": "integer",
            "description": "Maximum tokens to generate.",
            "minimum": 1
          },
          "temperature": {
            "type": "number",
            "description": "Sampling temperature (0–2).",
            "minimum": 0,
            "maximum": 2
          },
          "top_p": { "type": "number", "minimum": 0, "maximum": 1 },
          "stream": {
            "type": "boolean",
            "default": false,
            "description": "When true, tokens are streamed as server-sent events."
          }
        }
      },
      "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": { "$ref": "#/components/schemas/Choice" }
          },
          "usage": { "$ref": "#/components/schemas/Usage" }
        }
      },
      "Choice": {
        "type": "object",
        "properties": {
          "index": { "type": "integer" },
          "message": { "$ref": "#/components/schemas/Message" },
          "finish_reason": { "type": "string", "example": "stop" }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": { "type": "integer" },
          "completion_tokens": { "type": "integer" },
          "total_tokens": { "type": "integer" }
        }
      },
      "ModelList": {
        "type": "object",
        "properties": {
          "object": { "type": "string", "example": "list" },
          "data": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Model" }
          }
        }
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "gemini-flash" },
          "object": { "type": "string", "example": "model" },
          "owned_by": { "type": "string", "example": "nodaryx" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": { "type": "string" },
              "type": { "type": "string" },
              "code": {
                "type": "string",
                "description": "Machine-readable error code (see the Errors & Troubleshooting page)."
              }
            }
          }
        }
      }
    }
  }
}
