[GH-ISSUE #6422] ollama golang client hides API errors #50549

Open
opened 2026-04-28 16:20:55 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @dcarrier on GitHub (Aug 19, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6422

What is the issue?

While testing ollama in combination with k8sgpt I ran into an issue with ollama queries responding with:

invalid character 'p' after top-level value

After some hunting I found that the documentation for k8sgpt incorrectly adds a suffix to the ollama baseurl (http://localhost:11434/v1). Ollama API was responding with a plaintext HTTP body of 404 Not Found but I was unablwe to see this in the error message without debugging the ollama go client here:

https://github.com/ollama/ollama/blob/main/api/client.go#L166-L189

Ideally we are able to view both the API response and errorResponse (unmarshal error) to aid in quick debugging. I mocked up a rough diff illustrating what I am talking about:

https://github.com/ollama/ollama/compare/main...dcarrier:ollama:unmarshal-fix?expand=1#diff-aa9bfd1a638fbb706f8e8920297902937011160319d9679add5dca56e5ab8277

That code results in this error message:

404 Not Found: invalid character 'p' after top-level value

We can also manipulate Error() method of StatusError to clean up the formatting but I am hoping this is enough to get the idea across. Another option is to change the NoRoute handler to respond with a json payload with an Error field. However that feels like a riskier change than the aforementioned.

If this is acceptable I am happy to work on this and open a PR.

Thanks for considering!

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

v0.3.6

Originally created by @dcarrier on GitHub (Aug 19, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6422 ### What is the issue? While testing ollama in combination with k8sgpt I ran into an issue with ollama queries responding with: ``` invalid character 'p' after top-level value ``` After some hunting I found that the documentation for k8sgpt incorrectly adds a suffix to the ollama baseurl (`http://localhost:11434/v1`). Ollama API was responding with a plaintext HTTP body of `404 Not Found` but I was unablwe to see this in the error message without debugging the ollama go client here: https://github.com/ollama/ollama/blob/main/api/client.go#L166-L189 Ideally we are able to view both the API response and errorResponse (unmarshal error) to aid in quick debugging. I mocked up a rough diff illustrating what I am talking about: https://github.com/ollama/ollama/compare/main...dcarrier:ollama:unmarshal-fix?expand=1#diff-aa9bfd1a638fbb706f8e8920297902937011160319d9679add5dca56e5ab8277 That code results in this error message: ``` 404 Not Found: invalid character 'p' after top-level value ``` We can also manipulate Error() method of StatusError to clean up the formatting but I am hoping this is enough to get the idea across. Another option is to change the NoRoute handler to respond with a json payload with an Error field. However that feels like a riskier change than the aforementioned. If this is acceptable I am happy to work on this and open a PR. Thanks for considering! ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version v0.3.6
GiteaMirror added the bugapi labels 2026-04-28 16:21:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#50549