Repository: mindsdb/mindsdb
Pull request: modify get_api_key util function and affected handlers
## Description

Please include a summary of the change and the issue it solves. 

Fixes #7496 

## Type of change

(Please delete options that are not relevant)

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [ ] My code follows the style guidelines(PEP 8) of MindsDB.
- [ ] I have appropriately commented on my code, especially in complex areas.
- [ ] Necessary documentation updates are either made or tracked in issues.
- [ ] Relevant unit and integration tests are updated or added.





Problem statement:
[refactor] Modify `get_api_key` to always check integration name in field
Currently, `mindsdb.integrations.utilities.handler_utils.get_api_key` checks for the parameter `api_name` only in the env variable and config file. We should modify its behavior so that it also checks for f`{integration_name}_api_key` in model creation and engine creation time arguments. This will enable its usage for cases like `serper_api_key` in the langchain handler.

The cost of doing this is that documentation and model commands for all `api_key` based integrations will have to be modified to continue working. For example:

```sql
CREATE ML_ENGINE openai FROM openai USING api_key = 'sk-...';
```

Will now be:

```sql
CREATE ML_ENGINE openai FROM openai USING openai_api_key = 'sk-...';
```

Hints from issue discussion:

Commit message: corrected error message

Patch to review:
diff --git a/docs/integrations/ai-engines/anthropic.mdx b/docs/integrations/ai-engines/anthropic.mdx
index d15edbe7c69..60a61dd24d5 100644
--- a/docs/integrations/ai-engines/anthropic.mdx
+++ b/docs/integrations/ai-engines/anthropic.mdx
@@ -27,7 +27,7 @@ You can create an Anthropic engine using this command:
 CREATE ML_ENGINE anthropic_engine
 FROM anthropic
 USING
-    api_key = 'your-anthropic-api-key';
+    anthropic_api_key = 'your-anthropic-api-key';
 ```
 
 <Tip>
diff --git a/docs/integrations/ai-engines/cohere.mdx b/docs/integrations/ai-engines/cohere.mdx
index e62c0ed0ade..87f13646b5f 100644
--- a/docs/integrations/ai-engines/cohere.mdx
+++ b/docs/integrations/ai-engines/cohere.mdx
@@ -27,7 +27,7 @@ You can create an Cohere engine using this command:
 CREATE ML_ENGINE cohere_engine
 FROM cohere
 USING
-    api_key = 'your-cohere-api-key';
+    cohere_api_key = 'your-cohere-api-key';
 ```
 
 <Tip>
diff --git a/docs/integrations/ai-engines/huggingface.mdx b/docs/integrations/ai-engines/huggingface.mdx
index 055b6a36d24..972d17adbc0 100644
--- a/docs/integrations/ai-engines/huggingface.mdx
+++ b/docs/integrations/ai-engines/huggingface.mdx
@@ -46,7 +46,7 @@ Please note that in order to use the Hugging Face Inference API, you need to cre
 ```sql
 CREATE ML_ENGINE hf_inference_api
 FROM huggingface_api
-USING api_key = 'hf_xxx';
+USING huggingface_api_api_key = 'hf_xxx';
 ```
 
 You can generate Hugging Face tokens in the `Settings -> Access Tokens` tab of your Hugging Face account.
diff --git a/docs/integrations/ai-engines/langchain.mdx b/docs/integrations/ai-engines/langchain.mdx
index ae5de54ee78..6ea78526947 100644
--- a/docs/integrations/ai-engines/langchain.mdx
+++ b/docs/integrations/ai-engines/langchain.mdx
@@ -21,11 +21,15 @@ Before creating a model, it is required to create an AI engine based on the prov
 If you installed MindsDB locally, make sure to install all LangChain dependencies by running `pip install .[langchain]` or from the [requirements.txt](https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/handlers/langchain_handler/requirements.txt) file.
 </Tip>
 
-You can create a LangChain engine using this command:
+You can create a LangChain engine using this command and providing at least one of OpenAI or Anthropic API keys:
 
 ```sql
 CREATE ML_ENGINE langchain_engine
-FROM langchain;
+FROM langchain
+USING
+    openai_api_key = 'your-openai-api-key',
+    anthropic_api_key = 'your-anthropic-api-key',
+    serper_api_key = 'your-serper-api-key'; -- this is optional
 ```
 
 The name of the engine (here, `langchain_engine`) should be used as a value for the `engine` parameter in the `USING` clause of the `CREATE MODEL` statement.
