AIU. - Artificial Intelligence Utility

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Setup and Configuration >

AIU. - Artificial Intelligence Utility

AIU.SaveKey

Previous Top Next


MiniRobotLanguage (MRL)

 

AIU.SaveKey
Save OpenAI-API Key to a File

 

clip0584

 

Intention

 

SaveKey Command: Storing Your OpenAI API Key Securely
 
The SaveKey command enables you to save your OpenAI API key to a file, enhancing security and convenience for future use in your scripts.

This command is a vital part of the AIU - OpenAI API suite, allowing you to safeguard your key and streamline its management.

 

What is the SaveKey Command?

 

The SaveKey command stores an OpenAI API key in a file, optionally at a custom path you specify.

If no path is provided, it defaults to a predefined location relative to your script or executable, typically in the AIU_Folder directory.

 

Why Use the SaveKey Command?

 

Saving your API key to a file offers several benefits:

Security: Keeps the key out of plain-text scripts, reducing exposure risk.

Convenience: Allows reuse across multiple scripts via AIU.SetKey with the 'fromFile' option.

Management: Centralizes key storage for easier updates or retrieval.

 

How to Use the SaveKey Command?

 

To use AIU.SaveKey, provide the API key as the first parameter and, optionally, a file path as the second.

If the path is omitted, the key is saved to a default file in the AIU_Folder directory, which can be retrieved using AIU.GetFolder.

 

Example Usage

 

' Save the API Key to the default location

$$KEY=sk-abcdefghijklmnopqrstuvwxyz123456

AIU.SaveKey|$$KEY

DBP.Key saved to default location: ?exeloc\AIU_Folder\

 

' Save the API Key to a custom file path

$$KEY=sk-abcdefghijklmnopqrstuvwxyz123456

$$PATH=C:\MyKeys\MyAPIKey.key

AIU.SaveKey|$$KEY|$$PATH

DBP.Key saved to: $$PATH

 

Note: The key must be at least 5 characters long, or the command will fail.

 

Syntax

 

AIU.SaveKey|P1[|P2]

AIU.Save_Key|P1[|P2]

 

Parameter Explanation

 

P1 - The OpenAI API key to save (required, minimum 5 characters).

P2 - (Optional) The file path where the key will be saved. If omitted, defaults to the AIU_Folder directory.

 

Example

 

'*****************************************************

' EXAMPLE: Saving the OpenAI API Key

'*****************************************************

' Save to default location

$$KEY=sk-samplekey1234567890abcdefg

AIU.SaveKey|$$KEY

DBP.Key saved to default AIU_Folder

 

' Save to custom location and load it back

$$KEY=sk-samplekey1234567890abcdefg

$$PATH=C:\APIKeys\MyKey.dat

AIU.SaveKey|$$KEY|$$PATH

AIU.SetKey|fromFile|$$PATH

AIU.GetKey|$$RET

DBP.Retrieved Key: $$RET ' Outputs: sk-samplekey1234567890abcdefg

ENR.

 

Remarks

 

- The key is saved as provided; encryption is not explicitly guaranteed by this command alone (depends on implementation).

- Use AIU.SetKey with 'fromFile' to load the saved key.

- Ensure the file path (if specified) is valid and writable, or the command may fail silently.

 

Limitations

 

- The API key must be at least 5 characters long; shorter keys will cause the command to fail.

- The file path, if provided, must be at least 3 characters long to be considered valid.

 

See also:

 

AIU.Set_Key

AIU.Get_Key

AIU.Get_Folder