Skip to main content

vLLM Semantic Router - Intelligent routing for Mixture-of-Models

Project description

vLLM Semantic Router

Intelligent Router for Mixture-of-Models (MoM).

GitHub: https://github.com/vllm-project/semantic-router

Quick Start

Installation

# Install from PyPI
pip install vllm-sr

# Or install from source (development)
cd src/vllm-sr
pip install -e .

Usage

# Start the router (includes dashboard and first-run setup)
HF_TOKEN=hf_xxx vllm-sr serve

# Start an isolated second local stack on offset host ports
VLLM_SR_STACK_NAME=lane-b VLLM_SR_PORT_OFFSET=200 HF_TOKEN=hf_xxx vllm-sr serve

# Open the dashboard
# http://localhost:8700
# second stack example: http://localhost:8900

# Optional: open the dashboard in your browser
vllm-sr dashboard

# View logs
vllm-sr logs router
vllm-sr logs envoy
vllm-sr logs dashboard

# Check status
vllm-sr status

# Stop
vllm-sr stop

If you start in an empty directory, vllm-sr serve bootstraps a minimal workspace and opens the dashboard in setup mode. Configure your first model there, then activate routing.

Local dashboard state is persisted under .vllm-sr/dashboard-data/ and bind-mounted into the container at /app/data. User accounts, evaluation history, and ML pipeline artifacts survive vllm-sr stop followed by a new vllm-sr serve as long as that workspace directory is kept.

To run parallel local stacks from the same machine or multiple worktrees, set VLLM_SR_STACK_NAME and VLLM_SR_PORT_OFFSET before vllm-sr serve, vllm-sr status, vllm-sr dashboard, and vllm-sr stop. The stack name isolates container and network names, and the port offset shifts the published host ports while keeping internal container ports unchanged.

Advanced YAML-first setup

# Generate an advanced sample config if you prefer editing YAML directly
vllm-sr init

# Validate the sample before serving
vllm-sr validate config.yaml

vllm-sr init is optional. It generates a lean advanced sample plus .vllm-sr/router-defaults.yaml for users who want to hand-author routing config. router-defaults.yaml contains advanced runtime defaults; it is not required for first-run dashboard setup.