@@ -39,9 +43,10 @@ CREATE MODEL model_name
 PREDICT column_to_be_predicted
 USING
     engine = 'langchain_engine',
-    model_name = 'anthropic-or-openai-model'
-    api_key = 'either-openai-or-anthropic-api-key',
-    serper_api_key = 'if-serper-dev-search-is-used',
+    model_name = 'anthropic-or-openai-model',
+    -- openai_api_key = 'your-openai-api-key', -- if not provided in the ML_ENGINE
+    -- anthropic_api_key = 'your-anthropic-api-key', -- if not provided in the ML_ENGINE
+    -- serper_api_key = 'if-serper-dev-search-is-used', -- if not provided in the ML_ENGINE
     prompt_template = 'message to the model that may include some {{input}} columns as variables',
     ...;
 ```
diff --git a/docs/integrations/ai-engines/llamaindex.mdx b/docs/integrations/ai-engines/llamaindex.mdx
index 0b0ff1c60a2..d54279019ed 100644
--- a/docs/integrations/ai-engines/llamaindex.mdx
+++ b/docs/integrations/ai-engines/llamaindex.mdx
@@ -14,7 +14,8 @@ Before creating a model, you can create an ML engine for LlamaIndex using the `C
 ```sql
 CREATE ML_ENGINE llama_index
 FROM llama_index
-USING api_key='your_openai_api_key';
+USING
+    llama_index_api_key='your-api-key';
 ```
 
 You can check the available engines with this command:
diff --git a/docs/integrations/ai-engines/openai.mdx b/docs/integrations/ai-engines/openai.mdx
index ab8f2e79cb5..1f967652593 100644
--- a/docs/integrations/ai-engines/openai.mdx
+++ b/docs/integrations/ai-engines/openai.mdx
@@ -27,7 +27,7 @@ You can create an OpenAI engine using this command:
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-    api_key = 'your-openai-api-key';
+    openai_api_key = 'your-openai-api-key';
 ```
 
 <Tip>
diff --git a/docs/integrations/app-integrations/gmail.mdx b/docs/integrations/app-integrations/gmail.mdx
index 5c6b54370de..c193d573df2 100644
--- a/docs/integrations/app-integrations/gmail.mdx
+++ b/docs/integrations/app-integrations/gmail.mdx
@@ -130,7 +130,7 @@ First, create an OpenAI engine, passing your OpenAI API key:
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-    api_key = 'your-openai-api-key';
+    openai_api_key = 'your-openai-api-key';
 ```
 
 Then, create a model using this engine:
diff --git a/docs/nlp/json-from-text.mdx b/docs/nlp/json-from-text.mdx
index 3e8f8dd3ffa..f27af8f8985 100644
--- a/docs/nlp/json-from-text.mdx
+++ b/docs/nlp/json-from-text.mdx
@@ -69,7 +69,7 @@ Let's create an OpenAI model.
     CREATE ML_ENGINE openai_engine
     FROM openai
     USING
-        api_key = 'your-openai-api-key';
+        openai_api_key = 'your-openai-api-key';
     ```
     ```sql
     CREATE MODEL mindsdb.nlp_model
