{"error":"invalid character '\\'' looking for beginning of value"} — Ollama
received a request body that is not JSON, because the Windows shell changed your quotes
before curl.exe sent them. The command copied from a Linux tutorial works there
and fails in cmd.exe and in Windows PowerShell 5.1. Put the JSON in a file and
send it with -d @file.json, so the shell never touches the quotes.
Each shell breaks the body differently, so the message differs: cmd.exe sends
the single quotes along (invalid character '\''), Windows PowerShell 5.1 drops
the double quotes (invalid character 'm' looking for beginning of object key
string), and a backslash-escaped body in PowerShell ended with unexpected EOF.
The error
C:\> curl.exe -s -i http://127.0.0.1:15190/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"Say hi","stream":false}'
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Date: Fri, 06 Nov 2026 07:28:01 GMT
Content-Length: 66
{"error":"invalid character '\\'' looking for beginning of value"}
The same command in Windows PowerShell 5.1:
PS> curl.exe -s -i http://127.0.0.1:15190/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"Say hi","stream":false}'
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Date: Fri, 06 Nov 2026 07:28:03 GMT
Content-Length: 76
{"error":"invalid character 'm' looking for beginning of object key string"}
Why it happens
Single quotes are a Unix shell feature. cmd.exe does not treat them as quotes
at all, so the first character Ollama sees is a literal ', and a JSON body
cannot start with that. The doubled backslash in the reply is only JSON escaping of
\' inside the error string.
Windows PowerShell 5.1 does understand single quotes, but when it passes the argument to a
native program such as curl.exe it drops the double quotes inside it. The
error shows the result: the parser met the m of model where a
quoted key should start. Escaping the quotes with backslashes, the
usual next try, failed in the test too: the reply was
{"error":"unexpected EOF"}.
The fix
PS> Get-Content hi.json
{"model":"qwen2.5:0.5b","prompt":"Say hi in two words.","stream":false}
PS> curl.exe -s http://127.0.0.1:15190/api/generate -d '@hi.json'
{"model":"qwen2.5:0.5b","created_at":"2026-11-06T07:28:03.982685Z","response":"Hi, how are you?","done":true,"done_reason":"stop", ...
A body file removes the shell from the problem: curl reads the bytes itself. In PowerShell
quote '@hi.json', because a bare @ means something else there.
Save the file as ASCII, as the test did with Out-File -Encoding ascii.
Out-File -Encoding utf8 in Windows PowerShell 5.1 writes a byte order mark
(the file started with bytes 239,187,191), and Ollama refused that file:
PS> curl.exe -s http://127.0.0.1:15190/api/generate -d '@hi-utf8.json'
{"error":"invalid character 'ï' looking for beginning of value"}
In cmd.exe the inline form works if the body is in double quotes and every
inner quote is escaped:
C:\> curl.exe -s http://127.0.0.1:15190/api/generate -d "{\"model\":\"qwen2.5:0.5b\",\"prompt\":\"Say hi in two words.\",\"stream\":false}"
{"model":"qwen2.5:0.5b","created_at":"2026-11-06T07:28:03.5639518Z","response":"Hello.","done":true,"done_reason":"stop", ...
The long context array and the timings at the end of both successful replies
are cut here, as marked.
How it was reproduced
Windows 11 with curl.exe 8.21.0, run from a cmd.exe batch file
and from Windows PowerShell 5.1.26100, against a separate test server started with
ollama serve (Ollama 0.40.14) on 127.0.0.1:15190 with
qwen2.5:0.5b. The same JSON body was sent single-quoted in both shells,
escaped in both, and from hi.json in PowerShell.
Frequently asked
- Why does curl to Ollama say invalid character looking for beginning of value on Windows?
- cmd.exe does not treat single quotes as quotes, so the body starts with a literal quote character and is not JSON. Use double quotes with escaped inner quotes in cmd, or send the body from a file.
- How do I send JSON with curl.exe in PowerShell?
- Save the JSON to an ASCII file and pass it as -d '@file.json'. Windows PowerShell 5.1 drops the double quotes inside an inline argument to curl.exe, backslash-escaped quotes gave unexpected EOF in the test, and a UTF-8 file with a byte order mark was refused too.
- What does invalid character 'm' looking for beginning of object key string mean?
- The JSON reached Ollama without its double quotes, so the parser found the letter m of model where a quoted key should start. It is the Windows PowerShell 5.1 quote stripping; use a body file.
More decoded errors in the Fixes category. The other errors the API returns for a bad body are in 'model not found', 'model is required' and 'cannot unmarshal'.