Skip to content

Commit e201e94

Browse files
committed
fix(backend-monitor): accept model as a query parameter
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=<name> 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 <dennisadira@gmail.com>
1 parent ad74273 commit e201e94

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

core/http/endpoints/localai/backend_monitor.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ import (
99
// BackendMonitorEndpoint returns the status of the specified backend
1010
// @Summary Backend monitor endpoint
1111
// @Tags monitoring
12-
// @Param request body schema.BackendMonitorRequest true "Backend statistics request"
12+
// @Param model query string true "Name of the model to monitor"
1313
// @Success 200 {object} proto.StatusResponse "Response"
1414
// @Router /backend/monitor [get]
1515
func BackendMonitorEndpoint(bm *monitoring.BackendMonitorService) echo.HandlerFunc {
1616
return func(c echo.Context) error {
17-
18-
input := new(schema.BackendMonitorRequest)
19-
// Get input data from the request body
20-
if err := c.Bind(input); err != nil {
21-
return err
17+
model := c.QueryParam("model")
18+
// Fall back to binding the request body so pre-existing clients that
19+
// sent `{"model": "..."}` with GET keep working.
20+
if model == "" {
21+
input := new(schema.BackendMonitorRequest)
22+
if err := c.Bind(input); err != nil {
23+
return err
24+
}
25+
model = input.Model
26+
}
27+
if model == "" {
28+
return echo.NewHTTPError(400, "model query parameter is required")
2229
}
2330

24-
resp, err := bm.CheckAndSample(input.Model)
31+
resp, err := bm.CheckAndSample(model)
2532
if err != nil {
2633
return err
2734
}

docs/content/features/backend-monitor.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ LocalAI provides endpoints to monitor and manage running backends. The `/backend
1414

1515
### Request
1616

17-
The request body is JSON:
17+
The model to monitor is passed as a query parameter:
1818

19-
| Parameter | Type | Required | Description |
20-
|-----------|----------|----------|--------------------------------|
21-
| `model` | `string` | Yes | Name of the model to monitor |
19+
| Parameter | Type | Required | Location | Description |
20+
|-----------|----------|----------|----------|--------------------------------|
21+
| `model` | `string` | Yes | query | Name of the model to monitor |
22+
23+
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.
2224

2325
### Response
2426

@@ -42,9 +44,7 @@ If the gRPC status call fails, the endpoint falls back to local process metrics:
4244
### Usage
4345

4446
```bash
45-
curl http://localhost:8080/backend/monitor \
46-
-H "Content-Type: application/json" \
47-
-d '{"model": "my-model"}'
47+
curl "http://localhost:8080/backend/monitor?model=my-model"
4848
```
4949

5050
### Example response

swagger/docs.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -985,13 +985,11 @@ const docTemplate = `{
985985
"summary": "Backend monitor endpoint",
986986
"parameters": [
987987
{
988-
"description": "Backend statistics request",
989-
"name": "request",
990-
"in": "body",
991-
"required": true,
992-
"schema": {
993-
"$ref": "#/definitions/schema.BackendMonitorRequest"
994-
}
988+
"type": "string",
989+
"description": "Name of the model to monitor",
990+
"name": "model",
991+
"in": "query",
992+
"required": true
995993
}
996994
],
997995
"responses": {

swagger/swagger.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -982,13 +982,11 @@
982982
"summary": "Backend monitor endpoint",
983983
"parameters": [
984984
{
985-
"description": "Backend statistics request",
986-
"name": "request",
987-
"in": "body",
988-
"required": true,
989-
"schema": {
990-
"$ref": "#/definitions/schema.BackendMonitorRequest"
991-
}
985+
"type": "string",
986+
"description": "Name of the model to monitor",
987+
"name": "model",
988+
"in": "query",
989+
"required": true
992990
}
993991
],
994992
"responses": {

swagger/swagger.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,12 +2363,11 @@ paths:
23632363
/backend/monitor:
23642364
get:
23652365
parameters:
2366-
- description: Backend statistics request
2367-
in: body
2368-
name: request
2366+
- description: Name of the model to monitor
2367+
in: query
2368+
name: model
23692369
required: true
2370-
schema:
2371-
$ref: '#/definitions/schema.BackendMonitorRequest'
2370+
type: string
23722371
responses:
23732372
"200":
23742373
description: Response

0 commit comments

Comments
 (0)