diff --git a/docs/nlp/nlp-mindsdb-openai.mdx b/docs/nlp/nlp-mindsdb-openai.mdx
index 16e4066dfd4..b00658498fa 100644
--- a/docs/nlp/nlp-mindsdb-openai.mdx
+++ b/docs/nlp/nlp-mindsdb-openai.mdx
@@ -34,7 +34,7 @@ We first create the openai engine by providing the api_key:
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-  api_key= 'YOUR_OPENAI_API_KEY';
+  openai_api_key= 'YOUR_OPENAI_API_KEY';
 ```
 
 Next, use this engine to create the model as:
diff --git a/docs/nlp/question-answering-inside-mysql-with-openai.mdx b/docs/nlp/question-answering-inside-mysql-with-openai.mdx
index af59c76573d..be688d5812b 100644
--- a/docs/nlp/question-answering-inside-mysql-with-openai.mdx
+++ b/docs/nlp/question-answering-inside-mysql-with-openai.mdx
@@ -58,7 +58,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/docs/nlp/sentiment-analysis-inside-mysql-with-openai.mdx b/docs/nlp/sentiment-analysis-inside-mysql-with-openai.mdx
index c98823a5436..f4d52bdcb84 100644
--- a/docs/nlp/sentiment-analysis-inside-mysql-with-openai.mdx
+++ b/docs/nlp/sentiment-analysis-inside-mysql-with-openai.mdx
@@ -58,7 +58,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/docs/nlp/text-summarization-inside-mysql-with-openai.mdx b/docs/nlp/text-summarization-inside-mysql-with-openai.mdx
index adeaf645f94..b7ca64ef24e 100644
--- a/docs/nlp/text-summarization-inside-mysql-with-openai.mdx
+++ b/docs/nlp/text-summarization-inside-mysql-with-openai.mdx
@@ -58,7 +58,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/docs/sql/api/finetune.mdx b/docs/sql/api/finetune.mdx
index a9194799087..991129d16d6 100644
--- a/docs/sql/api/finetune.mdx
+++ b/docs/sql/api/finetune.mdx
@@ -299,7 +299,7 @@ First, create an OpenAI engine, passing your OpenAI API key:
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-    api_key = 'your-openai-api-key';
+    openai_api_key = 'your-openai-api-key';
 ```
 
 Then, create a model using this engine:
diff --git a/docs/sql/create/ml-engine.mdx b/docs/sql/create/ml-engine.mdx
index 2425ecf0356..190acd80096 100644
--- a/docs/sql/create/ml-engine.mdx
+++ b/docs/sql/create/ml-engine.mdx
@@ -93,7 +93,7 @@ Here we create an ML engine using the OpenAI handler and providing an OpenAI API
 CREATE ML_ENGINE my_openai_engine
 FROM openai
 USING
-    api_key = '<your opanai api key>';
+    openai_api_key = '<your opanai api key>';
 ```
 
 On execution, we get:
diff --git a/docs/sql/tutorials/house-sales-timegpt.mdx b/docs/sql/tutorials/house-sales-timegpt.mdx
index 55c388ba7ab..87014c5ccc1 100644
--- a/docs/sql/tutorials/house-sales-timegpt.mdx
+++ b/docs/sql/tutorials/house-sales-timegpt.mdx
@@ -26,7 +26,7 @@ SHOW ML_ENGINES;
 If you see the TimeGPT engine on the list, you are ready to follow the tutorials. If you do not see TimeGPT on the list, you will have to create an instance of the engine first with this command:
 
 ```sql
-CREATE ML_ENGINE timegpt FROM timegpt USING api_key = '...'
+CREATE ML_ENGINE timegpt FROM timegpt USING timegpt_api_key = '...'
 ```
 
 Notice that the `USING` clause is optional, but you must pass an API key eventually (either at model creation, engine creation, model usage, or in the mindsdb configuration file). The only exception to this is when using `cloud.mindsdb.com`. If you want your own token please register [here](https://www.nixtla.io/) (Submit Interest).
diff --git a/docs/sql/tutorials/image-generator.mdx b/docs/sql/tutorials/image-generator.mdx
index b05343e941b..147e2959913 100644
--- a/docs/sql/tutorials/image-generator.mdx
+++ b/docs/sql/tutorials/image-generator.mdx
@@ -20,7 +20,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/docs/sql/tutorials/monthly-expediture-timegpt.mdx b/docs/sql/tutorials/monthly-expediture-timegpt.mdx
index e0858bdd2b3..1a08b40cb1c 100644
--- a/docs/sql/tutorials/monthly-expediture-timegpt.mdx
+++ b/docs/sql/tutorials/monthly-expediture-timegpt.mdx
@@ -26,7 +26,7 @@ SHOW ML_ENGINES;
 If you see the TimeGPT engine on the list, you are ready to follow the tutorials. If you do not see TimeGPT on the list, you will have to create an instance of the engine first with this command:
 
 ```sql
