From 607efe5a4c4967b7b3e7024b00e26197576f48dc Mon Sep 17 00:00:00 2001 From: Adira Date: Tue, 21 Apr 2026 23:06:35 +0300 Subject: [PATCH] fix(backend-monitor): accept model as a query parameter (#9411) The /backend/monitor endpoint is routed as GET but its handler bound the model name from a request body, which is invalid per REST and breaks Swagger UI and OpenAPI codegen tools that refuse to send bodies with GET. Switch to reading ?model= as a query parameter and update the Swagger annotation, regenerated spec files, and documentation. The handler still falls back to body binding when the query parameter is absent, so existing clients sending {"model": "..."} continue to work. Fixes #9207 Signed-off-by: Adira Denis Muhando --- .../http/endpoints/localai/backend_monitor.go | 21 ++++++++++++------- docs/content/features/backend-monitor.md | 14 ++++++------- swagger/docs.go | 12 +++++------ swagger/swagger.json | 12 +++++------ swagger/swagger.yaml | 9 ++++---- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/core/http/endpoints/localai/backend_monitor.go b/core/http/endpoints/localai/backend_monitor.go index b3e30f512..d138c5bee 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 b1d16eab6..0d23c05a5 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 c4791350a..9d0367d69 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 c819c6171..4aa7df7ab 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 06de43e66..e46ce10c8 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -2382,12 +2382,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