LiteLLM model routing failing? Check aliases and upstreams
gist Give apps a stable model alias, check the proxy with a fixed mock reply, then point that alias at Ollama.
You stopped about in. Jump back
contents
If LiteLLM cannot route an app’s model request, check the model alias and upstream address with a fixed mock reply before switching the alias to Ollama.
LiteLLM is the model proxy in my Docker stack.
An app can request demo-chat while the proxy handles the provider and upstream address. LiteLLM documents this mapping through model_name and litellm_params. LiteLLM configuration documentation.
Step 1: Map a model name
Start with LiteLLM installed and a reachable upstream. For the first check, use a controlled mock OpenAI-compatible server that returns a fixed reply. It needs a /v1/chat/completions endpoint and a model identifier matching mock-chat.
Save the mapping as proxy.yml:
model_list:
- model_name: demo-chat
litellm_params:
model: openai/mock-chat
api_base: http://upstream.example:8080/v1
api_key: "os.environ/DEMO_API_KEY"
demo-chat is the client alias. mock-chat is the mock’s model identifier. The openai/ prefix selects an OpenAI-compatible upstream. api_base points to that server. The key line reads a value from the environment; the capture masks the unused mock credential. LiteLLM configuration documentation.
For this controlled mock, set DEMO_API_KEY to an arbitrary test value in the environment that starts LiteLLM. Use the upstream provider’s required credential when replacing the mock with a real service.
Start the proxy with the configuration:
litellm --config proxy.yml --port 4000
Check that startup loads the intended configuration and lists the configured model. Keep model_list at the YAML root. LiteLLM configuration documentation.

Step 2: Send a request through the proxy
Set a private master key before allowing other applications to access the proxy. For that authenticated setup, use a bearer header in the request. LiteLLM authentication documentation. With the proxy reachable on the same machine, send a small chat request:
curl --fail-with-body \
http://127.0.0.1:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${LITELLM_MASTER_KEY}" \
--data '{
"model": "demo-chat",
"messages": [
{"role": "user", "content": "Reply with a short greeting."}
],
"stream": false
}'
The request uses the proxy alias. For a successful mock check, inspect choices[0].message.content and compare it with the mock’s fixed reply. LiteLLM exposes an OpenAI-compatible chat endpoint for clients. LiteLLM quick start.
A matching reply checks the request route and response format. Test Ollama generation separately after changing the upstream.
Check that an unauthenticated request is rejected when the proxy requires a key. Keep credentials out of saved terminal output.

Step 3: Point the alias at Ollama
Before switching, confirm that Ollama has the model you want:
ollama list
Use the exact installed model tag. Replace gpt-oss:20b if your installed tag differs. Ollama’s compatibility documentation uses this tag in chat examples. Ollama OpenAI compatibility.
Replace the mock entry with:
model_list:
- model_name: "demo-chat"
litellm_params:
model: "ollama_chat/gpt-oss:20b"
api_base: "os.environ/OLLAMA_API_BASE"
general_settings:
master_key: "os.environ/LITELLM_MASTER_KEY"
Set OLLAMA_API_BASE to the Ollama server address reachable from LiteLLM, such as http://ollama.example:11434. The ollama_chat/ prefix selects LiteLLM’s Ollama chat provider. LiteLLM Ollama documentation.
With separate network namespaces on a Docker bridge, 127.0.0.1 refers to the current container. Put both services on a suitable shared network and use an address that resolves from the proxy container. Check reachability from there. Docker networking documentation.
Restart LiteLLM with the changed configuration. Repeat the chat request and check for an actual generated answer.
docker exec ollama-example ollama list
NAME ID SIZE MODIFIED
Step 4: Set the application’s connection
For an app that supports a custom OpenAI-compatible Chat Completions endpoint, configure:
| Setting | Value |
|---|---|
| API base URL | http://127.0.0.1:4000/v1 when the app and proxy share a machine |
| Model | demo-chat |
| API key | The proxy credential |
For an app on another machine or in another container, use a proxy address reachable from that app. Check whether its URL field expects a base URL or the full chat endpoint. LiteLLM quick start.
Test plain chat first. Then test each feature the app needs, such as streaming, tools or structured output. Tool support depends on the selected model and provider configuration. LiteLLM Ollama documentation.
Compare the alternatives
| Option | When it fits | What to check |
|---|---|---|
| LiteLLM | Apps need shared aliases, proxy authentication or several backends. | Provider mappings, credentials and required API features. |
| Direct Ollama API | One Ollama server already meets the app’s needs. | Ollama supports parts of the OpenAI API; its example API key is ignored. |
| llama.cpp server | You want to serve models through llama.cpp directly. | Model files, chat templates and endpoint support. |
| vLLM | You want an inference server with OpenAI-compatible endpoints. | Model support, hardware requirements and chat templates. |
| Other compatible proxies | A different gateway better matches your access or routing needs. | Verify each required feature in its documentation before switching. |
Direct Ollama can remove a proxy from a simple setup. llama.cpp and vLLM serve inference themselves. LiteLLM connects clients to configured providers. See the Ollama compatibility documentation, llama.cpp server README and vLLM server documentation.
Common questions
Why is LiteLLM returning an empty model list?
Check that the running process loaded the intended configuration. Confirm that model_list is at the YAML root and includes the expected alias. In Docker, check the mounted file and startup command. LiteLLM configuration documentation.
Why can LiteLLM not connect to Ollama in Docker?
Check the upstream address from the LiteLLM container. A working request from the host does not prove the container can reach the same address. Confirm that the containers share a network and Ollama listens on a reachable interface. Docker networking documentation.
Do I need LiteLLM to use Ollama with an OpenAI client?
No. Ollama has its own OpenAI-compatible endpoints. Use LiteLLM when shared aliases, proxy authentication or multiple providers solve a need in your setup. Ollama OpenAI compatibility.
Can LiteLLM load balance multiple model servers?
Yes. LiteLLM documents multiple deployments under one model name and selectable routing strategies. A single entry points to one deployment. Check each backend before adding balancing. LiteLLM load balancing documentation.
How should I test tool calling through LiteLLM?
Test tools with the chosen model and application. A plain text reply checks a different request path from a tool call. LiteLLM Ollama documentation.
Related: local AI guides · guide index.
../local-ai/ every Local AI guide