Skip to main content

vLLM pass-through

The /vllm route forwards requests to a self-hosted vLLM server. It covers the OpenAI-compatible paths vLLM serves and the vLLM-only ones the unified API does not, such as /classify, /score and /tokenize. The gateway checks the virtual key, forwards the request and records the spend. When the model in the body names a deployment from model_list, the gateway routes through that deployment, which means its api_base, retries and fallbacks apply.

A real-world scenario​

A trust and safety team runs a vLLM classifier on an internal GPU box. Several services need /classify, which no unified endpoint offers, and nobody wants the GPU box reachable from everywhere. They register the vLLM server as a deployment on the gateway and the services call /vllm/classify with a virtual key. The box only accepts traffic from the gateway, and every classification is attributed to the calling service.

Before you start​

The gateway needs the address of the vLLM server. It looks first for a model_list deployment of provider Hosted vLLM whose model_name matches the model in the body, then for the environment below.

VariablePurpose
HOSTED_VLLM_API_BASEThe vLLM server address, such as http://vllm.internal:8000.
HOSTED_VLLM_API_KEYOptional. A key the vLLM server expects, sent as a bearer token.
model_list:
- model_name: my-vllm-model
spanway_params:
model: hosted_vllm/my-vllm-model
api_base: http://vllm.internal:8000
use_in_pass_through: true

Steps​

  1. Register the server. Open /ui/models-and-endpoints, on the Add Model tab pick Hosted vLLM under Provider, enter the model name and the server address under API Base, open Advanced Settings, turn on Use in pass through routes and click Add Model. Or set HOSTED_VLLM_API_BASE and restart the gateway.

  2. Issue a virtual key on /ui/api-keys with + Create New Key, then Create Key.

  3. Call the vLLM server through the gateway.

    curl -X POST http://localhost:4000/vllm/classify \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model": "my-vllm-model", "input": ["Please refund one of the two charges."]}'
  4. Open /ui/logs and click the newest row to see the request and the key that made it.

Expected result​

The vLLM server's own response, with its status code and headers. Streaming is streamed through as it arrives.

{
"id": "classify-2c1a",
"object": "list",
"model": "my-vllm-model",
"data": [{"index": 0, "label": "refund_request", "probs": [0.96, 0.04]}],
"usage": {"prompt_tokens": 9, "total_tokens": 9}
}

The spend log row carries the key, team and user. Set a price on the deployment under Custom Pricing to have each call costed.

Errors​

StatusMessageWhat it means and how to fix it
401Authentication Error, Invalid proxy server token passedThe virtual key is missing, wrong, expired or blocked.
403Key/team denied access to passthrough route /vllm/...The key or team lists the route in denied_passthrough_routes. The message goes on with Matched <pattern> in denied_passthrough_routes, naming the pattern to remove from the key or team.
502 or connection errorConnection refused from the gateway's HTTP clientThe gateway cannot reach the vLLM server. Check api_base or HOSTED_VLLM_API_BASE and the network path from the gateway.
Any otherThe vLLM server's own error bodyvLLM refused the request. The message is returned unchanged.

Pass-through endpoints lists every built-in route. The unified chat completions endpoint covers vLLM's OpenAI-compatible paths with guardrails and routing. The vLLM provider page covers the unified integration.