ollama - 💡(How to fix) Fix ResponseError: unauthorized (status code: 401)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

ResponseError Traceback (most recent call last) Cell In[16], line 26 22 else {} 23 ), 24 ) 25 ---> 26 ollama_client.create( 27 model = LLM_MODEL_NEW, 28 from_ = LLM_MODEL_BASE, 29 system = "You are an academic reviewer who is screening some mobile applications to find if they should be included in a systematic review study or not.",

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/client.py:589, in Client.create(self, model, quantize, from, files, adapters, template, license, system, parameters, messages, stream) 569 def create( 570 self, 571 model: str, (...) 582 stream: bool = False, 583 ) -> Union[ProgressResponse, Iterator[ProgressResponse]]: 584 """ 585 Raises ResponseError if the request could not be fulfilled. 586 587 Returns ProgressResponse if stream is False, otherwise returns a ProgressResponse generator. 588 """ --> 589 return self.request( 590 ProgressResponse, 591 'POST', 592 '/api/create', 593 json=CreateRequest( 594 model=model, 595 stream=stream, 596 quantize=quantize, 597 from=from_, 598 files=files, 599 adapters=adapters, 600 license=license, 601 template=template, 602 system=system, 603 parameters=parameters, 604 messages=messages, 605 ).model_dump(exclude_none=True), 606 stream=stream, 607 )

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:199, in Client._request(self, cls, stream, *args, **kwargs) 195 yield cls(**part) 197 return inner() --> 199 return cls(**self._request_raw(*args, **kwargs).json())

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:143, in Client._request_raw(self, *args, **kwargs) 141 return r 142 except httpx.HTTPStatusError as e: --> 143 raise ResponseError(e.response.text, e.response.status_code) from None 144 except httpx.ConnectError: 145 raise ConnectionError(CONNECTION_ERROR_MESSAGE) from None

ResponseError: unauthorized (status code: 401)

Code Example

ResponseError                             Traceback (most recent call last)
Cell In[16], line 26
     22         else {}
     23     ),
     24 )
     25 
---> 26 ollama_client.create(
     27     model = LLM_MODEL_NEW,
     28     from_ = LLM_MODEL_BASE,
     29     system = "You are an academic reviewer who is screening some mobile applications to find if they should be included in a systematic review study or not.",

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:589, in Client.create(self, model, quantize, from_, files, adapters, template, license, system, parameters, messages, stream)
    569 def create(
    570   self,
    571   model: str,
   (...)    582   stream: bool = False,
    583 ) -> Union[ProgressResponse, Iterator[ProgressResponse]]:
    584   """
    585   Raises `ResponseError` if the request could not be fulfilled.
    586 
    587   Returns `ProgressResponse` if `stream` is `False`, otherwise returns a `ProgressResponse` generator.
    588   """
--> 589   return self._request(
    590     ProgressResponse,
    591     'POST',
    592     '/api/create',
    593     json=CreateRequest(
    594       model=model,
    595       stream=stream,
    596       quantize=quantize,
    597       from_=from_,
    598       files=files,
    599       adapters=adapters,
    600       license=license,
    601       template=template,
    602       system=system,
    603       parameters=parameters,
    604       messages=messages,
    605     ).model_dump(exclude_none=True),
    606     stream=stream,
    607   )

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:199, in Client._request(self, cls, stream, *args, **kwargs)
    195         yield cls(**part)
    197   return inner()
--> 199 return cls(**self._request_raw(*args, **kwargs).json())

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:143, in Client._request_raw(self, *args, **kwargs)
    141   return r
    142 except httpx.HTTPStatusError as e:
--> 143   raise ResponseError(e.response.text, e.response.status_code) from None
    144 except httpx.ConnectError:
    145   raise ConnectionError(CONNECTION_ERROR_MESSAGE) from None

ResponseError: unauthorized (status code: 401)
RAW_BUFFERClick to expand / collapse

What is the issue?

Similar to #15074, I get the 401 error when I want to create a model based on a cloud model using the ollama-python API's ollama.Client(...).create(...) function. It used to work before.

I tried a sign-out + sign-in using the Ollama's CLI command ollama signin, but no success.

Relevant log output

ResponseError                             Traceback (most recent call last)
Cell In[16], line 26
     22         else {}
     23     ),
     24 )
     25 
---> 26 ollama_client.create(
     27     model = LLM_MODEL_NEW,
     28     from_ = LLM_MODEL_BASE,
     29     system = "You are an academic reviewer who is screening some mobile applications to find if they should be included in a systematic review study or not.",

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:589, in Client.create(self, model, quantize, from_, files, adapters, template, license, system, parameters, messages, stream)
    569 def create(
    570   self,
    571   model: str,
   (...)    582   stream: bool = False,
    583 ) -> Union[ProgressResponse, Iterator[ProgressResponse]]:
    584   """
    585   Raises `ResponseError` if the request could not be fulfilled.
    586 
    587   Returns `ProgressResponse` if `stream` is `False`, otherwise returns a `ProgressResponse` generator.
    588   """
--> 589   return self._request(
    590     ProgressResponse,
    591     'POST',
    592     '/api/create',
    593     json=CreateRequest(
    594       model=model,
    595       stream=stream,
    596       quantize=quantize,
    597       from_=from_,
    598       files=files,
    599       adapters=adapters,
    600       license=license,
    601       template=template,
    602       system=system,
    603       parameters=parameters,
    604       messages=messages,
    605     ).model_dump(exclude_none=True),
    606     stream=stream,
    607   )

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:199, in Client._request(self, cls, stream, *args, **kwargs)
    195         yield cls(**part)
    197   return inner()
--> 199 return cls(**self._request_raw(*args, **kwargs).json())

File /opt/miniforge3/envs/pydsci/lib/python3.13/site-packages/ollama/_client.py:143, in Client._request_raw(self, *args, **kwargs)
    141   return r
    142 except httpx.HTTPStatusError as e:
--> 143   raise ResponseError(e.response.text, e.response.status_code) from None
    144 except httpx.ConnectError:
    145   raise ConnectionError(CONNECTION_ERROR_MESSAGE) from None

ResponseError: unauthorized (status code: 401)

OS

Linux

GPU

No response

CPU

Intel

Ollama version

0.23.2

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - 💡(How to fix) Fix ResponseError: unauthorized (status code: 401)