[Serve] VLLM_API_KEY / engine api_key argument is not enforced by Ray Serve LLM OpenAI endpoints
Title: VLLM_API_KEY / engine api_key argument is not enforced by Ray Serve LLM OpenAI endpoints
Body:
What happened + What you expected to happen
When deploying a model with the vLLM Docker image directly (e.g., vllm/vllm-openai), setting either:
- the
--api-keyCLI argument, or - the
VLLM_API_KEYenvironment variable
causes the OpenAI-compatible endpoints to reject requests that do not include a matching Authorization: Bearer <key> header.
I expected the same behavior when using the ray-llm Docker image with ray.serve.llm, because:
- The
LLMConfig/engine_kwargsAPI accepts vLLM engine arguments, includingapi_key. - The
runtime_env.env_varsblock inserveConfigV2can setVLLM_API_KEY. - The documentation describes the resulting endpoint as OpenAI-compatible.
However, requests with an incorrect Authorization header or no header at all still reach the model and return completions. The variables are effectively no-ops for endpoint security.
Versions / Dependencies
- Docker image:
rayproject/ray-llm:2.58.0-py312-cu130 - Ray: 2.58.0
- vLLM (bundled): 0.26.0
- Deployment entry points tested:
ray.serve.llm:build_openai_appray.llm._internal.serve.serving_patterns.data_parallel.builder:build_dp_openai_app
Reproduction
Deploy a RayService with serveConfig:
runtime_env:
env_vars:
VLLM_API_KEY: "my-secret-key"or with engine_kwargs:
engine_kwargs:
api_key: "my-secret-key"Then call the endpoint with a wrong key:
curl https://<ingress>/v1/chat/completions \
-H "Authorization: Bearer wrong-key" \
-H "Content-Type: application/json" \
-d '{"model": "moonshotai/Kimi-K2.7-Code", "messages": [{"role": "user", "content": "hi"}]}'Expected: HTTP 401 Unauthorized.
Actual: HTTP 200 with a model response.
Root cause
The vLLM OpenAI server installs an authentication middleware that validates Authorization against VLLM_API_KEY / --api-key. In contrast, the Ray Serve LLM builders create a separate FastAPI application (OpenAiIngress + LLMRouter) that routes requests to Ray Serve deployments. This FastAPI app:
- Does not import or install vLLM's auth middleware.
- Does not reference
VLLM_API_KEYanywhere in the ingress or router code.
Because VLLM_API_KEY is forwarded only to the engine process (which does not inspect HTTP headers), there is no enforcement on the HTTP surface.
Request
Please make the Ray Serve LLM OpenAI endpoint respect the same authentication settings as the native vLLM server. Options:
Preferred: When
VLLM_API_KEYorapi_keyis configured, automatically install anAuthorizationBearer-token check in the Ray Serve LLM ingress/router.Short-term: Document explicitly that
VLLM_API_KEY/api_keyare not enforced byray.serve.llmand recommend ingress-level auth as the workaround.
Until this is fixed, deployments using ray-llm are left without built-in endpoint authentication.
Source: ray-project/ray