# 401 Client Error: Unauthorized for url: https://detect.roboflow.com/model/registry

**URL:** <https://discuss.roboflow.com/t/401-client-error-unauthorized-for-url-https-detect-roboflow-com-model-registry/5032>\
**Category:** 🤝  Community Help\
**Created:** [March 29, 2024, 4:02am UTC](https://discuss.roboflow.com/t/401-client-error-unauthorized-for-url-https-detect-roboflow-com-model-registry/5032 "2024-03-29T04:02:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/leo/32/2228_2.png) [@leo](https://discuss.roboflow.com/u/leo)\
**Post date:** [March 29, 2024, 4:02am UTC](https://discuss.roboflow.com/t/401-client-error-unauthorized-for-url-https-detect-roboflow-com-model-registry/5032/1 "2024-03-29T04:02:39Z")

</div>

The error pasted below occurs when using the Roboflow Hosted Inference API with [Inference](https://inference.roboflow.com/) and the following code:

```python
from inference_sdk import InferenceHTTPClient

CLIENT = InferenceHTTPClient(
    api_url="http://detect.roboflow.com",
    api_key="*API KEY*",
)

result = CLIENT.infer(image, model_id="*model id*")

```

```auto
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/inference_sdk/http/client.py in decorate(*args, **kwargs)
     81 try:
---> 82 return function(*args, **kwargs)
     83 except HTTPError as error:

10 frames
HTTPError: 401 Client Error: Unauthorized for url: https://detect.roboflow.com/model/registry

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

HTTPCallErrorError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/inference_sdk/http/client.py in decorate(*args, **kwargs)
     86 else:
     87 api_message = error.response.text
---> 88 raise HTTPCallErrorError(
     89 description=str(error),
     90 status_code=error.response.status_code,

HTTPCallErrorError: HTTPCallErrorError(description='401 Client Error: Unauthorized for url: https://detect.roboflow.com/model/registry', api_message='Unauthorized',status_code=401)

```

---

<div class="post-metadata">

**Author:** ![Lenny](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/lenny/32/2383_2.png) [@Lenny](https://discuss.roboflow.com/u/Lenny)\
**Post date:** [March 29, 2024, 4:03am UTC](https://discuss.roboflow.com/t/401-client-error-unauthorized-for-url-https-detect-roboflow-com-model-registry/5032/2 "2024-03-29T04:03:25Z")

</div>

The error message you’re seeing, `401 Client Error: Unauthorized`, typically indicates an issue with the API key you’re using. It’s possible that the API key is incorrect, expired, or doesn’t have the necessary permissions.

Here’s how you can troubleshoot this issue:

1. **Check your API key** : Make sure that the API key you’re using is correct. You can find your API key in your Roboflow account. Here’s a [guide on how to retrieve your API key](https://docs.roboflow.com/api-reference/introduction).

2. **Check your model ID** : Ensure that the model ID you’re using is correct. The model ID should be in the format `project_id/model_version`. You can find these details on the Versions page of your project in the Roboflow dashboard. Here’s a [guide on how to retrieve your project ID and model version number](https://docs.roboflow.com/api-reference/workspace-and-project-ids).

3. **Check your API key permissions** : If you’re still encountering the error after verifying the API key and model ID, it’s possible that your API key doesn’t have the necessary permissions. You might need to generate a new API key or update the permissions of your existing key.

If you’re still having trouble after trying these steps, I recommend reaching out to Roboflow’s support for further assistance.

* * *

> Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, and forum. If this solves your issue, please mark it as the solution using the checkbox icon. **If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.**

---

<div class="post-metadata">

**Author:** ![leo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/leo/32/2228_2.png) [@leo](https://discuss.roboflow.com/u/leo)\
**Post date:** [March 29, 2024, 4:05am UTC](https://discuss.roboflow.com/t/401-client-error-unauthorized-for-url-https-detect-roboflow-com-model-registry/5032/3 "2024-03-29T04:05:18Z")

</div>

This error can occur when the `api_url` argument when initializing `InferenceHTTPClient` is set to `http://detect.roboflow.com` instead of `https://detect.roboflow.com` (note the HTTP vs HTTPS)

The correct code snippet should look like this:

```python
CLIENT = InferenceHTTPClient(
    api_url="https://detect.roboflow.com",
    api_key="*api key*",
)

```

or look within the Roboflow app for a pre-generated code snippet.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [April 5, 2024, 4:06am UTC](https://discuss.roboflow.com/t/401-client-error-unauthorized-for-url-https-detect-roboflow-com-model-registry/5032/4 "2024-04-05T04:06:06Z")

</div>

Closed on April 5, 2024, 4:06am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
