Huggingface_hub.client giving error on list_deployed_models()

Hi all ,
I am getting the following error when I call the list_deployed_models() on the InferenceClient.

framework = "text-generation-inference"  # "text-to-speech", 
deployed_models = client.list_deployed_models([framework])
print(deployed_models)

Error:

BadRequestError: (Request ID: Root=1-67c47933-02bf30da3e80cb5307dc9184;4dbda49a-b0b7-48bc-b0f7-5f7e09fc28d6)

Bad request:
Not allowed to request framework/text-generation-inference for provider hf-inference

Any help is appreciated

Regards, Raj

3 Likes

I think the URL for the reference is no longer valid. Perhaps the library hasn’t been updated with the new URL?

There doesn’t seem to be an issue, but it might be fixed eventually.

1 Like

Hey @acloudfan,
I ran the code through InferenceClient and was able to replicate the same error you encountered. However, the error stack also includes an additional warning indicating that listing models via InferenceClient has been deprecated. Going forward, only warm models can be referenced, and this must be done using HfApi, not InferenceClient:
Warning:

/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_deprecation.py:131: FutureWarning: 'list_deployed_models' (from 'huggingface_hub.inference._client') is deprecated and will be removed from version '0.33.0'. HF Inference API is getting revamped and will only support warm models in the future (no cold start allowed). Use `HfApi.list_models(..., inference_provider='...')` to list warm models per provider.  
  warnings.warn(warning_message, FutureWarning)

As the warning suggests, modifying the implementation to use HfApi instead of InferenceClient allows model listing to work correctly. The following code successfully retrieves and lists the models:

import os
os.environ["HF_TOKEN"] = "hf_yourhftoken"
from huggingface_hub import HfApi
api = HfApi()
models = api.list_models(filter="text-generation-inference", limit=1000)
for model in models:
    print(model)

You can use the code above to list models without any issues. Feel free to modify or remove the limit argument if you need to retrieve all models for a specific task.

For reference, you can check the list of available tasks in this message from @Wauplin:

Hope this helps! Let me know if it resolves your issue.

1 Like