One OpenAI-Compatible API for Self-Hosted vLLM and OpenAI: How the Gateway Routes, Fails Over and Breaks
Any LLM gateway can route to self-hosted vLLM and OpenAI behind one base URL, because vLLM already speaks OpenAI's API. The work is in model names, endpoint gaps, failover rules and where the keys live.
An LLM gateway can route to a self-hosted vLLM server and to OpenAI through one OpenAI-compatible API because vLLM's own server already implements OpenAI's chat, completions, embeddings and Responses endpoints. LiteLLM Proxy does it with a hosted_vllm/ model entry and an api_base; Agent Router (the project formerly called Envoy AI Gateway), agentgateway, Apache APISIX and Portkey each treat vLLM as an OpenAI-type backend with a custom host. Clients keep the OpenAI SDK, change one base_url, and pick a backend by the model name. What decides whether it works in production is matching vLLM's served model name exactly, knowing which endpoints and parameters vLLM handles differently, and writing failover rules that cover 429s, 5xx errors and timeouts.
Why this is mostly a routing problem, not a translation problem
Gateways that front Anthropic, Bedrock or Gemini have to translate request formats. vLLM spares them that. Its documentation says the server "implements OpenAI's Completions API, Chat API, and more," and its own example uses the official OpenAI Python client pointed at http://localhost:8000/v1. agentgateway's vLLM page makes the same point from the other side: it uses the openai provider type because "vLLM exposes an OpenAI-compatible API." Portkey's vLLM page tells users to select OpenAI as the provider type for the same reason.
So the gateway's job reduces to three things: send each request to the right base URL with the right upstream key, decide what happens when one backend fails, and give clients one set of credentials instead of two.
The minimum working setup
LiteLLM's vLLM page is the most direct reference for the pairing. A deployment uses the hosted_vllm/ prefix (the older vllm/ prefix is marked deprecated) and an api_base pointing at the vLLM server. An OpenAI deployment uses the openai/ prefix and reads its key from the environment. Combined, a config for a self-hosted Llama and OpenAI's gpt-6-sol looks like this:
model_list:
- model_name: llama-local
litellm_params:
model: hosted_vllm/meta-llama/Llama-3.1-8B-Instruct # must equal vLLM's served model name
api_base: http://vllm-host:8000/v1
api_key: os.environ/VLLM_API_KEY # only if vLLM runs with --api-key
- model_name: gpt-6-sol
litellm_params:
model: openai/gpt-6-sol
api_key: os.environ/OPENAI_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
Start it with litellm --config config.yaml; LiteLLM's docs show the proxy listening on port 4000. The client change is one line:
from openai import OpenAI
client = OpenAI(base_url="http://gateway:4000", api_key="sk-<gateway-issued key>")
client.chat.completions.create(model="llama-local", messages=[{"role": "user", "content": "Hi"}])
client.chat.completions.create(model="gpt-6-sol", messages=[{"role": "user", "content": "Hi"}])
One caution applies to every gateway. vLLM's quickstart says the server "currently hosts one model at a time," and its Completions, Chat and Responses APIs return HTTP 404 for an unknown model name. The name the gateway forwards has to equal what vLLM serves: agentgateway's docs say the configured model "must match the --model argument used when starting vLLM," and vLLM's Codex guide says the same of --served-model-name. A mismatch is the most common reason a setup that answers /v1/models still rejects real requests. LiteLLM's own vLLM page shows its mixed-provider example with Gemini rather than OpenAI, so the OpenAI half above follows LiteLLM's standard openai/ provider syntax rather than a copy of that page.
Which endpoints pass through, and where vLLM differs
"OpenAI-compatible" covers most of what applications use, but not all of it, and the gaps show up as 400s and 404s rather than as obvious errors at setup time. vLLM's server docs, updated November 17, 2026, list what it serves and the parameters it ignores or rejects.
| Endpoint or feature | What vLLM's docs say | What trips requests |
|---|---|---|
/v1/chat/completions |
Served for generative models with a chat template | user is ignored; image_url.detail is not supported |
/v1/completions |
Served for generative models | suffix is not supported |
/v1/embeddings |
Served only when vLLM runs an embedding model | A chat model's server will not answer it |
/v1/responses |
Served, with retrieve and cancel routes | Per LiteLLM's docs, backends that don't store responses typically reject previous_response_id |
| Tool calling | auto, required, none and named functions |
Without --enable-auto-tool-choice and --tool-call-parser, named or required calls return 400 |
Structured output works through OpenAI's response_format with a JSON schema, and vLLM's extra controls (top_k, structured_outputs with regex or choice lists) go in the OpenAI client's extra_body. Its old guided_json-style fields were removed in v0.12.0, so code written against older vLLM versions breaks on current ones. Logprobs are returned, but vLLM's docs say they are computed before temperature and penalties by default (--logprobs-mode changes that) and that it "does not guarantee stable log probabilities," so they will not match OpenAI's numbers for the same text. Streaming passes through Agent Router's chat route and LiteLLM's vLLM pass-through, according to their docs.
The gateway can introduce its own gaps. agentgateway's vLLM example sets path: /v1/chat/completions on the backend; its docs warn that without it vLLM receives the client's path unchanged and rejects the request, and embeddings need a separate multi-endpoint setup. LiteLLM lists /chat/completions, /embeddings, /completions, /rerank and /audio/transcriptions for hosted_vllm/, says that provider sends /v1/responses to vLLM natively, and offers a /vllm pass-through route (since v1.72.0) for vLLM-only endpoints, without cost tracking. Agent Router's endpoint list, updated November 10, now marks /v1/responses "Fully Supported" for any OpenAI-compatible provider, alongside chat, completions, embeddings and /v1/models, while noting that it "supports a subset of the full OpenAI API." Since its 1.2 release, the project says, calling an endpoint a provider doesn't support returns 422 rather than 500, so an unsupported call no longer looks like a backend outage. APISIX's ai-proxy-multi documentation covers chat and embeddings and does not mention a Responses endpoint.
Failover: self-hosted first, OpenAI when it fails
Most teams that put vLLM and OpenAI side by side want the self-hosted model to take traffic and OpenAI to catch what it drops. Every gateway here supports that, but each defines "failure" differently.
In LiteLLM, a fallbacks entry under litellm_settings maps one model group to another, and the docs say it covers all errors, "429, 500, etc." Retries happen first:
litellm_settings:
num_retries: 2
request_timeout: 10 # seconds; a timeout counts as a failure
fallbacks: [{"llama-local": ["gpt-6-sol"]}]
router_settings:
allowed_fails: 3 # cool down a deployment after 3 failures
cooldown_time: 30
Context-length and content-policy errors use separate context_window_fallbacks and content_policy_fallbacks lists. LiteLLM's response headers say which backend answered: x-litellm-model-api-base carries the upstream base URL, and x-litellm-attempted-fallbacks counts fallback attempts, so a request that failed over should carry OpenAI's base URL and a non-zero fallback count. Since proxy v1.85.0 the docs say the old mock_testing_fallbacks flag is stripped from proxy requests; the way to test is to make vLLM actually fail in a non-production environment.
agentgateway uses priority groups. Its failover page shows an in-cluster vLLM group first and OpenAI gpt-4.1 as the fallback group, with requests moving on "when all models in a group are evicted." By default a single 5xx or connection failure evicts a backend for three seconds, but 429s count only if the unhealthyCondition expression includes them, which matters because a saturated vLLM server's typical signal is a rate limit. Agent Router lists backends by priority in an AIGatewayRoute and triggers fallback through a BackendTrafficPolicy retry policy; its example retries on 500s, connection failures and retriable status codes with a 30-second per-try timeout. APISIX's ai-proxy-multi names its triggers directly: http_429, http_5xx and instance health or rate limiting, and its docs say a read timeout before the first streamed event also falls back. Portkey's gateway README lists fallbacks on chosen error codes and up to five retries.
Splitting traffic and routing per turn
Failover is one routing rule. Two others come up once both backends are live.
Weighted routing sends a fixed share of traffic to each backend. LiteLLM sets a weight on deployments that share a model name (its example weights 9 and 1, "pick this 90% of the time"); APISIX's instances carry weight and priority, and its default balancer is weighted round robin. Because the two deployments in a weighted pair are different models, this is a canary tool for comparing a self-hosted model against OpenAI on live traffic, not a default.
Per-turn routing lets each request in a conversation go to a different model. With any of these gateways the client can do it simply by naming a different model on each call. LiteLLM also has auto routers that pick a tier per request and report it in an x-litellm-complexity-router-tier header. The catch is state: OpenAI's Responses API can hold conversation state, and LiteLLM's docs warn that stateless OpenAI-compatible backends typically reject previous_response_id with a 400, so per-turn switching works best when the client sends the full history each turn.
Parsec, a small language model lab, approaches per-turn routing differently: its routers page says it routes per turn rather than per task, between models it post-trains on a customer's traffic and a frontier model, and claims "60%" savings on real workloads without defining the workload or baseline. It publishes no price for that service, and its inference page's only code sample uses the Anthropic SDK, so it is not documented as an OpenAI-compatible backend that drops into the gateways above.
Keys and keeping the model inside your network
A gateway in this setup holds two kinds of credential. Upstream keys stay on the gateway: an OpenAI key, and a vLLM key if the server runs with --api-key. Client keys are issued by the gateway: LiteLLM generates virtual keys from a master key through /key/generate and can restrict each key to a list of models, so a team can be given the local model and not OpenAI. Agent Router puts upstream credentials in a BackendSecurityPolicy, and APISIX attaches auth headers per instance.
vLLM's own key is weaker than it looks. Its docs warn that --api-key protects only the /v1, /v2, /inference and /cohere paths, that /invocations exposes the same inference unauthenticated, and that --api-key should not be relied on alone. Keeping vLLM on a private network, reachable only by the gateway, is the fix.
That also decides where the gateway runs. LiteLLM, Agent Router, agentgateway and APISIX are software you deploy yourself (LiteLLM documents Helm and Terraform on AWS and GCP), so the gateway and vLLM can sit in the same VPC or data centre and prompts for the self-hosted model never leave it. Portkey's gateway is MIT-licensed and can be run with npx @portkey-ai/gateway; its vLLM page says that when using the hosted gateway instead, the vLLM server has to be exposed through a tunnel such as ngrok or made publicly reachable.
How much the gateway adds, and what moving traffic saves
No independent measurement of gateway overhead for a vLLM-plus-OpenAI setup has been published for any of these gateways. LiteLLM's own benchmark, against a mock OpenAI endpoint with four 4-vCPU instances, reports 2 ms median and 8 ms p95 overhead, rising to 29 ms p95 on two instances; Portkey's README says "<1ms latency" without a method. Both are vendors measuring themselves.
The cost case depends almost entirely on which OpenAI model the self-hosted one replaces. Take 3 million requests a month at 1,000 input and 250 output tokens each. On gpt-6-sol at OpenAI's listed $2.00 per million input tokens and $10.00 per million output, that is $0.0045 a request, or $13,500 a month. Moving 60% of requests to vLLM cuts the OpenAI bill by $8,100. One H100 SXM at Lambda's on-demand $4.89 an hour costs $3,570 for a 730-hour month, so the self-hosted side breaks even at about 793,000 requests, roughly 26% of this traffic; with a second GPU for redundancy the break-even rises to about 53%. Against gpt-6-luna at $0.10 and $0.50 per million, the same 3 million requests cost $675 a month in total, less than one GPU. Whether one H100 carries 1.8 million requests a month of a given model has not been measured.
Bottom line
If you want the shortest path to one OpenAI-compatible endpoint over vLLM and OpenAI, run LiteLLM Proxy next to vLLM, register hosted_vllm/ with the exact served model name, set fallbacks with retries and a timeout, and read x-litellm-model-api-base to confirm which backend answered. If your platform is Kubernetes and the Gateway API, use agentgateway or Agent Router, and add 429s to the failure condition explicitly. If you already run APISIX, ai-proxy-multi gives self-hosted-first fallback on 429 and 5xx without another component. Whichever you pick, keep vLLM on a private network, test failover by breaking vLLM rather than with mock flags, and do the cost arithmetic against the OpenAI model you would actually use, because against the cheapest ones a GPU does not pay for itself.
Sources
- vLLM, OpenAI-compatible server: https://github.com/vllm-project/vllm/blob/main/docs/serving/online_serving/openai_compatible_server.md
- vLLM, Quickstart: https://github.com/vllm-project/vllm/blob/main/docs/getting_started/quickstart.md
- vLLM, Codex integration: https://github.com/vllm-project/vllm/blob/main/docs/serving/integrations/codex.md
- vLLM, Tool calling: https://github.com/vllm-project/vllm/blob/main/docs/features/tool_calling.md
- vLLM, Structured outputs: https://github.com/vllm-project/vllm/blob/main/docs/features/structured_outputs.md
- vLLM, V1 guide (logprobs): https://github.com/vllm-project/vllm/blob/main/docs/usage/v1_guide.md
- vLLM, FAQ: https://github.com/vllm-project/vllm/blob/main/docs/usage/faq.md
- LiteLLM, vLLM provider: https://github.com/BerriAI/litellm-docs/blob/main/docs/providers/vllm.md
- LiteLLM, vLLM pass-through: https://github.com/BerriAI/litellm-docs/blob/main/docs/pass_through/vllm.md
- LiteLLM, Fallbacks and reliability: https://github.com/BerriAI/litellm-docs/blob/main/docs/proxy/reliability.md
- LiteLLM, Response headers: https://github.com/BerriAI/litellm-docs/blob/main/docs/proxy/response_headers.md
- LiteLLM, Routing: https://github.com/BerriAI/litellm-docs/blob/main/docs/routing.md
- LiteLLM, Virtual keys: https://github.com/BerriAI/litellm-docs/blob/main/docs/proxy/virtual_keys.md
- LiteLLM, Native Responses passthrough: https://github.com/BerriAI/litellm-docs/blob/main/docs/response_api_native_passthrough.md
- LiteLLM, Deploy: https://github.com/BerriAI/litellm-docs/blob/main/docs/proxy/deploy.md
- LiteLLM, Benchmarks: https://github.com/BerriAI/litellm-docs/blob/main/docs/benchmarks.md
- Agent Router, README: https://github.com/theagentrouter/agent-router
- Agent Router, 1.2 release announcement: https://theagentrouter.ai/blog/v1.2-release-announcement
- Agent Router, Supported endpoints: https://github.com/theagentrouter/agent-router/blob/main/site/docs/capabilities/llm-integrations/supported-endpoints.md
- Agent Router, Supported providers: https://github.com/theagentrouter/agent-router/blob/main/site/docs/capabilities/llm-integrations/supported-providers.md
- Agent Router, Provider fallback: https://github.com/theagentrouter/agent-router/blob/main/site/docs/capabilities/traffic/provider-fallback.md
- agentgateway, vLLM provider: https://agentgateway.dev/docs/kubernetes/latest/llm/providers/vllm/
- agentgateway, Failover: https://agentgateway.dev/docs/kubernetes/latest/llm/failover/
- Apache APISIX, ai-proxy-multi: https://apisix.apache.org/docs/apisix/plugins/ai-proxy-multi/
- Portkey, Gateway repository: https://github.com/Portkey-AI/gateway
- Portkey, vLLM integration docs: https://github.com/Portkey-AI/docs-core/blob/main/aigw/integrations/llms/vllm.mdx
- OpenAI, API pricing: https://developers.openai.com/api/docs/pricing
- Lambda, GPU cloud pricing: https://lambda.com/pricing
- Parsec vs routers: https://parseclab.ai/compare/routers/
- Parsec, Inference: https://parseclab.ai/inference/