Error 401 Client Error: Unauthorized for url

I’m surprised you came up with such a workaround…:sweat_smile:

It seems that the token area is being modified, and the operation has changed twice today alone. Well, it’s probably best to wait for it to be fixed.

i agree john
i thought i was going crazy, but over the last 48 hours or so token procedures appear to change
and yes, putting it into a secret worked for me for some models too, still.
and yes, previously omitting tokens granted access for me as well.
i cant confirm CAPPING tokens, not yet at least
i cant really keep track of what i can and cant confirm or when

likely tomorrow itll change again eh?
i need a nice tall glass of drink

1 Like

yes this works (but I don’t know why the below cannot work for me:
from huggingface_hub import notebook_login
notebook_login()

1 Like

thank you so much! it works for me

1 Like

I’m having a similar issue now and I’m downloading stabilityai/stable-diffusion-xl-base-1.0 encounter RuntimeError: Data processing error: CAS service error : Reqwest Error: HTTP status client error (401 Unauthorized), domain: https:cas-server.xethub.hf.co/reconstruction/4cb12f8b6ebb11f02b908c4c878871cae90cbe3bad06db19e97336df6b7f3a6e I don’t understand why public repositories need authorization as well, and even if I give the correct token, it will still get an error, and I download other public models that don’t happen at the same time , I wouldn’t go wrong downloading the model on other PCs either

1 Like

Hmm… How about pip install -U huggingface_hub[hf_xet] ?

I’m getting the same error and I have hf-xet 1.1.5. I’m behind a firewall but have no problems with requests to other URLs.

1 Like

Hi @XPW123 thanks for the report - are you behind any firewalls when you make this request? If so, could you make sure you have the following domains allowlisted:

cas-bridge.xethub.hf.co
transfer.xethub.hf.co
cas-server.xethub.hf.co

If not (or if that doesn’t help), could you open an issue on the xet-core repository and we can investigate there?

1 Like

Hi @alfredgabal :waving_hand:

Could you provide the full error you’re seeing?

Also, do you have the following URLs allowlisted:

cas-bridge.xethub.hf.co
transfer.xethub.hf.co
cas-server.xethub.hf.co
1 Like

Hi @jsulz , thanks for the reply. I do get a response when I curl those three URLs. Here’s the full error message (I replaced some “https” with “h***s” because the page doesn’t let me post more than two links):

Fetching 83 files: 0%| | 0/83 [00:00<?, ?it/s]{“timestamp”:“2025-07-01T17:37:59.153575Z”,“level”:“ERROR”,“fields”:{“message”:“error downloading range, error: ReqwestMiddlewareError(Middleware(error sending request\n\nCaused by:\n 0: client error (SendRequest)\n 1: connection error\n 2: peer closed connection without sending TLS close_notify: h***s://docs.rs/rustls/latest/rustls/manual/_03_howto/index.html#unexpected-eof))”,“caller”:“/home/runner/work/xet-core/xet-core/cas_client/src/download_utils.rs:528”},“filename”:“/home/runner/work/xet-core/xet-core/error_printer/src/lib.rs”,“line_number”:28}
{“timestamp”:“2025-07-01T18:05:15.966119Z”,“level”:“WARN”,“fields”:{“message”:“Reqwest(reqwest::Error { kind: Request, source: hyper_util::client::legacy::Error(SendRequest, hyper::Error(Io, Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }). Retrying…”},“filename”:“/home/runner/work/xet-core/xet-core/cas_client/src/http_client.rs”,“line_number”:242}
{“timestamp”:“2025-07-01T18:05:15.970285Z”,“level”:“WARN”,“fields”:{“message”:“Retry attempt #0. Sleeping 2.750031341s before the next attempt”},“filename”:“/root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/reqwest-retry-0.7.0/src/middleware.rs”,“line_number”:171}

Fetching 83 files: 1%| | 1/83 [43:04<58:51:31, 2584.04s/it]
Fetching 83 files: 17%|█▋ | 14/83 [43:04<3:32:15, 184.57s/it]
{“timestamp”:“2025-07-01T18:06:30.649359Z”,“level”:“ERROR”,“fields”:{“message”:“error downloading range, error: ReqwestMiddlewareError(Middleware(error sending request\n\nCaused by:\n 0: client error (SendRequest)\n 1: connection error\n 2: peer closed connection without sending TLS close_notify: h***s://docs.rs/rustls/latest/rustls/manual/_03_howto/index.html#unexpected-eof))”,“caller”:“/home/runner/work/xet-core/xet-core/cas_client/src/download_utils.rs:528”},“filename”:“/home/runner/work/xet-core/xet-core/error_printer/src/lib.rs”,“line_number”:28}
Traceback (most recent call last):
File “/home/ag/Models/molmo-inference.py”, line 15, in
model = AutoModelForCausalLM.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py”, line 593, in from_pretrained
return model_class.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/modeling_utils.py”, line 311, in _wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/modeling_utils.py”, line 4674, in from_pretrained
checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/modeling_utils.py”, line 1295, in _get_resolved_checkpoint_files
checkpoint_files, sharded_metadata = get_checkpoint_shard_files(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/utils/hub.py”, line 1110, in get_checkpoint_shard_files
cached_filenames = cached_files(
^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/utils/hub.py”, line 557, in cached_files
raise e
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/transformers/utils/hub.py”, line 485, in cached_files
snapshot_download(
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py”, line 114, in _inner_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/_snapshot_download.py”, line 327, in snapshot_download
thread_map(
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/tqdm/contrib/concurrent.py”, line 69, in thread_map
return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/tqdm/contrib/concurrent.py”, line 51, in _executor_map
return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/tqdm/std.py”, line 1181, in iter
for obj in iterable:
^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/concurrent/futures/_base.py”, line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/concurrent/futures/_base.py”, line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/concurrent/futures/_base.py”, line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/concurrent/futures/_base.py”, line 401, in __get_result
raise self._exception
File “/home/ag/conda/Molmo/lib/python3.12/concurrent/futures/thread.py”, line 59, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/_snapshot_download.py”, line 301, in _inner_hf_hub_download
return hf_hub_download(
^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py”, line 114, in _inner_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/file_download.py”, line 1008, in hf_hub_download
return _hf_hub_download_to_cache_dir(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/file_download.py”, line 1161, in _hf_hub_download_to_cache_dir
_download_to_tmp_and_move(
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/file_download.py”, line 1710, in _download_to_tmp_and_move
xet_get(
File “/home/ag/conda/Molmo/lib/python3.12/site-packages/huggingface_hub/file_download.py”, line 627, in xet_get
download_files(
RuntimeError: Data processing error: CAS service error : Reqwest Error: HTTP status client error (401 Unauthorized), domain: https://cas-server.xethub.hf.co/reconstruction/c4ac4717bebd033e12a7f0036103c7383614198445be5970f0187fa2bfc0d9c3

Thanks for your help!

2 Likes

Thanks for the additional details! There is potentially some work we can do here on our authentication to the storage system backing these files.

I opened up an issue here on the xet-core repo, since the issue can potentially be addressed there.

Feel free to add any additional context or subscribe to the issue there to get updates (I’ll also post here when we think we’ve resolved the issue).

2 Likes

Hey @alfredgabal - just wanted to let you know that we believe the root cause of this issue was not providing enough buffer between a token refresh and when that same token was set to expire. The PR for this is here and will be included in our next release.

Thank you for reporting!

2 Likes

This occurs completely at random when using:
https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/v1/chat/completions
(Default for Gradio chatbot). Makes the whole thing unusable. Every second results in 401 and then at random it works. Shouldn’t not related to authorization in that case. Very bad issue.

What more I am using it directly via huggingface space.

2 Likes

Just want to echo the above. I’m new to try Hugging Face space and I also used the Gradio chatbot template. For me the 401 error happens on every single attempt.

huggingface_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/v1/chat/completions 

More stack trace:


Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/gradio/queueing.py", line 622, in process_events
    response = await route_utils.call_process_api(
  File "/usr/local/lib/python3.10/site-packages/gradio/route_utils.py", line 323, in call_process_api
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 2016, in process_api
    result = await self.call_function(
  File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1581, in call_function
    prediction = await utils.async_iteration(iterator)
  File "/usr/local/lib/python3.10/site-packages/gradio/utils.py", line 691, in async_iteration
    return await anext(iterator)
  File "/usr/local/lib/python3.10/site-packages/gradio/utils.py", line 796, in asyncgen_wrapper
    response = await iterator.__anext__()
  File "/usr/local/lib/python3.10/site-packages/gradio/chat_interface.py", line 667, in _stream_fn
    first_response = await async_iteration(generator)
  File "/usr/local/lib/python3.10/site-packages/gradio/utils.py", line 691, in async_iteration
    return await anext(iterator)
  File "/usr/local/lib/python3.10/site-packages/gradio/utils.py", line 685, in __anext__
    return await anyio.to_thread.run_sync(
  File "/usr/local/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2470, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 967, in run
    result = context.run(func, *args)
  File "/usr/local/lib/python3.10/site-packages/gradio/utils.py", line 668, in run_sync_iterator_async
    return next(iterator)
  File "/home/user/app/app.py", line 30, in respond
    for message in client.chat_completion(
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/inference/_client.py", line 842, in chat_completion
    data = self.post(model=model_url, json=payload, stream=stream)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/inference/_client.py", line 305, in post
    hf_raise_for_status(response)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 477, in hf_raise_for_status
    raise _format(HfHubHTTPError, str(e), response) from e
huggingface_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/v1/chat/completions (Request ID: Root=1-688a5344-50f1183c2473d25317effe51;3895cba8-31c5-4c70-89a9-423bebbd23d5)
1 Like

https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/v1/chat/completions

I think this format’s endpoint is either old or has been retained for compatibility reasons. Let’s change it to the new implementation.

@alfredgabal the issue you were experiencing:

RuntimeError: Data processing error: CAS service error : Reqwest Error: HTTP status client error (401 Unauthorized), domain: https://cas-server.xethub.hf.co/reconstruction/c4ac4717bebd033e12a7f0036103c7383614198445be5970f0187fa2bfc0d9c3

Should be addressed with the most current version of hf-xet, just pip install -U hf-xet, verify that you have a version >= 1.1.7 and you should be good to go.

1 Like

Hi, I also meet the error and my hf-xet’s version is 1.1.7.following is traceback.

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/load.py", line 1412, in load_dataset
    builder_instance.download_and_prepare(
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/builder.py", line 894, in download_and_prepare
    self._download_and_prepare(
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/builder.py", line 948, in _download_and_prepare
    split_generators = self._split_generators(dl_manager, **split_generators_kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/packaged_modules/parquet/parquet.py", line 49, in _split_generators
    data_files = dl_manager.download_and_extract(self.config.data_files)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/download/download_manager.py", line 326, in download_and_extract
    return self.extract(self.download(url_or_urls))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/download/download_manager.py", line 159, in download
    downloaded_path_or_paths = map_nested(
                               ^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/utils/py_utils.py", line 504, in map_nested
    map_nested(
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/utils/py_utils.py", line 521, in map_nested
    _single_map_nested((function, obj, batched, batch_size, types, None, True, None))
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/utils/py_utils.py", line 389, in _single_map_nested
    return [mapped_item for batch in iter_batched(data_struct, batch_size) for mapped_item in function(batch)]
                                                                                              ^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/download/download_manager.py", line 220, in _download_batched
    self._download_single(url_or_filename, download_config=download_config)
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/download/download_manager.py", line 229, in _download_single
    out = cached_path(url_or_filename, download_config=download_config)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/datasets/utils/file_utils.py", line 177, in cached_path
    ).hf_hub_download(
      ^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/hf_api.py", line 5528, in hf_hub_download
    return hf_hub_download(
           ^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/file_download.py", line 1010, in hf_hub_download
    return _hf_hub_download_to_cache_dir(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/file_download.py", line 1171, in _hf_hub_download_to_cache_dir
    _download_to_tmp_and_move(
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/file_download.py", line 1723, in _download_to_tmp_and_move
    xet_get(
  File "/root/miniconda3/envs/mor/lib/python3.12/site-packages/huggingface_hub/file_download.py", line 629, in xet_get
    download_files(
RuntimeError: Data processing error: CAS service error : Reqwest Error: HTTP status client error (401 Unauthorized), domain: 

2 Likes

Hi @muenyz - thanks for the report!

At the end of the trace you provided there should have been a domain included - could you provide that for further troubleshooting?

Also if you could let me know:

  • The repository where you encountered this
  • What API (e.g., snapshot_download, or hf download, etc) you were using

That should help us narrow down the reasons that you ran into this. Thank you!

1 Like

Hi,

the domain was https://cas-server.xethub.hf.co/reconstruction/e4c425cb37d8e5464f8704c27f2956be05ad34629c3260c64603b451ced33924

I was trying to use load_dataset to get a dataset,may be codelion/fineweb-edu-1B.And I finally got the dataset by disabling the technique.

2 Likes

Thanks @muenyz - has this been a persistent issue? Meaning, if you attempt to issue another download request for the same resource, do you consistently run into a 401?

1 Like