-CREATE ML_ENGINE timegpt FROM timegpt USING api_key = '...'
+CREATE ML_ENGINE timegpt FROM timegpt USING timegpt_api_key = '...'
 ```
 
 Notice that the `USING` clause is optional, but you must pass an API key eventually (either at model creation, engine creation, model usage, or in the mindsdb configuration file). The only exception to this is when using `cloud.mindsdb.com`. If you want your own token please register [here](https://www.nixtla.io/) (Submit Interest).
diff --git a/docs/sql/tutorials/slack-chatbot.mdx b/docs/sql/tutorials/slack-chatbot.mdx
index e65c6e854a7..09f2ccec9fa 100644
--- a/docs/sql/tutorials/slack-chatbot.mdx
+++ b/docs/sql/tutorials/slack-chatbot.mdx
@@ -128,7 +128,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/docs/sql/tutorials/twilio-chatbot.mdx b/docs/sql/tutorials/twilio-chatbot.mdx
index a7ffe110768..dde61bc0114 100644
--- a/docs/sql/tutorials/twilio-chatbot.mdx
+++ b/docs/sql/tutorials/twilio-chatbot.mdx
@@ -25,7 +25,7 @@ Then go to your MindsDB SQL Editor and enter the following commands to create AI
     CREATE ML_ENGINE openai_engine
     FROM openai
     USING
-    api_key = 'sk-xxx';
+        openai_api_key = 'sk-xxx';
     ```
 
     Now you can create a model:
diff --git a/docs/sql/tutorials/twitter-chatbot.mdx b/docs/sql/tutorials/twitter-chatbot.mdx
index 3ddf88087fc..d83258cfc82 100644
--- a/docs/sql/tutorials/twitter-chatbot.mdx
+++ b/docs/sql/tutorials/twitter-chatbot.mdx
@@ -38,7 +38,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-    api_key = 'your-openai-api-key';
+    openai_api_key = 'your-openai-api-key';
 ```
 
 Then, create a model using this engine:
@@ -86,7 +86,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = ‘your-openai-api-key’;
+	openai_api_key = ‘your-openai-api-key’;
 ```
 </Tip>
 
diff --git a/docs/sql/tutorials/twitterbot-mariadb-enterprise-server-skysql.mdx b/docs/sql/tutorials/twitterbot-mariadb-enterprise-server-skysql.mdx
index e5777842c4d..cf035e6ba6d 100644
--- a/docs/sql/tutorials/twitterbot-mariadb-enterprise-server-skysql.mdx
+++ b/docs/sql/tutorials/twitterbot-mariadb-enterprise-server-skysql.mdx
@@ -264,7 +264,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/docs/tutorials/sentiment-analysis-intercom-data-airbyte.mdx b/docs/tutorials/sentiment-analysis-intercom-data-airbyte.mdx
index 225aebad2c7..0e384886cea 100644
--- a/docs/tutorials/sentiment-analysis-intercom-data-airbyte.mdx
+++ b/docs/tutorials/sentiment-analysis-intercom-data-airbyte.mdx
@@ -42,7 +42,7 @@ Before creating an OpenAI model, please create an engine, providing your OpenAI
 CREATE ML_ENGINE openai_engine
 FROM openai
 USING
-	api_key = 'your-openai-api-key';
+	openai_api_key = 'your-openai-api-key';
 ```
 </Tip>
 
diff --git a/mindsdb/integrations/handlers/anthropic_handler/README.md b/mindsdb/integrations/handlers/anthropic_handler/README.md
index da66934b51f..d956d708368 100644
--- a/mindsdb/integrations/handlers/anthropic_handler/README.md
+++ b/mindsdb/integrations/handlers/anthropic_handler/README.md
@@ -15,7 +15,7 @@ Create a ML Engine with the new `anthropic` engine.
 CREATE ML_ENGINE Anthropic_ML_Engine
 FROM anthropic
 USING
-  api_key = 'your_api_key';
+  anthropic_api_key = 'your_api_key';
 ~~~~
 
 ~~~ sql
diff --git a/mindsdb/integrations/handlers/clipdrop_handler/README.md b/mindsdb/integrations/handlers/clipdrop_handler/README.md
index 221648ff403..b15c3ab4c3f 100644
--- a/mindsdb/integrations/handlers/clipdrop_handler/README.md
+++ b/mindsdb/integrations/handlers/clipdrop_handler/README.md
@@ -24,7 +24,7 @@ The first step is to create a ML Engine with the new `clipdrop` engine.
 CREATE ML_ENGINE clipdrop_engine
 FROM clipdrop
 USING
-  api_key = 'your_api_key';
+  clipdrop_api_key = 'your_api_key';
 ~~~~
 
 
diff --git a/mindsdb/integrations/handlers/cohere_handler/README.md b/mindsdb/integrations/handlers/cohere_handler/README.md
index ad9cbe72dda..29afaca125e 100644
--- a/mindsdb/integrations/handlers/cohere_handler/README.md
+++ b/mindsdb/integrations/handlers/cohere_handler/README.md
@@ -23,7 +23,7 @@ The first step is to create a ML Engine with the new `cohere` engine.
 CREATE ML_ENGINE Cohere_ML_Engine
 FROM cohere
 USING
-  api_key = 'your_api_key';
+  cohere_api_key = 'your_api_key';
 ~~~~
 
 ### Detect_language 
diff --git a/mindsdb/integrations/handlers/huggingface_api_handler/README.md b/mindsdb/integrations/handlers/huggingface_api_handler/README.md
index 10e32ac2f43..71f47d54a6b 100644
--- a/mindsdb/integrations/handlers/huggingface_api_handler/README.md
+++ b/mindsdb/integrations/handlers/huggingface_api_handler/README.md
@@ -18,7 +18,7 @@ The first step to make use of this handler is to create an ML Engine. This can b
 CREATE ML_ENGINE hf_api_engine
 FROM huggingface_api
 USING
-  api_key = '<YOUR_API_KEY>';
+  huggingface_api_api_key = '<YOUR_API_KEY>';
 ```
 
 ## Creating Models
