class_docstr: Integration with the Hugging Face Inference API.
docstr: API_KEY preference order:
      1. provided at model creation
      2. provided at engine creation
      3. HUGGINGFACE_API_KEY env variable
      4. huggingface.api_key setting in config.json
docstr_tok: ["API_KEY","preference","order",":","1.","provided","at","model","creation","2.","provided","at","engine","creation","3",".","HUGGINGFACE_API_KEY","env","variable","4.","huggingface.api_key","setting","in","config.json"]
code: def _get_huggingface_api_key(self, args, strict=True):
      """
      API_KEY preference order:
          1. provided at model creation
          2. provided at engine creation
          3. HUGGINGFACE_API_KEY env variable
          4. huggingface.api_key setting in config.json
      """  # noqa
      # 1
      if "api_key" in args:
          return args["api_key"]
      # 2
      connection_args = self.engine_storage.get_connection_args()
      if "api_key" in connection_args:
          return connection_args["api_key"]
      # 3
      api_key = os.getenv("HUGGINGFACE_API_KEY")
      if api_key is not None:
          return api_key
      # 4
      config = Config()
      openai_cfg = config.get("huggingface", {})
      if "api_key" in openai_cfg:
          return openai_cfg["api_key"]
  
      if strict:
          raise Exception(
              f'Missing API key "api_key". Either re-create this ML_ENGINE specifying the `api_key` parameter,\
                   or re-create this model and pass the API key with `USING` syntax.'
          )
  
file_path: mindsdb/mindsdb/integrations/handlers/huggingface_api_handler/huggingface_api_handler.py
imports: import json
  import os
  from typing import Optional, Dict
  import pandas
  from huggingface_hub import HfApi
  from huggingface_hub import hf_hub_download
  from hugging_py_face import NLP, ComputerVision, AudioProcessing, get_in_df_supported_tasks
  from mindsdb.utilities.config import Config
  from mindsdb.integrations.libs.base import BaseMLEngine
  from .exceptions import UnsupportedTaskException, InsufficientParametersException
label_desc: Use image node_id 4 for calling the HuggingFaceInferenceAPIHandler obj's underlying member method code with example usage: obj._get_huggingface_api_key(args, strict) and returns: args, connection_args, api_key, openai_cfg