transformers chat routes management endpoints under /v1 when base_url includes /v1
Author: VectorPeak
Pull request: no

﻿### System Info

- `transformers` source checkout: current `main`
- Affected command: `transformers chat`
- Related local serve endpoints:
  - OpenAI-compatible inference API: `/v1/...`
  - management endpoints: `/health`, `/load_model`

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts
- [x] The `transformers chat` CLI

### Tasks

- [x] An officially supported task in the `examples` folder
- [ ] My own task or dataset

### Reproduction

`transformers chat` documents the `base_url` argument with an OpenAI-compatible `/v1` example:

```bash
transformers chat HuggingFaceTB/SmolLM3-3B http://localhost:8000/v1
```

However, the CLI also uses the same `base_url` for local serve management endpoints. With `base_url=http://localhost:8000/v1`, the current URL construction can request:

```text
GET  http://localhost:8000/v1/health
POST http://localhost:8000/v1/load_model
```

The serve app exposes the management endpoints at the service root instead:

```text
GET  http://localhost:8000/health
POST http://localhost:8000/load_model
```

The OpenAI-compatible inference API remains under `/v1`, for example `/v1/chat/completions`.

A minimal code-path reproduction does not require downloading a model:

```python
from transformers.cli.chat import Chat, RichInterface

# Health check currently builds from the raw API base URL.
Chat.check_health("http://localhost:8000/v1")

# Model loading currently posts to base_url + "/load_model".
RichInterface(
    model_id="dummy-model",
    user_id="tester",
    base_url="http://localhost:8000/v1",
).print_model_load("dummy-model")
```

### Expected behavior

`base_url=http://localhost:8000/v1` should keep using `/v1` for the OpenAI-compatible inference client, while routing local management calls to the service root:

```text
GET  http://localhost:8000/health
POST http://localhost:8000/load_model
```

In other words, `transformers chat` should distinguish between:

- the OpenAI-compatible API base URL, usually `http://localhost:8000/v1`
- the Transformers serve management root, usually `http://localhost:8000`

### Actual behavior

The same `/v1` base URL can be reused for management endpoints, producing `/v1/health` and `/v1/load_model`. Those paths do not match the route layout exposed by `transformers serve`, where `/health` and `/load_model` are root-level management endpoints.

### Possible fix

A narrow fix would derive a separate management base URL inside `transformers chat`:

- keep the user-provided `base_url` unchanged for `AsyncInferenceClient`
- derive a management base URL for `/health` and `/load_model`
- strip only an exact root `/v1` API path for management calls
- leave unrelated paths such as `/proxy/v1` unchanged

I have a small local patch and focused tests for this behavior. The relevant local validation passed:

```text
python -m pytest tests/cli/test_chat.py -q
# 7 passed

python -m ruff check src/transformers/cli/chat.py tests/cli/test_chat.py
# All checks passed

python -m ruff format --check src/transformers/cli/chat.py tests/cli/test_chat.py
# 2 files already formatted

git diff --check
# passed
```

### Duplicate check

I searched issues and PRs with:

```text
chat base_url v1 health load_model
```

and did not find an obvious existing issue or PR for this specific `transformers chat` management endpoint routing problem.


Comments:
This one's real. The chat CLI reuses `base_url` for the management calls, so with `base_url=.../v1` it knocks on `/v1/health` and `/v1/load_model`. But `server.py` parks `/health`, `/load_model` and `/reset` at the root; `/v1` is inference-only. So the fix is to send management calls to the service root and leave the OpenAI client on `/v1`. I'll take this one and open a PR.