# vLLM

[vLLM](https://docs.vllm.ai/en/latest/serving/online_serving/openai_compatible_server/) is an open-source inference server that exposes OpenAI- and Anthropic-compatible APIs for models you run. AISIX adds caller authentication, stable model aliases, usage reporting, and traffic controls while vLLM continues to serve inference.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before starting, prepare the following:

* One AISIX setup:

  <!-- -->

  * For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway and a write-scoped admin token. For AISIX Enterprise, follow the [AISIX Enterprise getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/aisix-cloud-quickstart.md). To request AISIX Cloud access, [contact API7](https://api7.ai/contact).
  * For the open-source AISIX gateway, prepare either a local AISIX installation or the Docker setup from the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Configure the gateway to load a declarative resources file.

* A host with vLLM 0.10.0 or later installed and enough compute and storage for the selected model. This version introduced the native Responses route used in this guide.

* Network reachability from the AISIX gateway to vLLM.

* `curl` and `jq`.

## Prepare the Inference Server[​](#prepare-the-inference-server "Direct link to Prepare the Inference Server")

Start the official example model with API-key checking enabled:

```
vllm serve NousResearch/Meta-Llama-3-8B-Instruct \

  --dtype auto \

  --api-key token-abc123
```

Export the upstream key and an API base reachable from the AISIX gateway:

```
export VLLM_API_KEY="token-abc123"

export VLLM_API_BASE="http://vllm.internal:8000/v1"
```

Replace `vllm.internal` with a resolvable host or service name. For Docker Desktop with vLLM on the host, `http://host.docker.internal:8000/v1` is a typical value. If both services share a Docker or Kubernetes network, use the vLLM service DNS name.

caution

vLLM documents that `--api-key` protects its OpenAI-compatible API routes, not every endpoint the server may expose. Keep the vLLM service on a private network and apply network policy or an authenticated reverse proxy when administrative or diagnostic routes require protection.

## Configure with AISIX Enterprise or AISIX Cloud[​](#configure-with-aisix-enterprise-or-aisix-cloud "Direct link to Configure with AISIX Enterprise or AISIX Cloud")

Export the control-plane connection details:

```
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash

# The local AISIX Enterprise quickstart uses http://localhost:8080/api

export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"

export AISIX_TOKEN="YOUR_ADMIN_TOKEN"

export ENV_ID="YOUR_ENVIRONMENT_ID"
```

vLLM is a private endpoint rather than an AISIX catalog provider. Configure it with the `byo` provider value and select the `openai` adapter explicitly.

### Create a Provider Key[​](#create-a-provider-key "Direct link to Create a Provider Key")

```
PROVIDER_KEY_ID=$(

  curl -sS -X POST "$AISIX_CP/provider_keys" \

    -H "Authorization: Bearer $AISIX_TOKEN" \

    -H "Content-Type: application/json" \

    -d '{

      "display_name": "vllm-local",

      "provider": "byo",

      "adapter": "openai",

      "api_key": "'"${VLLM_API_KEY}"'",

      "api_base": "'"${VLLM_API_BASE}"'",

      "apis": {

        "responses": {}

      },

      "allowed_environments": ["'"${ENV_ID}"'"]

    }' | jq -er '.provider_key.id'

)



echo "$PROVIDER_KEY_ID"
```

A BYO key requires `provider: "byo"`, a non-empty `api_key`, and `api_base`. This guide sets `adapter: "openai"` explicitly; when omitted, AISIX defaults a BYO key to the OpenAI-compatible adapter. AISIX sends `VLLM_API_KEY` as `Authorization: Bearer <key>`, matching the key passed to `vllm serve`.

The `apis.responses` declaration sends Responses requests to the native vLLM endpoint instead of translating them through Chat Completions.

If you intentionally run vLLM without `--api-key`, AISIX still requires a non-empty placeholder in the provider-key schema. An authenticated vLLM endpoint is preferred whenever traffic can originate outside a tightly controlled local network.

### Create a Model[​](#create-a-model "Direct link to Create a Model")

Use the model name served by vLLM:

```
MODEL_ID=$(

  curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \

    -H "Authorization: Bearer $AISIX_TOKEN" \

    -H "Content-Type: application/json" \

    -d '{

      "display_name": "vllm-llama-prod",

      "model_name": "NousResearch/Meta-Llama-3-8B-Instruct",

      "provider_key_id": "'"${PROVIDER_KEY_ID}"'"

    }' | jq -er '.model.id'

)



echo "$MODEL_ID"
```

`model_name` must match the name vLLM exposes from `/v1/models`. If you start vLLM with a served-model-name override, use that override rather than the model repository path.

### Create a Caller API Key[​](#create-a-caller-api-key "Direct link to Create a Caller API Key")

```
AISIX_API_KEY=$(

  curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

    -H "Authorization: Bearer $AISIX_TOKEN" \

    -H "Content-Type: application/json" \

    -d '{

      "display_name": "vllm-caller",

      "allowed_models": ["'"${MODEL_ID}"'"]

    }' | jq -er '.plaintext'

)



echo "$AISIX_API_KEY"
```

## Configure with AISIX OSS[​](#configure-with-aisix-oss "Direct link to Configure with AISIX OSS")

Export the upstream credential and choose the caller API key that applications will send to the gateway:

```
export VLLM_API_KEY="token-abc123"

export VLLM_API_BASE="http://vllm.internal:8000/v1"

export CALLER_API_KEY="YOUR_CALLER_API_KEY"

export CALLER_API_KEY_SHA256="$(printf '%s' "$CALLER_API_KEY" | sha256sum | cut -d ' ' -f 1)"
```

For a new gateway, use this complete resources file. For an existing gateway, merge the entries into its [current file](https://docs.api7.ai/ai-gateway/reference/resources-file.md#apply-resource-examples-safely), preserving its other resources:

resources.yaml

```
_format_version: "2"



provider_keys:

  - id: 3d74b8f4-3ab6-4769-9908-135fb78de4d8

    display_name: "vllm-local"

    provider: "vllm"

    adapter: "openai"

    api_key: ${VLLM_API_KEY}

    api_base: "${VLLM_API_BASE}"

    apis:

      responses: {}



models:

  - id: 58c833c4-ff69-4e1f-8093-06c95ebd78b7

    display_name: "vllm-llama-prod"

    provider: "vllm"

    model_name: "NousResearch/Meta-Llama-3-8B-Instruct"

    provider_key_id: 3d74b8f4-3ab6-4769-9908-135fb78de4d8



api_keys:

  - id: 07a2d7e0-0091-4164-a841-0d0999c55dbc

    display_name: "vllm-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "vllm-llama-prod"
```

If AISIX is installed locally, validate the file before loading it:

```
aisix validate --resources resources.yaml
```

After validation, start the gateway with the referenced environment variables in its process environment. Reload an existing gateway only if those variables are already available to the process; otherwise, restart it with the updated environment.

If you use Docker, adapt the validation and startup commands in the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Mount this `resources.yaml` file and pass every environment variable it references with `-e` in both commands. After the resources load, prepare the shared verification request below:

```
export AISIX_API_KEY="$CALLER_API_KEY"
```

## Verify the Provider Connection[​](#verify-the-provider-connection "Direct link to Verify the Provider Connection")

Export the AISIX gateway origin:

```
# AISIX_PROXY has no trailing slash or endpoint path

# The local quickstarts use http://127.0.0.1:3000

export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
```

Send a Responses request through the AISIX proxy:

```
curl -sS -X POST "$AISIX_PROXY/v1/responses" \

  -H "Authorization: Bearer $AISIX_API_KEY" \

  -H "Content-Type: application/json" \

  -d '{

    "model": "vllm-llama-prod",

    "input": "Say hello from vLLM."

  }'
```

AISIX sends the served model name to the native vLLM `POST /v1/responses` endpoint with the configured bearer key, then restores the AISIX alias in the response.

## Use Native Messages Through Passthrough[​](#use-native-messages-through-passthrough "Direct link to Use Native Messages Through Passthrough")

Current vLLM releases expose Anthropic-compatible `/v1/messages` and `/v1/messages/count_tokens` routes. The authenticated server configured in this guide expects bearer authentication, while AISIX sends `x-api-key` on a declared native Messages surface. Do not add `apis.messages` to this provider key.

Configure a [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md), then call `/passthrough/byo/messages` or `/passthrough/vllm/messages` for native Messages. Append `/messages/count_tokens` to the same route prefix for Count Tokens. Passthrough keeps the configured bearer credential and the vLLM request and response contract.

## Endpoint Coverage[​](#endpoint-coverage "Direct link to Endpoint Coverage")

The current vLLM [online server](https://docs.vllm.ai/en/latest/serving/online_serving/) exposes OpenAI-compatible generation, Responses, embeddings, and speech-to-text APIs, plus pooling-model APIs such as rerank and score. Availability still depends on the model and task selected when the vLLM server starts.

| Route                                                   | Behavior with the vLLM alias in this guide                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/v1/chat/completions`                                  | Supported for a text-generation model with a chat template.                                                                                                                                                                                                                                                                                                            |
| `/v1/completions`                                       | Supported for a text-generation model. vLLM does not support the OpenAI `suffix` parameter.                                                                                                                                                                                                                                                                            |
| `/v1/responses`                                         | Sent to the native Responses API in vLLM because this guide declares `apis.responses`. On a server older than 0.10.0, omit the declaration so AISIX uses the [Responses bridge](https://docs.api7.ai/ai-gateway/endpoints/responses-api.md).                                                                                                                           |
| `/v1/messages`                                          | Supported through AISIX translation to chat completions, not the native Anthropic-compatible vLLM route. Use `/passthrough/byo/messages` or `/passthrough/vllm/messages` for the native vLLM contract.                                                                                                                                                                 |
| `/v1/messages/count_tokens`                             | The configured provider key does not declare a Messages surface, so AISIX rejects this normalized route. Current vLLM releases implement Count Tokens; append `/messages/count_tokens` to the passthrough route prefix instead.                                                                                                                                        |
| `/v1/embeddings`                                        | Supported when the alias points to a vLLM server running an embedding model.                                                                                                                                                                                                                                                                                           |
| `/v1/audio/transcriptions` and `/v1/audio/translations` | Supported when the alias points to a vLLM server running a compatible automatic speech recognition model with the vLLM audio dependencies installed. Translation support is model-dependent.                                                                                                                                                                           |
| `/v1/audio/speech`                                      | Not supported because vLLM does not publish an OpenAI-compatible text-to-speech route.                                                                                                                                                                                                                                                                                 |
| `/v1/realtime`                                          | Supported when vLLM serves a Realtime-capable automatic speech recognition model and has its audio dependencies installed. AISIX relays the OpenAI-style vLLM WebSocket protocol through the normalized Realtime route. Current vLLM support is streaming speech-to-text, not the bidirectional speech-generation behavior available from some OpenAI Realtime models. |
| `/v1/rerank`                                            | Rejected because neither `byo` nor `vllm` is in the normalized route's provider allowlist. A vLLM server running a scoring model exposes `/v1/rerank`; reach it at `/passthrough/byo/rerank` or `/passthrough/vllm/rerank`.                                                                                                                                            |
| `/v1/chat/completions/batch` and `/v1/score`            | AISIX has no normalized routes for these vLLM APIs. Reach them through your passthrough route's prefix followed by `/chat/completions/batch` or `/score`.                                                                                                                                                                                                              |
| `/v1/models`                                            | Returns caller-accessible AISIX aliases, not the models served by vLLM. Use `/passthrough/byo/models` or `/passthrough/vllm/models` for the native vLLM list.                                                                                                                                                                                                          |
| `/v1/images/generations` and `/v1/videos`               | Rejected because neither provider value is in the corresponding normalized route's allowlist. vLLM does not publish matching generation APIs.                                                                                                                                                                                                                          |

Use a separate model alias, and normally a separate provider key and serving process, for each generation, embedding, or speech-to-text model. The same requirement applies to a reranking model reached through a passthrough route.

The `/passthrough/byo` and `/passthrough/vllm` prefixes above assume a [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) claiming the prefix with the vLLM server root as its `target_url`; grant the route name on the caller key's `allowed_routes`. A passthrough route relays the request body unchanged, so use the model identifier exposed by vLLM rather than the AISIX alias. It relays upstream responses, including SSE, incrementally. For the request shapes that record token usage, see [Envelope Detection and Usage](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md#envelope-detection-and-token-usage). A route binds one fixed `target_url`, so create one route per vLLM server instead of relying on model access to pick an endpoint.

vLLM also publishes root-level APIs such as `/pooling` and `/classify`. They are outside the `/v1` API base configured in this guide and have no normalized AISIX route. Reaching them through a passthrough route requires a `target_url` at the vLLM server root; do not assume a route targeting the `/v1` base above can reach them.

## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

| Symptom                             | Check                                                                                  |
| ----------------------------------- | -------------------------------------------------------------------------------------- |
| Connection refused or timeout       | Resolve and call `VLLM_API_BASE` from the AISIX gateway container.                     |
| Upstream `401`                      | Use the same value for `--api-key` and the AISIX provider key's `api_key`.             |
| Model not found                     | Compare `model_name` with `GET $VLLM_API_BASE/models`.                                 |
| Chat-template error                 | Serve a chat model with a valid chat template or configure one in vLLM.                |
| Provider key creation returns `400` | Include `provider: "byo"`, `adapter: "openai"`, a non-empty `api_key`, and `api_base`. |

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have now connected AISIX to vLLM and verified the model alias. Continue with these guides:

* [Bring Your Own Endpoint](https://docs.api7.ai/ai-gateway/providers/bring-your-own-endpoint.md): review the reusable setup and custom pricing options for private OpenAI-compatible servers.
* [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md): configure routing, retry behavior, or cost metadata for the alias.
* [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md): review supported proxy endpoints and provider-specific boundaries.
