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

The error pasted below occurs when using the Roboflow Hosted Inference API with Inference and the following code:

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*")
---------------------------------------------------------------------------
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)

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.

  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.

  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.

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:

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

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

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