Skip to content

[serve][llm] Serve only inference routes under direct streaming - #68528

Open
jeffreywang88 wants to merge 1 commit into
ray-project:masterfrom
jeffreywang88:serve-llm-direct-streaming-route-allowlist
Open

jeffreywang88 wants to merge 1 commit into
ray-project:masterfrom
jeffreywang88:serve-llm-direct-streaming-route-allowlist

Conversation

@jeffreywang88

@jeffreywang88 jeffreywang88 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

With direct streaming, the vLLM replica now serves only inference routes. Operational routes such as /pause, /collective_rpc and /scale_elastic_ep return 404. RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES serves extra routes when needed.

Why

OpenAiIngress exposes a fixed set of routes. Direct streaming serves vLLM's whole app instead, so clients can call every route vLLM mounts. That includes routes that control the engine and have no auth: /scale_elastic_ep is always mounted, and VLLM_SERVER_DEV_MODE=1 adds /pause, /sleep, /collective_rpc, /update_weights and more.

Why an allowlist in Ray:

  • vLLM adds routes every release and can't tell clients from operators. Ray decides what's public.
  • With elastic EP on, Ray must be able to call /scale_elastic_ep and clients must not. Ray can call it through LLMServer methods, as it already does for pause and sleep.
  • A dropped route returns 404 for any spelling, e.g. /%73cale_elastic_ep.
  • Turning off VLLM_SERVER_DEV_MODE isn't enough. It removes only the dev-mode routes. /scale_elastic_ep and 24 other routes are mounted without it, and enabling a feature such as elastic EP or fault tolerance mounts its control routes.

Changes

  • constants.py: add DIRECT_STREAMING_VLLM_ROUTES and RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES.
  • vllm_engine.py: build_asgi_app keeps only those routes.
  • Docs: a "Served routes" section in the direct streaming guide.
  • Unit tests: build the real vLLM app with dev mode and elastic EP on. Check that operational routes return 404 and that the env var adds routes.
  • Release test test_direct_streaming_drops_operational_routes: the same checks end to end, through HAProxy and a real replica.
  • test_kv_events.py: calls /reset_prefix_cache, so it now lists that route in the env var.

Routes

Direct streaming on vLLM 0.34.0:

Routes master, dev mode off master, dev mode on This PR
OpenAI: /v1/chat/completions, /v1/completions, /v1/responses (+ retrieve, cancel), /v1/embeddings, /v1/audio/transcriptions, /v1/audio/translations, /v1/score, /v1/rerank, /v1/models served served served
Anthropic: /v1/messages, /v1/messages/count_tokens served served served
vLLM: /tokenize, /detokenize, /pooling, /classify, /score, /rerank served served served
Elastic EP: /scale_elastic_ep, /is_scaling_elastic_ep served served 404
Monitoring: /health, /ping, /metrics, /load, /version, /kv_event_sources served served 404
API docs: /docs, /redoc, /openapi.json served served 404
Other vLLM APIs: /invocations, /generative_scoring, /inference/v1/*, /v1/chat/completions/batch, /v1/decisions, /v1/systemone, */render, */derender served served 404
Dev mode: /pause, /resume, /sleep, /wake_up, /collective_rpc, /abort_requests, /reset_prefix_cache, /update_weights, /server_info and 14 more 404 served 404
Feature-gated: /v1/load_lora_adapter, /v1/fault_tolerance/*, /start_profile, /tokenizer_info, /checkpoint/*, /v1/realtime, Cohere routes, endpoint plugin routes served when enabled served when enabled 404

RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES can serve any 404 route again. Ray's /-/healthz health checks are unaffected.

Validation

Live: direct streaming with HAProxy, Qwen/Qwen3-0.6B, vLLM 0.34.0, VLLM_SERVER_DEV_MODE=1.

Request master This PR
chat, completions, messages, tokenize, models 200 200
/scale_elastic_ep, /%73cale_elastic_ep 200, scale runs 404
/server_info, /is_paused, /reset_prefix_cache, /collective_rpc, /metrics, /health reachable 404

With RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES=/reset_prefix_cache, that route returns 200.

Tests:

  • Both new unit tests fail without the change.
  • The new release test fails on master (/scale_elastic_ep reaches the handler) and passes with this PR.
  • Existing direct streaming and LLMServer unit tests give the same results before and after.
  • test_kv_events.py::TestKvEvents fails locally on both master and this PR, before it reaches /reset_prefix_cache, so I couldn't run that change end to end.

Related issues

Related: vllm-project/vllm#59094, which puts /scale_elastic_ep behind vLLM's --api-key.

AI assistance (🤖 Claude Code) was used to prepare this PR.

@jeffreywang88
jeffreywang88 requested review from a team as code owners November 24, 2026 21:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request restricts the routes served by the direct-streaming application to a predefined set of client-facing inference routes, dropping unauthenticated operational routes (such as /pause and /sleep) by default. It also introduces the RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES environment variable to allow users to expose additional routes. The feedback suggests normalizing these extra routes to ensure they always start with a leading slash / to prevent configuration mismatches, and defensively accessing the path attribute on Starlette routes to avoid potential AttributeErrors.

Comment on lines +139 to +140
dropped = sorted({r.path for r in app.routes if r.path not in allowed})
app.routes[:] = [r for r in app.routes if r.path in allowed]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In Starlette/FastAPI, not all route classes are guaranteed to have a path attribute (for example, custom route types or Starlette's Host routing class). Accessing r.path directly can raise an AttributeError. We should use getattr or check hasattr to defensively handle such routes.

Suggested change
dropped = sorted({r.path for r in app.routes if r.path not in allowed})
app.routes[:] = [r for r in app.routes if r.path in allowed]
dropped = sorted({r.path for r in app.routes if hasattr(r, "path") and r.path not in allowed})
app.routes[:] = [r for r in app.routes if getattr(r, "path", None) in allowed]

@jeffreywang88
jeffreywang88 force-pushed the serve-llm-direct-streaming-route-allowlist branch 2 times, most recently from da2ac51 to 913c284 Compare November 24, 2026 22:23
@jeffreywang88
jeffreywang88 force-pushed the serve-llm-direct-streaming-route-allowlist branch from 913c284 to ef4faea Compare November 24, 2026 22:48
@jeffreywang88 jeffreywang88 added the go add ONLY when ready to merge, run all tests label Nov 24, 2026
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue docs An issue or change related to documentation release-test release test labels Nov 25, 2026
@mbartholet

Copy link
Copy Markdown

Heads-up from #68623, which adds /v1/rerank and /v2/rerank to the default OpenAiIngress.

The allowlist in this PR has /v1/rerank and /rerank, but not /v2/rerank (vLLM's path for the Cohere v2 client). Could "/v2/rerank" be added to DIRECT_STREAMING_VLLM_ROUTES? Otherwise, once both PRs are merged:

  • /v2/rerank works in the default mode but returns 404 with direct streaming.
  • test_rerank_model in release/llm_tests/serve/test_llm_serve_integration.py fails in the direct-streaming release job, since it calls both paths.

If it's easier, I can add it in a follow-up after whichever PR lands second.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation go add ONLY when ready to merge, run all tests release-test release test serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants