Best Open-Source OpenAI-Compatible API Server for Production in 2026: vLLM vs SGLang vs Ollama vs TGI
For a self-hosted OpenAI API alternative in production, run vLLM or SGLang behind LiteLLM. Here is what each server actually implements, what prefix caching buys, and when renting beats owning.
The best open-source OpenAI-compatible API server for production in 2026 is vLLM, with SGLang as an equal choice when your requests share long prefixes and LiteLLM as an optional gateway in front for routing and fallback. Ollama and llama.cpp's server speak the same API but are built around one machine and, in Ollama's case, one request at a time by default. TGI is no longer an option for new builds: Hugging Face archived it on March 21, 2026. Before buying GPUs, price a hosted endpoint for the same open-weight model, because at moderate volume it is cheaper than one rented H100.
What "an alternative to the OpenAI API" actually means
Replacing the OpenAI API takes two separate choices. One is an open-weight model. The other is a server that answers the same HTTP routes, so the OpenAI SDK in your application keeps working when you change its base URL. The server decides how much of your code survives the switch and how many users one GPU can carry; the model decides answer quality, licence terms and how much GPU memory you need.
The compatibility question has also become harder. OpenAI's newer Responses API, tool calling and JSON-schema output are now everyday parts of production code, and the servers differ most on exactly those features. Plain /v1/chat/completions with streaming works on all four servers covered here. The differences are elsewhere.
Endpoint by endpoint, what each server implements
The table below reflects each project's own documentation for the releases current in mid-November 2026: vLLM v0.34.0 (released November 16), SGLang v0.5.23 (November 2), Ollama v0.40.16 (November 9) and llama.cpp's rolling server builds.
| Server | Responses API | Tool calling and JSON schema | Embeddings and audio |
|---|---|---|---|
| vLLM v0.34.0 | /v1/responses, plus retrieve and cancel |
Auto, required, none and named; needs a parser flag. Structured output on by default | Embeddings; transcription and translation on speech models |
| SGLang v0.5.23 | Documented for gpt-oss models | Parser flag per model family; JSON schema, regex or EBNF | Embeddings with --is-embedding; audio in the separate SGLang Omni project |
| Ollama v0.40.16 | Non-stateful only | Tools, but no tool_choice on chat; JSON mode |
Embeddings; speech, transcription and translation |
| llama.cpp server | /v1/responses |
Tools with --jinja; json_schema response format |
Embeddings; speech output; realtime transcription |
vLLM's coverage is the broadest. Its server docs list completions, chat, a batch chat route, Responses, embeddings and the two audio routes, and say the Responses API "is compatible with OpenAI's Responses API" through the official Python client. Tool calling needs two launch flags, --enable-auto-tool-choice and a --tool-call-parser matched to the model family, and the docs list parsers for Llama, Qwen, Mistral, DeepSeek, gpt-oss, Kimi-K2 and others. One cost hides in named tool choice: it runs through the structured-output engine, and vLLM warns the first such request can take "several seconds of latency (or more)" while the grammar compiles.
SGLang's docs index covers chat and completions, vision and embeddings; the Responses API appears in its gpt-oss guide, with built-in web search and a Python tool, rather than as a general feature for every model. Its structured output defaults to the XGrammar backend and allows one constraint type per request.
Ollama documents more than its reputation suggests, including a Responses route and the audio endpoints added in v0.40.8 and v0.40.12. Its Responses support is stateless ("Only the non-stateful flavor is supported"), and chat completions do not accept tool_choice, which matters if your code forces a specific function. llama.cpp's server now lists chat, Responses, embeddings, an OpenAI-style speech endpoint (WAV or PCM, not the MP3 default OpenAI uses) and realtime transcription.
Why vLLM is the default, and where it can bite
vLLM is the safe default because it covers the most OpenAI routes, supports the most model families through its tool parsers, and turns on structured output and prefix caching without extra configuration. Its engine configuration sets enable_prefix_caching to true.
The production caveat is security, not speed. vLLM's own server docs warn that --api-key only protects routes under /v1, /v2, /inference and /cohere, and that /invocations "exposes the same inference capabilities" without authentication. "Do not rely on --api-key alone to secure vLLM," the docs say, recommending a reverse proxy. Any production deployment should put something in front of it, which is one reason a gateway layer is common.
When SGLang's RadixAttention wins, and when it doesn't
SGLang's case rests on reusing work across requests. Its RadixAttention, as the LMSYS team described it on January 17, 2024, keeps the key-value cache for both prompts and outputs in a radix tree and evicts the least recently used leaves when memory fills. Requests that start with the same tokens (a long system prompt, few-shot examples, a shared RAG document, earlier turns of a chat, agent loops) skip recomputing that prefix. SGLang enables it by default; --disable-radix-cache turns it off.
The often-repeated speed claims come from that period. The 2024 blog reported "up to 5 times higher throughput" than Guidance and vLLM on Llama-7B and Mixtral-8x7B on A10G GPUs, and the SGLang paper, revised in June 2024, says "up to 6.4x." Those comparisons are against vLLM as it was then. vLLM now ships its own automatic prefix caching, on by default, hashing each block of cached tokens together with the prefix before it so a matching request can reuse it.
So the gap today is narrower than the old numbers suggest, and nobody has published a current, reproducible measurement of it on one model and GPU at 1, 16, 64 and 256 concurrent requests. What the two projects' docs do establish is where the effect can and cannot appear. vLLM's documentation says prefix caching only shortens prefill, the processing of the prompt, and "does not bring performance gain" when answers are long or prompts share nothing. That rule applies to both engines. Prefix reuse pays when prompts are long, shared and outputs are short: classification, extraction, RAG over a fixed corpus, multi-turn agents. It does nothing for long-form generation from unique prompts. SGLang also offers a lpm (longest prefix match) scheduling policy, though its default is first-come, first-served.
If your workload looks like the first group, test SGLang against vLLM on your own traffic before choosing. If it looks like the second, the choice will come down to features and model support, where vLLM has the edge.
How to test both on your own hardware
Since no current head-to-head has been published in a form anyone can re-run, your own test is the only way to settle it, and it is not hard to design. Pin one model, one GPU type and exact versions of both servers. Replay a sample of real prompts, not synthetic ones, at fixed concurrency levels such as 1, 16, 64 and 256. Record throughput in output tokens per second, time to first token and time per output token at each level, and report percentiles rather than averages. Run it twice: once with your real system prompts and RAG context, once with the shared prefix stripped out. The difference between those runs is what prefix caching is worth to you. Publish the script with the numbers, so the next version can be compared.
Where Ollama and llama.cpp fit
Ollama's defaults are built for one user. Its FAQ says each model processes "parallel requests ... default 1," queues up to 512 more before rejecting, and binds to 127.0.0.1:11434. Raising OLLAMA_NUM_PARALLEL multiplies the memory needed for context. It is a good development stand-in for the production server, and a reasonable choice for an internal tool with a handful of users.
llama.cpp's server is the stronger of the two for small deployments: its README lists parallel decoding for multiple users, and continuous batching and prompt caching are on by default.
Where LiteLLM fits
LiteLLM is not a model server. Its README describes it as an "Open Source AI Gateway for 100+ LLMs" that lets you "Call any LLM in OpenAI format," with virtual keys, spend tracking, load balancing and a router "with retry/fallback logic across multiple deployments." Its provider list includes vLLM and Ollama. The usual pattern is LiteLLM in front, one or more vLLM or SGLang servers behind it, and a hosted API as the fallback when your GPUs are busy or down. Its virtual keys also give every team its own credential, which helps with vLLM's authentication caveat as long as the model servers themselves stay off the public network.
The cost is an extra network hop. LiteLLM's README claims "8ms P95 latency at 1k RPS" from the project's own benchmark. Independent measurements of what it adds in front of a real model server have not been published; at that figure it is small next to model latency, but measure it in your test run.
Choosing the model you serve
The model sets the memory bill and the licence. OpenAI's gpt-oss-120b is Apache 2.0, has 117 billion parameters with 5.1 billion active per token, and its model card says it runs "on a single 80GB GPU" such as an H100; gpt-oss-20b runs "within 16GB of memory." Both only work correctly in OpenAI's harmony format; vLLM and SGLang each list a gpt-oss tool parser. Qwen3-8B is Apache 2.0 with 8.2 billion parameters and a 32,768-token native context. Mistral Small 3.2 (24B) is Apache 2.0, but needs about 55 GB of GPU memory at 16-bit precision. DeepSeek-V3 is far larger, 671 billion parameters with 37 billion active; its weights permit commercial use under DeepSeek's own model agreement, and its reference setup uses two nodes of eight GPUs. Llama 3.1's community licence requires "Built with Llama" attribution and a separate licence above 700 million monthly users.
For most teams replacing an OpenAI model, start with gpt-oss-120b on one 80 GB GPU for general work, or gpt-oss-20b or Qwen3-8B where latency and cost matter more than breadth.
A smaller model trained on your own traffic can beat a general one on a narrow task such as one extraction schema, one support domain or one classifier, but whether it does for yours has to be tested against a held-out sample of your requests. Parsec, a small language model lab, offers that loop as a managed service: it traces production requests, builds datasets and evaluations the customer approves, trains with SFT or LoRA, serves the result and sends low-confidence requests to a closed frontier model. Its inference page says "Weights: Yours. Download them." Parsec says a first post-trained model takes about four weeks, without a stated baseline. It publishes no price, its serving runs on a shared cluster "alongside other teams'," and its only code sample uses the Anthropic SDK rather than OpenAI's.
When you should not run GPUs at all
The no-GPU path is a hosted endpoint serving the same open weights over an OpenAI-compatible API. Together's docs say switching takes only the API key and the base URL, and list chat, completions, Responses, structured outputs and function calling. Fireworks works with the OpenAI client pointed at its own base URL. Both list gpt-oss-120b at $0.15 per million input tokens and $0.60 per million output, and Fireworks lists cached input at $0.015, which matters for the same long, repeated system prompts that make prefix caching pay.
Take a workload of 3 million requests a month, each 1,000 input and 250 output tokens: 3 billion tokens in and 750 million out. On OpenAI, at its list prices, that costs $675 a month on gpt-6-luna ($0.10 in, $0.50 out), $2,250 on gpt-5-mini and $13,500 on gpt-6-sol. Hosted gpt-oss-120b costs $900. One H100 for a 30-day month costs $3,952.80 as a Together dedicated endpoint at $5.49 an hour, $2,872.80 on Together's on-demand clusters at $3.99, or $5,760 at Fireworks' $8.00 on-demand rate, before a second GPU for redundancy. At this mix, a single self-hosted H100 only beats the hosted price above roughly 9.6 million requests a month, and whether one H100 carries that load has not been measured. Self-hosting is a decision about control, data location and steady high volume, not a default saving.
Bottom line
If you need your own servers, run vLLM for broad OpenAI compatibility and model support, secure it behind LiteLLM or a reverse proxy, and test SGLang against it if your prompts share long system prompts or RAG context. Use Ollama for development and small internal tools, llama.cpp's server for small deployments, and nothing new on TGI. Serve gpt-oss-120b or a smaller Apache 2.0 model to keep licences simple. If your volume is moderate, a hosted gpt-oss-120b endpoint at $0.15 and $0.60 per million tokens is cheaper than one rented H100, and it keeps the same OpenAI SDK code.
Sources
- vLLM, OpenAI-compatible server docs (GitHub): https://github.com/vllm-project/vllm/blob/main/docs/serving/online_serving/openai_compatible_server.md
- vLLM, Tool calling docs (GitHub): https://github.com/vllm-project/vllm/blob/main/docs/features/tool_calling.md
- vLLM, Structured outputs docs (GitHub): https://github.com/vllm-project/vllm/blob/main/docs/features/structured_outputs.md
- vLLM, Automatic prefix caching docs (GitHub): https://github.com/vllm-project/vllm/blob/main/docs/features/automatic_prefix_caching.md
- vLLM, Prefix caching design (GitHub): https://github.com/vllm-project/vllm/blob/main/docs/design/prefix_caching.md
- vLLM, Cache configuration source: https://github.com/vllm-project/vllm/blob/main/vllm/config/cache.py
- vLLM releases: https://github.com/vllm-project/vllm/releases
- SGLang repository: https://github.com/sgl-project/sglang
- SGLang releases: https://github.com/sgl-project/sglang/releases
- SGLang, OpenAI-compatible APIs index (GitHub): https://github.com/sgl-project/sglang/blob/main/docs/docs/basic_usage/openai_api.mdx
- SGLang, Embeddings docs (GitHub): https://github.com/sgl-project/sglang/blob/main/docs/docs/basic_usage/openai_api_embeddings.mdx
- SGLang, Tool parser docs (GitHub): https://github.com/sgl-project/sglang/blob/main/docs/docs/advanced_features/tool_parser.mdx
- SGLang, Structured outputs docs (GitHub): https://github.com/sgl-project/sglang/blob/main/docs/docs/advanced_features/structured_outputs.mdx
- SGLang, Server arguments (GitHub): https://github.com/sgl-project/sglang/blob/main/docs/docs/advanced_features/server_arguments.mdx
- SGLang, GPT-OSS cookbook (GitHub): https://github.com/sgl-project/sglang/blob/main/docs/cookbook/autoregressive/OpenAI/GPT-OSS.mdx
- LMSYS, Fast and Expressive LLM Inference with RadixAttention and SGLang: https://lmsys.org/blog/2024-01-17-sglang/
- Zheng et al., SGLang: Efficient Execution of Structured Language Model Programs: https://arxiv.org/abs/2312.07104
- Hugging Face, text-generation-inference repository: https://github.com/huggingface/text-generation-inference
- Ollama, OpenAI compatibility: https://docs.ollama.com/api/openai-compatibility
- Ollama, FAQ: https://docs.ollama.com/faq
- Ollama releases: https://github.com/ollama/ollama/releases
- llama.cpp, server README: https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md
- LiteLLM repository: https://github.com/BerriAI/litellm
- Hugging Face, openai/gpt-oss-120b: https://huggingface.co/openai/gpt-oss-120b
- Hugging Face, Qwen/Qwen3-8B: https://huggingface.co/Qwen/Qwen3-8B
- Hugging Face, Mistral-Small-3.2-24B-Instruct-2506: https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506
- Hugging Face, deepseek-ai/DeepSeek-V3: https://huggingface.co/deepseek-ai/DeepSeek-V3
- Hugging Face, Llama 3.1 8B Instruct licence: https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct
- OpenAI, API pricing: https://developers.openai.com/api/docs/pricing
- Together, OpenAI compatibility: https://docs.together.ai/docs/inference/openai-compatibility.md
- Together, Pricing: https://www.together.ai/pricing
- Fireworks, OpenAI compatibility: https://docs.fireworks.ai/tools-sdks/openai-compatibility.md
- Fireworks, Pricing: https://fireworks.ai/pricing
- Parsec, Inference: https://parseclab.ai/inference/
- Parsec vs your own GPUs: https://parseclab.ai/compare/own-gpus/
- Parsec vs routers: https://parseclab.ai/compare/routers/