diff --git a/mindsdb/integrations/handlers/pgvector_handler/README.md b/mindsdb/integrations/handlers/pgvector_handler/README.md
index 59183fea112..dafc87311c3 100644
--- a/mindsdb/integrations/handlers/pgvector_handler/README.md
+++ b/mindsdb/integrations/handlers/pgvector_handler/README.md
@@ -69,7 +69,7 @@ CREATE TABLE pvec.embed
 CREATE ML_ENGINE openai
 FROM openai
 USING
-    api_key = 'your-openai-api-key';
+    openai_api_key = 'your-openai-api-key';
 
 CREATE MODEL openai_emb 
 PREDICT embedding 
diff --git a/mindsdb/integrations/handlers/stabilityai_handler/README.md b/mindsdb/integrations/handlers/stabilityai_handler/README.md
index f36689e5bfc..6b6d4176ddf 100644
--- a/mindsdb/integrations/handlers/stabilityai_handler/README.md
+++ b/mindsdb/integrations/handlers/stabilityai_handler/README.md
@@ -27,7 +27,7 @@ The first step is to create a ML Engine with the new `stabilityai` engine.
 CREATE ML_ENGINE stabilityai_engine
 FROM stabilityai
 USING
-  api_key = 'your_api_key';
+  stabilityai_api_key = 'your_api_key';
 ~~~~
 
 
