EN ▾
Get API key

Ollama API Not Working: Diagnosing Connection Problems

Connection refused, model not found or an app that cannot reach the server: a step-by-step way to find the cause, and a hosted fallback.

Updated

A server with a disconnected cable being traced, next to a connected cloud
Chat dashboard connected by a glowing cable to an API server cube, with message bubbles flowing between them

Key points

  1. Test with curl on the same machine first: localhost:11434 should say Ollama is running.
  2. Model names must match ollama list exactly.
  3. Containers cannot use localhost to reach a host-side server.
  4. A hosted OpenAI-compatible endpoint avoids ports, drivers and memory limits.

Check that the server is running

When your ollama api not working problem shows up as "connection refused", the server is usually not running or not where you think it is. Start with a plain request from the same machine.

curl http://localhost:11434
# expected: Ollama is running

curl http://localhost:11434/api/tags
# expected: JSON list of models you have pulled

If the first call fails, start the server. On Linux with the install script, run systemctl status ollama and read the log with journalctl -u ollama -e. On macOS and Windows the desktop app runs the server, so check that the app is open. If you launch it by hand, use ollama serve in a terminal and leave it running.

If the server says the address is already in use, another copy of Ollama, or another program, holds port 11434. Stop it, or set a different port with the OLLAMA_HOST variable, for example OLLAMA_HOST=127.0.0.1:11500.

Error: model not found or empty reply

The next most common cause is a model name that does not match what is installed. Run ollama list and copy the name exactly, including the tag after the colon. A request for llama3 when you pulled llama3:8b can return a 404 "model not found" error.

  • Pull first: ollama pull <name>. A request does not always download the model for you.
  • Use the same name in your code as in ollama list.
  • If a pull stops half-way, repeat the command. It resumes.

An empty or very short answer often points to a context problem: the prompt does not fit in the context size the model was loaded with, so the start is cut off. Raise num_ctx in the request options or the Modelfile, and check that you have the memory for it.

The OpenAI-compatible route and client settings

Ollama also exposes an OpenAI-style API under /v1. Clients that use it need three settings: the base URL, any non-empty API key (Ollama ignores the value) and the exact model name.

from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
r = client.chat.completions.create(
    model="llama3:8b",          # must match `ollama list`
    messages=[{"role": "user", "content": "ping"}],
)
print(r.choices[0].message.content)

Common mistakes here: leaving out /v1 in the base URL, using https for a local server that only speaks plain HTTP, and sending the request to a host name that points at a different machine. If a front end says "failed to fetch", paste the same URL into curl on the same machine and see whether curl works. Also watch for proxies: a system-wide HTTP proxy setting can send requests to localhost through the proxy and fail. Add localhost to the NO_PROXY variable if that happens.

curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "llama3:8b", "messages": [{"role": "user", "content": "ping"}]}'

If that curl call works and your app still fails, the bug is in the app's settings, not in Ollama.

Docker, WSL and remote machines

Most "works in the terminal, fails in my app" reports come from a network boundary. Ollama listens on 127.0.0.1 by default, so only programs on the same host can reach it.

  • A web UI in Docker, Ollama on the host. Inside the container, localhost is the container itself. Use http://host.docker.internal:11434 on Docker Desktop, or add --add-host=host.docker.internal:host-gateway on Linux. Then set OLLAMA_HOST=0.0.0.0:11434 for the Ollama service so it accepts connections from the Docker network.
  • WSL and Windows. A server in WSL may not be reachable from Windows apps, and the other way round. Test with curl from both sides and adjust the host address.
  • Another computer on your network. Set OLLAMA_HOST=0.0.0.0, open port 11434 in the firewall and use the machine's LAN address. Do not expose that port to the internet, because there is no authentication.
  • Browser apps. A page served from another origin may be blocked by CORS. Add the origin to OLLAMA_ORIGINS and restart the service.

Slow, timing out or crashing

The first request after a pause loads the model into memory, which can take many seconds for a large one. A client with a short timeout reports an error although nothing is broken. Raise the timeout, and use OLLAMA_KEEP_ALIVE to keep a model loaded for longer.

If the process dies or the GPU is not used, the model is probably too big for your memory. Pick a smaller or more heavily quantized version. Watch memory use while a request runs; when the model spills out of GPU memory to system RAM, speed drops sharply. Run the server in a terminal with ollama serve and read the output while you send a request, since the log shows whether the request even arrives. Check the server log for lines about out of memory errors, driver problems or "offloading" counts.

Several users at once also stall a single local server. Requests are handled in a queue, and each running model takes memory, so a small team can feel a slowdown that you never see alone. For more help with local problems, our local LLM troubleshooting page goes further.

When a hosted endpoint removes the problem

Everything above is about running your own server. If your goal is an app that talks to a chat model, you can skip the server and call a hosted endpoint. This site's API runs one open-weight model from an independent provider, tuned to answer without content refusals for lawful adult use. It is text only, and it is not the official API of any model vendor. Sexual content involving minors is never allowed.

The code looks the same as the Ollama example, with a different base URL, a real key and one fixed model name:

from openai import OpenAI

client = OpenAI(base_url="https://api.uncensoredllms.top/v1", api_key="YOUR_KEY")
r = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "ping"}],
)
print(r.choices[0].message.content)

No ports, drivers, Docker networks or memory limits are involved, and a 100,000 token context window is available without any setup. The trade-off is that you pay per token and your prompts leave your machine, though they are not used for training. Local still wins when you must stay offline or want to run many different models.

Cost and trial

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit with no subscription. A chat turn of 2,000 input and 500 output tokens costs $0.00055, so $0.55 for 1,000 turns. Failed or refused requests are not charged.

Sign up with Google or email and claim $0.50 of trial credit with one click on the API key page, with no card and valid for 7 days. After that, top-ups are any whole amount from $20 to $500 by crypto (USDT on TRC20, USDC on Base). See the pricing page and the docs.

Quick checklist

  1. curl http://localhost:11434 prints "Ollama is running".
  2. ollama list shows the model, and your code uses the exact name.
  3. The base URL ends in /v1 for OpenAI-style clients.
  4. Containers use host.docker.internal, not localhost.
  5. The server listens on an address the client can reach, and the firewall allows it.
  6. Timeouts allow for the first model load.
  7. The model fits in memory with the context size you set.

Go through the list in order, and change one thing at a time so you know which change fixed it. Write down what you tried; when you ask for help in a forum or an issue tracker, the exact error text, your operating system, the Ollama version and the output of the two curl commands from the top of this article answer most of the questions people would otherwise ask you first. Most cases end at item one, two or five.

Questions and answers

What port does Ollama use?

11434 by default. Change it with the OLLAMA_HOST variable if something else uses it.

Why does my app say connection refused?

The server is not running, it listens on a different address, or the app is in a container where localhost is not the host.

Do I need an API key for Ollama?

No. OpenAI-style clients need a non-empty value, but Ollama ignores it.

Can I use a hosted API with the same client code?

Yes. Change the base URL to https://api.uncensoredllms.top/v1, use your key and the model name uncensored.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key