System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found). from an Ollama call in .NET almost always means the model name you passed is not pulled on that server. Use a name exactly as ollama list prints it, or pull the model first.

The exception hides the server's explanation. Ollama answered model 'llama3' not found, but the .NET message only says 404, so the first thing to check is the model name, not the URL.

The error

Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at OllamaSharp.OllamaApiClient.EnsureSuccessStatusCodeAsync(HttpResponseMessage response)

Why it happens

Ollama's chat endpoint returns HTTP 404 when the request names a model that is not on the server. The same request sent with curl shows the body the server wrote:

HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8

{"error":"model 'llama3' not found"}

OllamaSharp checks the status code and, for this case, lets HttpResponseMessage.EnsureSuccessStatusCode() throw, which produces the generic 404 text without the body. A 404 therefore looks like a wrong URL or route, when the route is fine and only the model is missing. A common way to get here is a tag mismatch: this machine had llama3.1:8b, and llama3 is a different name.

The fix

PS> ollama list
NAME                       ID              SIZE      MODIFIED
qwen2.5:3b                 357c53fb659c    1.9 GB    Less than a second ago
llama3.1:8b                46e0c10c039e    4.9 GB    3 weeks ago

PS> dotnet run --no-build -- qwen2.5:3b http://localhost:11434 chat
Blazor is a framework for building web applications using .NET that renders client-side using JavaScript and HTML.
IChatClient ollama = new OllamaApiClient(new Uri(baseUrl), model);
var reply = await ollama.GetResponseAsync("In one short sentence, what is Blazor?");
Console.WriteLine(reply.Text);

Nothing in the code changed: the model argument went from llama3 to qwen2.5:3b, a name copied from the NAME column of ollama list. If you do want the missing model, run ollama pull with its exact tag on the same server your app calls, then retry. When the app talks to a remote Ollama, run ollama list there, not on your own machine. Reading the model name from configuration keeps a later rename to a one-line settings change.

How it was reproduced

A console app from dotnet new console -n FixLab -f net10.0 on .NET SDK 10.0.401, with Microsoft.Extensions.AI 10.10.0 and OllamaSharp 5.5.0, called GetResponseAsync on OllamaApiClient with the model name llama3, which was not pulled, against Ollama 0.40.1 on Windows 11. The stack trace is cut after its second frame, the curl response is shown without its Date and Content-Length headers, and ollama list is shortened to two of its five rows.

Frequently asked

Why does OllamaSharp throw 404 Not Found?
In this test the 404 came from Ollama's chat endpoint because the requested model was not pulled. The server's body said model not found, but the .NET exception shows only the status code.
How do I see which models my Ollama server has?
Run ollama list on the machine where the server runs. Use a name exactly as it appears in the NAME column, including the tag after the colon.
Is llama3 the same as llama3.1:8b in Ollama?
No. They are different names. A request for llama3 fails with 404 when only llama3.1:8b is pulled.

More decoded errors in the Fixes category. The same missing-tag mistake on the command line gives pull model manifest: file does not exist.