diff --git a/core/http/endpoints/localai/backend_monitor.go b/core/http/endpoints/localai/backend_monitor.go index b3e30f512b5d..d138c5bee3e0 100644 --- a/core/http/endpoints/localai/backend_monitor.go +++ b/core/http/endpoints/localai/backend_monitor.go @@ -9,19 +9,26 @@ import ( // BackendMonitorEndpoint returns the status of the specified backend // @Summary Backend monitor endpoint // @Tags monitoring -// @Param request body schema.BackendMonitorRequest true "Backend statistics request" +// @Param model query string true "Name of the model to monitor" // @Success 200 {object} proto.StatusResponse "Response" // @Router /backend/monitor [get] func BackendMonitorEndpoint(bm *monitoring.BackendMonitorService) echo.HandlerFunc { return func(c echo.Context) error { - - input := new(schema.BackendMonitorRequest) - // Get input data from the request body - if err := c.Bind(input); err != nil { - return err + model := c.QueryParam("model") + // Fall back to binding the request body so pre-existing clients that + // sent `{"model": "..."}` with GET keep working. + if model == "" { + input := new(schema.BackendMonitorRequest) + if err := c.Bind(input); err != nil { + return err + } + model = input.Model + } + if model == "" { + return echo.NewHTTPError(400, "model query parameter is required") } - resp, err := bm.CheckAndSample(input.Model) + resp, err := bm.CheckAndSample(model) if err != nil { return err } diff --git a/docs/content/features/backend-monitor.md b/docs/content/features/backend-monitor.md index b1d16eab6481..0d23c05a5abd 100644 --- a/docs/content/features/backend-monitor.md +++ b/docs/content/features/backend-monitor.md @@ -14,11 +14,13 @@ LocalAI provides endpoints to monitor and manage running backends. The `/backend ### Request -The request body is JSON: +The model to monitor is passed as a query parameter: -| Parameter | Type | Required | Description | -|-----------|----------|----------|--------------------------------| -| `model` | `string` | Yes | Name of the model to monitor | +| Parameter | Type | Required | Location | Description | +|-----------|----------|----------|----------|--------------------------------| +| `model` | `string` | Yes | query | Name of the model to monitor | + +For backwards compatibility, a JSON body with the same field is still accepted when the `model` query parameter is not set, but new clients should use the query parameter. ### Response @@ -42,9 +44,7 @@ If the gRPC status call fails, the endpoint falls back to local process metrics: ### Usage ```bash -curl http://localhost:8080/backend/monitor \ - -H "Content-Type: application/json" \ - -d '{"model": "my-model"}' +curl "http://localhost:8080/backend/monitor?model=my-model" ``` ### Example response diff --git a/swagger/docs.go b/swagger/docs.go index e736509e9747..279a1e5f1a4b 100644 --- a/swagger/docs.go +++ b/swagger/docs.go @@ -985,13 +985,11 @@ const docTemplate = `{ "summary": "Backend monitor endpoint", "parameters": [ { - "description": "Backend statistics request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/schema.BackendMonitorRequest" - } + "type": "string", + "description": "Name of the model to monitor", + "name": "model", + "in": "query", + "required": true } ], "responses": { diff --git a/swagger/swagger.json b/swagger/swagger.json index 9d3b506e2f2e..fe52f795a28a 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -982,13 +982,11 @@ "summary": "Backend monitor endpoint", "parameters": [ { - "description": "Backend statistics request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/schema.BackendMonitorRequest" - } + "type": "string", + "description": "Name of the model to monitor", + "name": "model", + "in": "query", + "required": true } ], "responses": { diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml index 9d51aa5d517b..746177371d22 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -2363,12 +2363,11 @@ paths: /backend/monitor: get: parameters: - - description: Backend statistics request - in: body - name: request + - description: Name of the model to monitor + in: query + name: model required: true - schema: - $ref: '#/definitions/schema.BackendMonitorRequest' + type: string responses: "200": description: Response