Error: invalid character '<' looking for beginning of value from
ollama list or ollama ps appeared in this test when
OLLAMA_HOST pointed at a web server that is not Ollama, and the client got an
HTML page. Point
OLLAMA_HOST back at the Ollama server and the same command works.
To see what answers on that address, ask it for /api/version with curl. Ollama
answered {"version":"0.40.8"}; the impostor in this test answered an HTML page.
The error
PS> $env:OLLAMA_HOST = "127.0.0.1:15962"
PS> ollama list
Error: invalid character '<' looking for beginning of value
exit=1
PS> ollama ps
Error: invalid character '<' looking for beginning of value
exit=1
The server on port 15962 was a small Python web server that answered
200 OK with an HTML page for /api/tags, /api/ps and
/api/version. Against a second web server that answered
404 HTML instead, the client printed the page itself after
Error::
PS> ollama list
Error: <!DOCTYPE HTML>
<html lang="en">
...
<p>Error code: 404</p>
<p>Message: File not found.</p>
...
ollama --version did not show either message; against both web servers it
printed Warning: could not connect to a running Ollama instance followed by
the client version.
Why it happens
OLLAMA_HOST tells the client which address to send its requests to. In the
test it named a port where another HTTP server listened. That server answered the
request, so there was no connection error; with a 200 answer the message named
<, the first character of that HTML page, and with a 404
answer the client printed the HTML body. For ollama run and
ollama pull, which send POST requests, the Python server answered
501 Unsupported method ('POST') and the client printed that.
The fix
Check what each address answers:
PS> curl.exe -s -i http://127.0.0.1:15962/api/version
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.13.7
...
Content-type: application/octet-stream
...
<!doctype html><html><body><h1>Intranet portal</h1></body></html>
PS> curl.exe -s http://127.0.0.1:15960/api/version
{"version":"0.40.8"}
Then point the client at the address that answered JSON:
PS> $env:OLLAMA_HOST = "127.0.0.1:15960"
PS> ollama list
NAME ID SIZE MODIFIED
exit=0
The list is empty because the test server had no models. The fix is the address, not the
client: whatever set OLLAMA_HOST to the wrong port, correct the value there.
How it was reproduced
Windows client ollama version is 0.40.14 in Windows PowerShell 5.1. The real
server was docker run -d --name fix9-olc-srv -p 127.0.0.1:15960:11434 ollama/ollama
(server 0.40.8). The impostors were python -m http.server 15961 --bind 127.0.0.1
and python -m http.server 15962 --bind 127.0.0.1 (Python 3.13.7), the second
serving files named api/tags, api/ps and
api/version that hold a one-line HTML page. OLLAMA_HOST was set
in the script's own process only. The container and both servers were the test's own and
were removed or stopped by process id afterwards.
Frequently asked
- Why does ollama list say invalid character '<' looking for beginning of value?
- The address in OLLAMA_HOST answered with an HTML page instead of Ollama's JSON. Check it with curl.exe -s http://<host:port>/api/version; Ollama answers with a version in JSON.
- How do I check if OLLAMA_HOST points at a real Ollama server?
- Request /api/version on that address. In the test the Ollama server answered {"version":"0.40.8"} and the impostor answered an HTML page.
- Why does ollama --version not show the invalid character error?
- In the test it printed Warning: could not connect to a running Ollama instance and the client version instead, against both HTML servers. Use ollama list or curl on /api/version to see what the address answers.
More decoded errors in the Fixes category. The same
words appear for a different cause when JSON typed into curl.exe is mangled by
the Windows shell, see
the
curl quoting post; for what OLLAMA_HOST controls, see
Ollama ports and OLLAMA_HOST.