Guide

How to give your own models an OpenAI-compatible API (vLLM and Ollama)

Serve open models with an OpenAI-compatible API using vLLM or Ollama, call them with the OpenAI SDK, and what to add for many users.

Both vLLM and Ollama can serve open models behind an OpenAI-compatible API, so any app that uses the OpenAI SDK can call your own models by changing the base URL. vLLM is built for throughput on GPU servers; Ollama is the quickest way to start on one machine. Once several people or servers are involved, put a gateway in front for keys, limits and failover.

Commands checked against the vLLM and Ollama docs on 2 December 2026.

Why the OpenAI format

The OpenAI API has become the common language for LLM apps. SDKs, agent frameworks and tools speak it. If your own models speak it too, you can switch an app between a vendor and your hardware without rewriting code: only the URL, key and model name change.

Option 1: vLLM

vLLM is an inference engine for GPU servers, designed to serve many requests at once.

Start the server:

vllm serve meta-llama/Llama-3.1-8B-Instruct --api-key your-secret-key

This starts an OpenAI-compatible server, on port 8000 by default, with endpoints including /v1/chat/completions, /v1/completions and /v1/embeddings for models that support them.

Call it with the OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    base_url="http://your-gpu-server:8000/v1",
    api_key="your-secret-key",
)

response = client.chat.completions.create(
    model="meta-llama/Llama-3.1-8B-Instruct",
    messages=[{"role": "user", "content": "Summarise our refund policy in two sentences."}],
)
print(response.choices[0].message.content)

Good to know:

  • --api-key sets one static key for the whole server. Everyone shares it.
  • Health endpoints (/health, /health_generate) don't require the key, which is what you want for load balancers.
  • /metrics exposes Prometheus metrics.

Option 2: Ollama

Ollama is the simplest way to run open models on a laptop or a single server.

Pull and run a model:

ollama pull llama3.1
ollama serve

Call it with the OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1/",
    api_key="ollama",  # required by the SDK, ignored by Ollama
)

response = client.chat.completions.create(
    model="llama3.1",
    messages=[{"role": "user", "content": "Summarise our refund policy in two sentences."}],
)
print(response.choices[0].message.content)

Ollama's OpenAI-compatible chat endpoint supports streaming, JSON mode, vision and tools. The local API has no authentication at all, so never expose port 11434 directly. See Ollama authentication.

vLLM or Ollama?

vLLMOllama
Best forProduction GPU servers, many concurrent usersLaptops, single servers, quick experiments
AuthenticationOne static key with --api-keyNone on the local API
Scaling to many serversWith a router or gateway in frontWith a gateway in front

A reasonable split: Ollama for development, vLLM for production.

What you still don't have

A single server with an OpenAI-compatible API is a good start. As soon as more than a few people use it, gaps appear:

  • One shared key. You can't tell who sent what, revoke one person, or give someone access to only some models.
  • No limits. One script can saturate the GPU for everyone.
  • No failover. If the server is down or busy, requests fail.
  • No cost view. If you also use paid vendors, you can't see spend across both.
  • Several servers, several URLs. Apps need to know which machine has which model.

That's the job of a gateway: one URL in front of all your servers and vendors. Read what is an LLM gateway for how it works. If you're specifically balancing load across many vLLM replicas, see vLLM router.

Putting a gateway in front

AI Gateway by LayerX is built for this setup. You register your vLLM and Ollama servers as providers, give each model a name your team recognises, and add vendor accounts like OpenAI, Groq, Together or OpenRouter as backup. Apps call one URL with the OpenAI SDK. Requests go to your GPUs first and move to vendors when your machines are busy or down. Each person gets their own key, daily and monthly token budgets and a list of allowed models, and prompts are never stored. You can change the model catalogue live and take a server out for maintenance without dropping requests.

Questions

What is an OpenAI-compatible API?

An API that accepts the same requests and returns the same responses as OpenAI's, so OpenAI SDKs and tools work with it by changing the base URL and key.

Does vLLM support the OpenAI API?

Yes. vllm serve starts an OpenAI-compatible server with chat completions, completions and embeddings endpoints, among others.

Does Ollama support the OpenAI API?

Yes, at http://localhost:11434/v1/. The SDK needs an API key value, but the local server ignores it.

How do I give each user their own API key for my models?

Neither vLLM nor Ollama does this alone. Put a gateway in front that issues a key per person and applies limits and budgets.

More posts

Keep reading.

See how AI Gateway fits your setup.

Tell us what you run today and how many people need access. We'll get back to you to learn more about your setup.

See how AI Gateway fits your setup.

What do you run today?