diff --git a/docs/docs.go b/docs/docs.go index 6248bd8..0448820 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -21,6 +21,11 @@ const docTemplate = `{ "paths": { "/instances": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns a list of all instances managed by the server", "tags": [ "instances" @@ -47,6 +52,11 @@ const docTemplate = `{ }, "/instances/{name}": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the details of a specific instance by name", "tags": [ "instances" @@ -83,6 +93,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Updates the configuration of a specific instance by name", "consumes": [ "application/json" @@ -131,6 +146,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Creates a new instance with the provided configuration options", "consumes": [ "application/json" @@ -179,6 +199,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Stops and removes a specific instance by name", "tags": [ "instances" @@ -214,6 +239,11 @@ const docTemplate = `{ }, "/instances/{name}/logs": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the logs from a specific instance by name with optional line limit", "tags": [ "instances" @@ -258,6 +288,11 @@ const docTemplate = `{ }, "/instances/{name}/proxy": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Forwards HTTP requests to the llama-server instance running on a specific port", "tags": [ "instances" @@ -297,6 +332,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Forwards HTTP requests to the llama-server instance running on a specific port", "tags": [ "instances" @@ -338,6 +378,11 @@ const docTemplate = `{ }, "/instances/{name}/restart": { "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Restarts a specific instance by name", "tags": [ "instances" @@ -376,6 +421,11 @@ const docTemplate = `{ }, "/instances/{name}/start": { "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Starts a specific instance by name", "tags": [ "instances" @@ -414,6 +464,11 @@ const docTemplate = `{ }, "/instances/{name}/stop": { "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Stops a specific instance by name", "tags": [ "instances" @@ -452,6 +507,11 @@ const docTemplate = `{ }, "/server/devices": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns a list of available devices for the llama server", "tags": [ "server" @@ -475,6 +535,11 @@ const docTemplate = `{ }, "/server/help": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the help text for the llama server command", "tags": [ "server" @@ -498,6 +563,11 @@ const docTemplate = `{ }, "/server/version": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the version of the llama server command", "tags": [ "server" @@ -521,7 +591,12 @@ const docTemplate = `{ }, "/v1/": { "post": { - "description": "Handles all POST requests to /v1/*, routing to the appropriate instance based on the request body", + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Handles all POST requests to /v1/*, routing to the appropriate instance based on the request body. Requires API key authentication via the ` + "`" + `Authorization` + "`" + ` header.", "consumes": [ "application/json" ], @@ -550,6 +625,11 @@ const docTemplate = `{ }, "/v1/models": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns a list of instances in a format compatible with OpenAI API", "tags": [ "openai" diff --git a/docs/swagger.json b/docs/swagger.json index ae75018..87168b7 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -14,6 +14,11 @@ "paths": { "/instances": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns a list of all instances managed by the server", "tags": [ "instances" @@ -40,6 +45,11 @@ }, "/instances/{name}": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the details of a specific instance by name", "tags": [ "instances" @@ -76,6 +86,11 @@ } }, "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Updates the configuration of a specific instance by name", "consumes": [ "application/json" @@ -124,6 +139,11 @@ } }, "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Creates a new instance with the provided configuration options", "consumes": [ "application/json" @@ -172,6 +192,11 @@ } }, "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Stops and removes a specific instance by name", "tags": [ "instances" @@ -207,6 +232,11 @@ }, "/instances/{name}/logs": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the logs from a specific instance by name with optional line limit", "tags": [ "instances" @@ -251,6 +281,11 @@ }, "/instances/{name}/proxy": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Forwards HTTP requests to the llama-server instance running on a specific port", "tags": [ "instances" @@ -290,6 +325,11 @@ } }, "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Forwards HTTP requests to the llama-server instance running on a specific port", "tags": [ "instances" @@ -331,6 +371,11 @@ }, "/instances/{name}/restart": { "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Restarts a specific instance by name", "tags": [ "instances" @@ -369,6 +414,11 @@ }, "/instances/{name}/start": { "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Starts a specific instance by name", "tags": [ "instances" @@ -407,6 +457,11 @@ }, "/instances/{name}/stop": { "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Stops a specific instance by name", "tags": [ "instances" @@ -445,6 +500,11 @@ }, "/server/devices": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns a list of available devices for the llama server", "tags": [ "server" @@ -468,6 +528,11 @@ }, "/server/help": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the help text for the llama server command", "tags": [ "server" @@ -491,6 +556,11 @@ }, "/server/version": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns the version of the llama server command", "tags": [ "server" @@ -514,7 +584,12 @@ }, "/v1/": { "post": { - "description": "Handles all POST requests to /v1/*, routing to the appropriate instance based on the request body", + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Handles all POST requests to /v1/*, routing to the appropriate instance based on the request body. Requires API key authentication via the `Authorization` header.", "consumes": [ "application/json" ], @@ -543,6 +618,11 @@ }, "/v1/models": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "description": "Returns a list of instances in a format compatible with OpenAI API", "tags": [ "openai" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index cf45768..d6a7433 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -399,6 +399,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: List all instances tags: - instances @@ -422,6 +424,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Delete an instance tags: - instances @@ -446,6 +450,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Get details of a specific instance tags: - instances @@ -478,6 +484,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Create and start a new instance tags: - instances @@ -510,6 +518,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Update an instance's configuration tags: - instances @@ -540,6 +550,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Get logs from a specific instance tags: - instances @@ -568,6 +580,8 @@ paths: description: Instance is not running schema: type: string + security: + - ApiKeyAuth: [] summary: Proxy requests to a specific instance tags: - instances @@ -595,6 +609,8 @@ paths: description: Instance is not running schema: type: string + security: + - ApiKeyAuth: [] summary: Proxy requests to a specific instance tags: - instances @@ -620,6 +636,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Restart a running instance tags: - instances @@ -645,6 +663,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Start a stopped instance tags: - instances @@ -670,6 +690,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Stop a running instance tags: - instances @@ -685,6 +707,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: List available devices for llama server tags: - server @@ -700,6 +724,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Get help for llama server tags: - server @@ -715,6 +741,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: Get version of llama server tags: - server @@ -723,7 +751,8 @@ paths: consumes: - application/json description: Handles all POST requests to /v1/*, routing to the appropriate - instance based on the request body + instance based on the request body. Requires API key authentication via the + `Authorization` header. responses: "200": description: OpenAI response @@ -735,6 +764,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: OpenAI-compatible proxy endpoint tags: - openai @@ -751,6 +782,8 @@ paths: description: Internal Server Error schema: type: string + security: + - ApiKeyAuth: [] summary: List instances in OpenAI-compatible format tags: - openai diff --git a/pkg/handlers.go b/pkg/handlers.go index afaee99..fe2088b 100644 --- a/pkg/handlers.go +++ b/pkg/handlers.go @@ -29,6 +29,7 @@ func NewHandler(im InstanceManager, config Config) *Handler { // @Summary Get help for llama server // @Description Returns the help text for the llama server command // @Tags server +// @Security ApiKeyAuth // @Produces text/plain // @Success 200 {string} string "Help text" // @Failure 500 {string} string "Internal Server Error" @@ -50,6 +51,7 @@ func (h *Handler) HelpHandler() http.HandlerFunc { // @Summary Get version of llama server // @Description Returns the version of the llama server command // @Tags server +// @Security ApiKeyAuth // @Produces text/plain // @Success 200 {string} string "Version information" // @Failure 500 {string} string "Internal Server Error" @@ -71,6 +73,7 @@ func (h *Handler) VersionHandler() http.HandlerFunc { // @Summary List available devices for llama server // @Description Returns a list of available devices for the llama server // @Tags server +// @Security ApiKeyAuth // @Produces text/plain // @Success 200 {string} string "List of devices" // @Failure 500 {string} string "Internal Server Error" @@ -92,6 +95,7 @@ func (h *Handler) ListDevicesHandler() http.HandlerFunc { // @Summary List all instances // @Description Returns a list of all instances managed by the server // @Tags instances +// @Security ApiKeyAuth // @Produces json // @Success 200 {array} Instance "List of instances" // @Failure 500 {string} string "Internal Server Error" @@ -116,6 +120,7 @@ func (h *Handler) ListInstances() http.HandlerFunc { // @Summary Create and start a new instance // @Description Creates a new instance with the provided configuration options // @Tags instances +// @Security ApiKeyAuth // @Accept json // @Produces json // @Param name path string true "Instance Name" @@ -157,6 +162,7 @@ func (h *Handler) CreateInstance() http.HandlerFunc { // @Summary Get details of a specific instance // @Description Returns the details of a specific instance by name // @Tags instances +// @Security ApiKeyAuth // @Produces json // @Param name path string true "Instance Name" // @Success 200 {object} Instance "Instance details" @@ -189,6 +195,7 @@ func (h *Handler) GetInstance() http.HandlerFunc { // @Summary Update an instance's configuration // @Description Updates the configuration of a specific instance by name // @Tags instances +// @Security ApiKeyAuth // @Accept json // @Produces json // @Param name path string true "Instance Name" @@ -229,6 +236,7 @@ func (h *Handler) UpdateInstance() http.HandlerFunc { // @Summary Start a stopped instance // @Description Starts a specific instance by name // @Tags instances +// @Security ApiKeyAuth // @Produces json // @Param name path string true "Instance Name" // @Success 200 {object} Instance "Started instance details" @@ -261,6 +269,7 @@ func (h *Handler) StartInstance() http.HandlerFunc { // @Summary Stop a running instance // @Description Stops a specific instance by name // @Tags instances +// @Security ApiKeyAuth // @Produces json // @Param name path string true "Instance Name" // @Success 200 {object} Instance "Stopped instance details" @@ -293,6 +302,7 @@ func (h *Handler) StopInstance() http.HandlerFunc { // @Summary Restart a running instance // @Description Restarts a specific instance by name // @Tags instances +// @Security ApiKeyAuth // @Produces json // @Param name path string true "Instance Name" // @Success 200 {object} Instance "Restarted instance details" @@ -325,6 +335,7 @@ func (h *Handler) RestartInstance() http.HandlerFunc { // @Summary Delete an instance // @Description Stops and removes a specific instance by name // @Tags instances +// @Security ApiKeyAuth // @Param name path string true "Instance Name" // @Success 204 "No Content" // @Failure 400 {string} string "Invalid name format" @@ -351,6 +362,7 @@ func (h *Handler) DeleteInstance() http.HandlerFunc { // @Summary Get logs from a specific instance // @Description Returns the logs from a specific instance by name with optional line limit // @Tags instances +// @Security ApiKeyAuth // @Param name path string true "Instance Name" // @Param lines query string false "Number of lines to retrieve (default: all lines)" // @Produces text/plain @@ -398,6 +410,7 @@ func (h *Handler) GetInstanceLogs() http.HandlerFunc { // @Summary Proxy requests to a specific instance // @Description Forwards HTTP requests to the llama-server instance running on a specific port // @Tags instances +// @Security ApiKeyAuth // @Param name path string true "Instance Name" // @Success 200 "Request successfully proxied to instance" // @Failure 400 {string} string "Invalid name format" @@ -462,6 +475,7 @@ func (h *Handler) ProxyToInstance() http.HandlerFunc { // @Summary List instances in OpenAI-compatible format // @Description Returns a list of instances in a format compatible with OpenAI API // @Tags openai +// @Security ApiKeyAuth // @Produces json // @Success 200 {object} OpenAIListInstancesResponse "List of OpenAI-compatible instances" // @Failure 500 {string} string "Internal Server Error" @@ -499,8 +513,9 @@ func (h *Handler) OpenAIListInstances() http.HandlerFunc { // OpenAIProxy godoc // @Summary OpenAI-compatible proxy endpoint -// @Description Handles all POST requests to /v1/*, routing to the appropriate instance based on the request body +// @Description Handles all POST requests to /v1/*, routing to the appropriate instance based on the request body. Requires API key authentication via the `Authorization` header. // @Tags openai +// @Security ApiKeyAuth // @Accept json // @Produces json // @Success 200 "OpenAI response"