Features

  • Router: Intelligent request routing based on intent classification
  • Envoy Proxy: High-performance proxy with ext_proc integration
  • Dashboard: Web UI for monitoring and testing (http://localhost:8700)
  • Metrics: Prometheus metrics endpoint (http://localhost:9190/metrics)

Endpoints

After running vllm-sr serve, the following endpoints are available:

Endpoint Port Description
Dashboard 8700 Web UI for monitoring and Playground
API 8888* Chat completions API (configurable in config.yaml)
Metrics 9190 Prometheus metrics
gRPC 50051 Router gRPC (internal)
Jaeger UI 16686 Distributed tracing UI
Grafana (embedded) 8700 Dashboards at /embedded/grafana
Prometheus UI 9090 Metrics storage and querying

*Default port, configurable via listeners in config.yaml

Observability

vllm-sr serve automatically starts the observability stack:

Note: Grafana is optimized for embedded access through the dashboard. For the best experience, use http://localhost:8700/embedded/grafana where anonymous authentication is pre-configured.

Tracing is enabled by default. Traces are visible in Jaeger under the vllm-sr service name.

Configuration

Plugin Configuration

The CLI supports configuring plugins in your routing decisions. Plugins are per-decision behaviors that customize request handling (security, caching, customization, debugging).

Supported Plugin Types:

  • semantic-cache - Cache similar requests for performance
  • jailbreak - Detect and block adversarial prompts
  • pii - Detect and enforce PII policies
  • system_prompt - Inject custom system prompts
  • header_mutation - Add/modify HTTP headers
  • hallucination - Detect hallucinations in responses
  • router_replay - Record routing decisions for debugging

Plugin Examples:

  1. semantic-cache - Cache similar requests:
plugins:
  - type: "semantic-cache"
    configuration:
      enabled: true
      similarity_threshold: 0.92  # 0.0-1.0, higher = more strict
      ttl_seconds: 3600  # Optional: cache TTL in seconds
  1. jailbreak - Block adversarial prompts:
plugins:
  - type: "jailbreak"
    configuration:
      enabled: true
      threshold: 0.8  # Optional: detection sensitivity 0.0-1.0
  1. pii - Enforce PII policies:
plugins:
  - type: "pii"
    configuration:
      enabled: true
      threshold: 0.7  # Optional: detection sensitivity 0.0-1.0
      pii_types_allowed: ["EMAIL_ADDRESS"]  # Optional: list of allowed PII types
  1. system_prompt - Inject custom instructions:
plugins:
  - type: "system_prompt"
    configuration:
      enabled: true
      system_prompt: "You are a helpful assistant."
      mode: "replace"  # "replace" (default) or "insert" (prepend)
  1. header_mutation - Modify HTTP headers:
plugins:
  - type: "header_mutation"
    configuration:
      add:
        - name: "X-Custom-Header"
          value: "custom-value"
      update:
        - name: "User-Agent"
          value: "SemanticRouter/1.0"
      delete:
        - "X-Old-Header"
  1. hallucination - Detect hallucinations:
plugins:
  - type: "hallucination"
    configuration:
      enabled: true
      use_nli: false  # Optional: use NLI for detailed analysis
      hallucination_action: "header"  # "header", "body", or "none"
  1. router_replay - Record decisions for debugging:
plugins:
  - type: "router_replay"
    configuration:
      enabled: true
      max_records: 200  # Optional: max records in memory (default: 200)
      capture_request_body: false  # Optional: capture request payloads (default: false)
      capture_response_body: false  # Optional: capture response payloads (default: false)
      max_body_bytes: 4096  # Optional: max bytes to capture (default: 4096)

Validation Rules:

  • Plugin Type: Must be one of: semantic-cache, jailbreak, pii, system_prompt, header_mutation, hallucination, router_replay
  • enabled: Must be a boolean (required for most plugins)
  • threshold/similarity_threshold: Must be a float between 0.0 and 1.0
  • max_records/max_body_bytes: Must be a positive integer
  • ttl_seconds: Must be a non-negative integer
  • pii_types_allowed: Must be a list of strings (if provided)
  • system_prompt: Must be a string (if provided)
  • mode: Must be "replace" or "insert" (if provided)

CLI Commands:

# Generate an advanced YAML sample if you want to edit config directly
vllm-sr init

# Validate configuration (including plugins)
vllm-sr validate config.yaml

# Generate router config with plugins
vllm-sr config router --config config.yaml

File Descriptor Limits

The CLI automatically sets file descriptor limits to 65,536 for Envoy proxy. To customize:

export VLLM_SR_NOFILE_LIMIT=100000  # Optional (min: 8192)
vllm-sr serve

License

Apache 2.0

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vllm_sr-0.2.0.dev20260313094400.tar.gz (83.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vllm_sr-0.2.0.dev20260313094400-py3-none-any.whl (84.7 kB view details)

Uploaded Python 3

File details

Details for the file vllm_sr-0.2.0.dev20260313094400.tar.gz.

File metadata

File hashes

Hashes for vllm_sr-0.2.0.dev20260313094400.tar.gz
Algorithm Hash digest
SHA256 0fe1c767647ae5e2657ab253f7d86446e25115c6d979f675a50e0b2028b1c5e5
MD5 64e9fb8504fafb688ef4bcc298928436
BLAKE2b-256 0d6c2a52ea3f5f15fb1d0b37c0766f3db7a75c8c86a3bf9732069c015459ec6f

See more details on using hashes here.

File details

Details for the file vllm_sr-0.2.0.dev20260313094400-py3-none-any.whl.

File metadata

File hashes

Hashes for vllm_sr-0.2.0.dev20260313094400-py3-none-any.whl
Algorithm Hash digest
SHA256 97d8efac747e2b3607e09a1a59e34c03bcfbd4f7999354eb59b9b3116bdacdaa
MD5 b2c0ff46f9b46c6e21d4c450fd33d8a5
BLAKE2b-256 50e0de68e9ae019388582d0ef6350d9baf9a2d803a81a614e5f362a6e8b4a174

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page