diff --git a/mindsdb/integrations/utilities/handler_utils.py b/mindsdb/integrations/utilities/handler_utils.py
index 20a02493aa9..40bbadfdd1b 100644
--- a/mindsdb/integrations/utilities/handler_utils.py
+++ b/mindsdb/integrations/utilities/handler_utils.py
@@ -31,25 +31,24 @@ def get_api_key(
         4. api_key setting in config.json
     """
     # 1
-    if "api_key" in create_args:
-        return create_args["api_key"]
+    if f"{api_name.lower()}_api_key" in create_args:
+        return create_args[f"{api_name.lower()}_api_key"]
     # 2
     connection_args = engine_storage.get_connection_args()
-    if "api_key" in connection_args:
-        return connection_args["api_key"]
+    if f"{api_name.lower()}_api_key" in connection_args:
+        return connection_args[f"{api_name.lower()}_api_key"]
     # 3
-    api_key = os.getenv(f"{api_name.upper()}_API_KEY")
+    api_key = os.getenv(f"{api_name.lower()}_api_key")
     if api_key is not None:
         return api_key
     # 4
     config = Config()
     api_cfg = config.get(api_name, {})
-    if "api_key" in api_cfg:
-        return api_cfg["api_key"]
+    if f"{api_name.lower()}_api_key" in api_cfg:
+        return api_cfg[f"{api_name.lower()}_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.'
+            "Missing API key f'"{api_name.lower()}_api_key"'. Either re-create this ML_ENGINE specifying the f'"{api_name.lower()}_api_key"' parameter, or re-create this model and pass the API key with `USING` syntax."
         )  # noqa
     return None
diff --git a/tests/integration_tests/flows/test_predict_text_sentiment_openai_tutorial.py b/tests/integration_tests/flows/test_predict_text_sentiment_openai_tutorial.py
index 2c9713f279f..91cdf25dc95 100644
--- a/tests/integration_tests/flows/test_predict_text_sentiment_openai_tutorial.py
+++ b/tests/integration_tests/flows/test_predict_text_sentiment_openai_tutorial.py
@@ -37,7 +37,7 @@ class QueryStorage:
 
     create_engine = """
                     CREATE ML_ENGINE openai2
-                    FROM openai USING api_key='%s';
+                    FROM openai USING openai_api_key='%s';
                         """
 
     create_model = """
diff --git a/tests/unit/ml_handlers/test_anthropic.py b/tests/unit/ml_handlers/test_anthropic.py
index c6ad7debb8a..020e1d13e57 100644
--- a/tests/unit/ml_handlers/test_anthropic.py
+++ b/tests/unit/ml_handlers/test_anthropic.py
@@ -19,7 +19,7 @@ def setup_method(self):
             CREATE ML_ENGINE anthropic
             FROM anthropic
             USING
-            api_key = '{self.get_api_key('ANTHROPIC_API_KEY')}';
+            anthropic_api_key = '{self.get_api_key('ANTHROPIC_API_KEY')}';
             """
         )
 
diff --git a/tests/unit/ml_handlers/test_clipdrop.py b/tests/unit/ml_handlers/test_clipdrop.py
index 6d00f61c857..bd4cb473b7b 100644
--- a/tests/unit/ml_handlers/test_clipdrop.py
+++ b/tests/unit/ml_handlers/test_clipdrop.py
@@ -19,7 +19,7 @@ def setup_method(self):
             CREATE ML_ENGINE clipdrop_engine
             FROM clipdrop
             USING
-            api_key = '{self.get_api_key('CLIPDROP_API_KEY')}';
+            clipdrop_api_key = '{self.get_api_key('CLIPDROP_API_KEY')}';
             """
         )
 
diff --git a/tests/unit/ml_handlers/test_stabilityai.py b/tests/unit/ml_handlers/test_stabilityai.py
index 459a6d1a024..0aec623324b 100644
--- a/tests/unit/ml_handlers/test_stabilityai.py
+++ b/tests/unit/ml_handlers/test_stabilityai.py
@@ -19,7 +19,7 @@ def setup_method(self):
             CREATE ML_ENGINE stability_engine
             FROM stabilityai
             USING
-            api_key = '{self.get_api_key('STABILITY_API_KEY')}';
+            stabilityai_api_key = '{self.get_api_key('STABILITY_API_KEY')}';
             """
         )
 
diff --git a/tests/unit/test_mongodb_server.py b/tests/unit/test_mongodb_server.py
index f0a211ded7b..f52ff7d370d 100644
--- a/tests/unit/test_mongodb_server.py
+++ b/tests/unit/test_mongodb_server.py
@@ -233,7 +233,7 @@ def t_create_ml_engine(self, client_con, mock_executor):
 
         ast = mock_executor.call_args[0][0]
 
-        expected_sql = "CREATE ML_ENGINE openai2 FROM openai USING api_key= 'qqq'"
+        expected_sql = "CREATE ML_ENGINE openai2 FROM openai USING openai_api_key= 'qqq'"
         assert parse_sql(expected_sql, 'mindsdb').to_string() == ast.to_string()
 
     def t_list_ml_engines(self, client_con, mock_executor):


Code review comments:
diff_hunk: @@ -49,6 +49,6 @@ def get_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.'
+            "Missing API key f'"{api_name.lower()}_api_key"'. Either re-create this ML_ENGINE specifying the f'"{api_name.lower()}_api_key"' parameter, or re-create this model and pass the API key with `USING` syntax."
path: mindsdb/integrations/utilities/handler_utils.py
text: @user1:
The `f` that indicates this is an f-string should be present only once, at the start of the string. Like so:

```python
f"Missing API key '{api_name.lower()}_api_key'. Either re-create this ML_ENGINE specifying the '{api_name.lower()}_api_key' parameter, or re-create this model and pass the API key with `USING` syntax."
```

@user1:
(as it is right now, it will not work)

@author:
That's right. Thank you @user1