Editing
Troubleshooting of Ollama API
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Troubleshooting of [https://ollama.com/ Ollama] [https://github.com/ollama/ollama/blob/main/docs/api.md API] {{Raise hand | text = If you have any questions about the Ollama API, you can post them on the [https://github.com/ollama/ollama/issues Ollama GitHub Repository].}} == How to fix "json: cannot unmarshal object ..." == '''Error message:''' <pre> HTTP Error 400: {"error": "json: cannot unmarshal object into Go struct field ChatRequest.messages of type []api.Message"} </pre> '''Applicable Model:''' * {{kbd | key=gpt-oss:120b}} '''Solution''' Root Cause: Incorrect `messages` format. The API expects an array format, but a single object was being sent. Incorrect Format in PHP: ❌ This is an object <pre> 'messages' => ['role' => 'user', 'content' => $message] </pre> Correct Format in PHP: ✅ This is an array containing an object <pre> 'messages' => [['role' => 'user', 'content' => $message]] </pre> '''Explanation:''' The `messages` parameter must be an array of message objects, not a single message object. Each message object should contain `role` and `content` properties. The extra square brackets `[]` wrap the message object into an array, which matches the API's expected format. This fix resolves the `"cannot unmarshal object into Go struct field ChatRequest.messages"` error. == Related links == * Forum: [https://www.reddit.com/r/ollama/ ollama] [[Category: Tools]] [[Category: Ollama]] [[Category: Revised with LLMs]] [[Category: Generative AI]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Kbd
(
edit
)
Template:Raise hand
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information