Troubleshooting of Ollama API: Difference between revisions

Jump to navigation Jump to search
How to Fix "Unauthorized" Error
No edit summary
(How to Fix "Unauthorized" Error)
Line 3: Line 3:


{{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].}}
{{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 "Unauthorized" Error ==
'''Error message:'''
<pre>
HTTP Error 401
Response: {"error":"Unauthorized"}
</pre>
'''Solution'''
Verify that your API key is correct by testing it with the following curl command:
<pre>
curl -s -o /dev/null -w "%{http_code}\n" -X POST https://ollama.com/api/chat -H "Authorization: Bearer REPLACE_WITH_YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model":"gpt-oss:120b","messages":[{"role":"user","content":"hi"}],"stream":false}'
</pre>
Check the returned status code:
* '''200''' — the API key is valid
* '''401''' — the API key is invalid or incorrect


== How to fix "json: cannot unmarshal object ..." ==
== How to fix "json: cannot unmarshal object ..." ==

Navigation menu