Skip to content

Route chat management calls to the service root (#47138) - #47303

Merged
SunMarc merged 6 commits into
huggingface:mainfrom
dhruv7477:fix/chat-management-endpoints-root
Jul 22, 2026
Merged

Route chat management calls to the service root (#47138)#47303
SunMarc merged 6 commits into
huggingface:mainfrom
dhruv7477:fix/chat-management-endpoints-root

Conversation

@dhruv7477

@dhruv7477 dhruv7477 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

CI

What does this PR do?

Fixes #47138

transformers chat reuses base_url for the serve management endpoints. With the documented base_url ending in /v1, the health check requests /v1/health and model loading posts to /v1/load_model. The serve app mounts /health, /load_model and /reset at the service root; only the OpenAI-compatible inference API lives under /v1. Ran the numbers on both sides to be sure: server.py registers the management routes at root, and chat.py builds both management URLs from the raw base_url.

The fix derives a management base url by stripping a trailing /v1 segment and routes check_health and print_model_load through it, while the AsyncInferenceClient keeps the full base_url for inference. Deliberately boring on the edges: a base_url without /v1 behaves exactly as before, and a /v1 behind a reverse-proxy prefix keeps the prefix (https://host/proxy/v1 manages at https://host/proxy).

Tests cover the url derivation and both management calls, mocked, so they run anywhere with no model download.

Who can review?

CLI / serving: @Rocketknight1

transformers chat reuses base_url for the serve management endpoints, so
with the documented base_url ending in /v1 the health check requests
/v1/health and model loading posts to /v1/load_model. The serve app mounts
/health, /load_model and /reset at the service root; only the
OpenAI-compatible inference API lives under /v1.

Derive the management base url by stripping a trailing /v1 segment and use
it for check_health and print_model_load, while the AsyncInferenceClient
keeps the full base_url. A base_url without /v1 is unchanged, and a /v1
under a reverse-proxy prefix keeps the prefix.

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>
@Rocketknight1

Copy link
Copy Markdown
Member

cc @SunMarc @remi-or @LysandreJik for serving, see also the original issue at #47138!

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just a few nits

Comment thread tests/cli/test_chat.py Outdated
Comment thread src/transformers/cli/chat.py Outdated
Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx

Comment thread src/transformers/cli/chat.py Outdated
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@dhruv7477
dhruv7477 requested a review from SunMarc July 22, 2026 14:53
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 29928532700:2
Result: success | Jobs: 3 | Tests: 29 | Failures: 0 | Duration: 1m 58s

@SunMarc
SunMarc enabled auto-merge July 22, 2026 15:30
@SunMarc
SunMarc added this pull request to the merge queue Jul 22, 2026
Merged via the queue into huggingface:main with commit ffae066 Jul 22, 2026
32 checks passed
@dhruv7477
dhruv7477 deleted the fix/chat-management-endpoints-root branch July 22, 2026 15:46
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
…uggingface#47303)

* Route chat management calls to the service root (huggingface#47138)

transformers chat reuses base_url for the serve management endpoints, so
with the documented base_url ending in /v1 the health check requests
/v1/health and model loading posts to /v1/load_model. The serve app mounts
/health, /load_model and /reset at the service root; only the
OpenAI-compatible inference API lives under /v1.

Derive the management base url by stripping a trailing /v1 segment and use
it for check_health and print_model_load, while the AsyncInferenceClient
keeps the full base_url. A base_url without /v1 is unchanged, and a /v1
under a reverse-proxy prefix keeps the prefix.

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

* Address review: rename helper to get_service_root_url, drop mocked tests

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

* Build the service root url with urlunparse instead of ParseResult._replace

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

---------

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>
Sainava pushed a commit to Sainava/Sai-transformers that referenced this pull request Aug 3, 2026
…uggingface#47303)

* Route chat management calls to the service root (huggingface#47138)

transformers chat reuses base_url for the serve management endpoints, so
with the documented base_url ending in /v1 the health check requests
/v1/health and model loading posts to /v1/load_model. The serve app mounts
/health, /load_model and /reset at the service root; only the
OpenAI-compatible inference API lives under /v1.

Derive the management base url by stripping a trailing /v1 segment and use
it for check_health and print_model_load, while the AsyncInferenceClient
keeps the full base_url. A base_url without /v1 is unchanged, and a /v1
under a reverse-proxy prefix keeps the prefix.

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

* Address review: rename helper to get_service_root_url, drop mocked tests

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

* Build the service root url with urlunparse instead of ParseResult._replace

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>

---------

Signed-off-by: Dhruv Sharma <dhruv7477@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformers chat routes management endpoints under /v1 when base_url includes /v1

4 participants