401 unauthorized for create_inference_endpoint

Hello,
I’m trying to create an inference endpoint with a custom docker image using the huggingface_hub library because the web interface doesn’t allow environment variables to be set.

I first log in with huggingface-cli login, then call create_inference_endpoint and get a 401 error, then I tried calling login() within the python script in case that would help and got an identical error, shown below. I’ve also tried creating a new access token with the same result, and upgraded huggingface_hub from 0.20.x to 0.23.0, also with no change.
I’m at a bit of a loss; I suppose I could set the environment variables when creating the docker image, but that’s a pretty messy workaround for something that ought to work.

Enter your token (input will not be visible):
Add token as git credential? (Y/n)
Token is valid (permission: write).
Your token has been saved in your configured git credential helpers (store).
Your token has been saved to /home/srt/.cache/huggingface/token
Login successful
Traceback (most recent call last):
File “/home/srt/anaconda3/lib/python3.11/site-packages/huggingface_hub/utils/_errors.py”, line 304, in hf_raise_for_status
response.raise_for_status()
File “/home/srt/anaconda3/lib/python3.11/site-packages/requests/models.py”, line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.endpoints.huggingface.cloud/v2/endpoint/srt-primis

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/srt/hf_test/create_endpoint.py”, line 5, in
endpoint = create_inference_endpoint(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/srt/anaconda3/lib/python3.11/site-packages/huggingface_hub/hf_api.py”, line 7264, in create_inference_endpoint
hf_raise_for_status(response)
File “/home/srt/anaconda3/lib/python3.11/site-packages/huggingface_hub/utils/_errors.py”, line 371, in hf_raise_for_status
raise HfHubHTTPError(str(e), response=response) from e
huggingface_hub.utils._errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://api.endpoints.huggingface.cloud/v2/endpoint/srt-primis (Request ID: IWBbJQ)

401 Unauthorized

I am also trying to create an inference endpoint for a private model in my organization. I have the admin role in my organization and have logged in with a write access token but I am still getting this error. Not sure what the reason might be.