{"error":"model 'nope' not found"} with HTTP 404, {"error":"model is required"} with 400, and json: cannot unmarshal string into Go struct field .ChatRequest.messages are Ollama's REST API rejecting the request itself, before any model runs. Send a model name exactly as ollama list prints it, and for /api/chat a messages array of objects with role and content.

The bodies that worked are in the fix below. On Windows PowerShell 5.1, keep them in a file and send it with -d "@file.json"; inline JSON loses its quotes on the way to curl.exe.

The error

PS> curl.exe -s -i http://127.0.0.1:15101/api/generate -d "@generate-nope.json"
HTTP/1.1 404 Not Found
{"error":"model 'nope' not found"}
PS> curl.exe -s -i http://127.0.0.1:15101/api/chat -d "@chat-no-model.json"
HTTP/1.1 400 Bad Request
{"error":"model is required"}
PS> curl.exe -s -i http://127.0.0.1:15101/api/chat -d "@chat-string-messages.json"
HTTP/1.1 400 Bad Request
{"error":"json: cannot unmarshal string into Go struct field .ChatRequest.messages of type []api.Message"}

Why it happens

The server decodes the body into a Go struct first, so a field of the wrong type is reported in Go's words: the path .ChatRequest.messages and the type it wanted, []api.Message, a list of messages. Then it checks the model name and looks for it locally; a name it does not have gets 404 and nothing is downloaded. Each body the test sent, and the answer:

  • "model": "nope" on either endpoint: 404, model 'nope' not found.
  • No model on /api/chat: 400, model is required. The same omission on /api/generate answered 404, model '' not found.
  • messages as a string, as a single object, or with content as an array: 400, cannot unmarshal string, object or array, naming the field.
  • A body missing its closing brace: 400, unexpected EOF.
  • Inline JSON in Windows PowerShell 5.1: 400, invalid character 'm' looking for beginning of object key string, because the shell stripped the double quotes and the server saw {model:.
  • A prompt field sent to /api/chat: no error at all, 200 with empty content and "done_reason":"load". That one only loads the model.
  • A GET on /api/chat: 405, 405 method not allowed.

The fix

chat-ok.json:
{"model": "qwen2.5:0.5b", "messages": [{"role": "user", "content": "Reply with the single word ready."}], "stream": false}
generate-ok.json:
{"model": "qwen2.5:0.5b", "prompt": "Reply with the single word ready.", "stream": false}

PS> curl.exe -s -i http://127.0.0.1:15101/api/chat -d "@chat-ok.json"
HTTP/1.1 200 OK
{"model":"qwen2.5:0.5b","created_at":"2026-10-30T02:57:55.813869Z","message":{"role":"assistant","content":"ready"},"done":true,"done_reason":"stop",...}
PS> curl.exe -s -i http://127.0.0.1:15101/api/generate -d "@generate-ok.json"
HTTP/1.1 200 OK
{"model":"qwen2.5:0.5b","created_at":"2026-10-30T02:57:55.86646Z","response":"ready","done":true,"done_reason":"stop",...}
PS> Invoke-RestMethod http://127.0.0.1:15101/api/chat -Method Post -Body (Get-Content .\chat-ok.json -Raw) | Select-Object -ExpandProperty message
role    : assistant
content : ready

/api/chat takes a conversation, /api/generate a single prompt; mixing the two fields up is the quiet mistake. "stream": false returns one JSON object instead of a line per token. The field list for each endpoint is in Ollama's API reference. From PowerShell, Invoke-RestMethod with the body read from the file avoids the quoting problem entirely.

How it was reproduced

On Windows 11 with Ollama 0.40.11 and the curl.exe 8.21.0 that ships in C:\Windows\system32, in Windows PowerShell 5.1, against a separate ollama serve on 127.0.0.1:15101 holding only qwen2.5:0.5b; that port is the test's own, and on a default install the address is localhost:11434. Eleven bodies were saved as files, one per case, and each response is shown with its status line; the other headers are cut.

Frequently asked

What does 'model is required' mean in the Ollama API?
The request body has no model field, or it did not reach the server as valid JSON with one. In the test /api/chat answered 400 model is required, while /api/generate without a model answered 404 model '' not found.
Why does Ollama say 'cannot unmarshal string into Go struct field .ChatRequest.messages'?
The messages field must be an array of objects, each with a role and a content string. A plain string, a single object, or content sent as an array all fail with a cannot unmarshal error that names the field.
Why does curl to Ollama fail in PowerShell with 'invalid character' errors?
Windows PowerShell 5.1 removes the double quotes inside an argument passed to curl.exe, so Ollama receives broken JSON. Save the body in a file and send it with -d @file.json, or use Invoke-RestMethod with -Body.

More decoded errors in the Fixes category. The same 404 seen through OllamaSharp in C# arrives as an HttpRequestException with the server's message hidden: Ollama from .NET: 404 Not Found.