class_docstr: This integration seamlessly combines MindsDB and Leonardo AI to create a powerful
  AI-driven solution for creative content generation.
  
  Content Generation with Leonardo AI: Harness the power of advanced generative
  models for creative content production. From realistic images to artistic text, Leonardo
  AI opens up new possibilities for content creators.
class_docstr_tok: ["This","integration","seamlessly","combines","MindsDB","and","Leonardo","AI","to","create","a","powerful","AI-driven","solution","for","creative","content","generation",".","Content","Generation","with","Leonardo","AI",":","Harness","the","power","of","advanced","generative","models","for","creative","content","production",".","From","realistic","images","to","artistic","text",",","Leonardo","AI","opens","up","new","possibilities","for","content","creators","."]
docstr: API_KEY preference order:
      1. provided at model creation
      2. provided at engine creation
      3. LEONARDO_API_KEY env variable
      4. leonardo.api_key setting in config.json
docstr_tok: ["API_KEY","preference","order",":","1.","provided","at","model","creation","2.","provided","at","engine","creation","3",".","LEONARDO_API_KEY","env","variable","4.","leonardo.api_key","setting","in","config.json"]
code: def _get_leonardo_api_key(
      self, args, engine_storage: HandlerStorage, strict=True
  ):
      """
      API_KEY preference order:
          1. provided at model creation
          2. provided at engine creation
          3. LEONARDO_API_KEY env variable
          4. leonardo.api_key setting in config.json
      """
  
      # 1
      if "api_key" in args["using"]:
          return args["using"]["api_key"]
      # 2
      connection_args = engine_storage.get_connection_args()
      if "api_key" in connection_args:
          return connection_args["api_key"]
      # 3
      api_key = os.getenv("LEONARDO_API_KEY")
      if api_key is not None:
          return api_key
      # 4
      config = Config()
      leonardo_cfg = config.get("leonardo", {})
      if "api_key" in leonardo_cfg:
          return leonardo_cfg["api_key"]
  
      if strict:
          raise Exception(
              '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/leonardoai_handler/leonardo_ai_handler.py
imports: import os
  import requests
  import time
  from typing import Dict, Optional
  from mindsdb.integrations.libs.llm_utils import get_completed_prompts
  import pandas
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.utilities import log
  from mindsdb.interfaces.storage.model_fs import HandlerStorage
  from mindsdb.utilities.config import Config
label_desc: Use image node_id 4 for calling the LeonardoAIHandler obj's underlying member method code with example usage: obj._get_leonardo_api_key(args, engine_storage, strict) and returns: args, connection_args, api_key, leonardo_cfg