llm-proxy-ondemand
A FastAPI proxy server for vLLM with SLURM support and automatic process management.
Features
- On-demand vLLM server startup: The vLLM server is only started when the first request is received
- SLURM integration: Run vLLM on SLURM clusters with SSH reverse tunneling
- Automatic port management: Auto-select available ports if not specified
- Idle timeout: Automatically shutdown vLLM server after a configurable period of inactivity
- OpenAI-compatible API: Proxy all vLLM OpenAI-compatible endpoints (
/v1/chat/completions,/v1/models, etc.) - Health monitoring: Built-in health endpoint for monitoring
- Flexible command handling: Works with any vLLM-compatible server command (as long as target run command has --host and --port)
Installation
pip install llm-proxy-ondemand
Or install from source:
git clone <repository-url>
cd llm-proxy-ondemand
pip install -e .
Usage
Basic Usage
Start a proxy server that will launch vLLM on-demand:
llm-proxy-ondemand -- uv run --with vllm python -m vllm.entrypoints.openai.api_server --model tiiuae/falcon3-10b-instruct
Note: Use -- to separate llm-proxy-ondemand options from the vLLM command.
This will:
- Start FastAPI server on port 8100 (default)
- Auto-select an available port for vLLM (starting from 8101)
- Launch vLLM when the first request is received
- Shutdown vLLM after 30 minutes of inactivity
Custom Ports
llm-proxy-ondemand --port 8085 --target-port 8084 -- uv run --with vllm python -m vllm.entrypoints.openai.api_server --model some-model
SLURM Integration
For running on SLURM clusters with SSH reverse tunneling:
llm-proxy-ondemand --use-slurm --loopback-user e123456 --loopback-host 10.10.10.5 -- \
uv run --with vllm python -m vllm.entrypoints.openai.api_server \
--model tiiuae/falcon3-10b-instruct \
--api-key apikey \
--tensor-parallel-size 1
Custom SLURM Resources
llm-proxy-ondemand --use-slurm --srun-cmd "srun --mem=60G --gres=gpu:2 --time=4:00:00" \
--loopback-user e123456 --loopback-host 10.10.10.5 -- \
uv run --with vllm python -m vllm.entrypoints.openai.api_server --model some-model
# A working example
uv run --with vllm --with numpy==1.26.4 --with flashinfer-python==0.2.2 llm-proxy-ondemand --use-slurm --loopback-user e128356 --loopback-host 10.205.51.153 --api-key password -- python -m vllm.entrypoints.openai.api_server --model Qwen/Qwen3-0.6B
Issues that are hard to debug:
- Wrong ssh username or password, check the logging output files.
Custom Idle Timeout
llm-proxy-ondemand --idle-timeout 3600 -- uv run --with vllm python -m vllm.entrypoints.openai.api_server --model some-model
Command Line Options
--port: Port for the FastAPI proxy server (default: 8100)--target-port: Port for the vLLM server (default: auto-select from 8101+)--use-slurm: Use SLURM to run the vLLM server--srun-cmd: SLURM srun command (default: "srun --mem=30G --gres=gpu:1")--loopback-user: SSH user for reverse tunneling (required with --use-slurm)--loopback-host: SSH host for reverse tunneling (required with --use-slurm)--idle-timeout: Idle timeout in seconds before shutting down vLLM server (default: 1800)--ping-path: Path to ping the target server to check if it's ready (default: /ping)--log-level: Logging level (DEBUG, INFO, WARNING, ERROR, default: INFO)--api-key: API key for Bearer token authentication (optional)
API Endpoints
Health Check
curl http://localhost:8100/health
Response:
{
"status": "healthy",
"llm_running": false,
"target_port": 8101,
"last_request": 1640995200.0
}
OpenAI-Compatible Endpoints
All vLLM OpenAI-compatible endpoints are proxied:
POST /v1/chat/completions- Chat completionsGET /v1/models- List available models- And any other
/v1/*endpoints supported by vLLM
Example:
curl -X POST http://localhost:8100/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "tiiuae/falcon3-10b-instruct",
"messages": [{"role": "user", "content": "Hello!"}]
}'
How It Works
- Startup: llm-proxy-ondemand starts a FastAPI server immediately
- First Request: When a request is made to
/v1/*, the vLLM server is started - Proxying: All subsequent requests are forwarded to the vLLM server
- Idle Monitoring: After the configured idle timeout, the vLLM server is shutdown
- Auto-restart: The vLLM server will be restarted on the next request
SLURM Integration Details
When using --use-slurm, llm-proxy-ondemand:
- Constructs a SLURM job using the provided
--srun-cmd - Sets up SSH reverse tunneling from the compute node back to the proxy server
- Runs the vLLM command on the compute node
- Forwards requests through the SSH tunnel
The generated SLURM command looks like:
srun --mem=30G --gres=gpu:1 bash -c "
# Start reverse SSH tunnel in background
ssh -v -N -f -R 8101:localhost:8101 user@host
# Start vLLM server
uv run --with vllm python -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 8101 --model some-model
"
Requirements
For SLURM usage:
- SSH access from compute node to current node
- Proper SSH key setup for password-less authentication
Development
git clone <repository-url>
cd llm-proxy-ondemand
pip install -e .
License
MIT License
Metadata
Release files for llm-proxy-ondemand 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_proxy_ondemand-0.1.4.tar.gz | 49.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_proxy_ondemand-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.5 kB
Release files / llm_proxy_ondemand-0.1.4.tar.gz
| Download URL | llm_proxy_ondemand-0.1.4.tar.gz |
|---|---|
| Size | 49.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
821cf11faacffe7017291f4721df46792630ad6b810695b14f2c7828dd6b4a50
|
|
BLAKE2b-256 checksum How to use checksums |
1829fd37d874c97a4c3605675fc055e6824af7503fec40b973b2b3bdf456eda2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.12
|
Release files / llm_proxy_ondemand-0.1.4-py3-none-any.whl
| Download URL | llm_proxy_ondemand-0.1.4-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
235053653a2e7bd931a4722beb4352917eba00f0c899a0e4a0921201bd556a57
|
|
BLAKE2b-256 checksum How to use checksums |
da3bf6835022bf2d612291a69e42958656d8aa5f39d2ffa841b7764fd9533d18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.12
|
Security for llm-proxy-ondemand 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.