|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Setup and Configuration > AIU. - Artificial Intelligence Utility |
MiniRobotLanguage (MRL)
AIU.GetKey
Retrieve OpenAI-API Key

Intention
GetKey Command: Retrieving Your Current OpenAI API Key
The GetKey command allows you to retrieve the currently set OpenAI API key within your script.
This is useful for debugging, verification, or when you need to pass the key to another part of your program.
Let’s explore how to use it effectively.
The GetKey command retrieves the OpenAI API key that was previously set using the AIU.SetKey command.
You can store the retrieved key in a variable for further use or, if no variable is specified, it will be placed on the Top of Stack (TOS).
This command is part of the AIU - OpenAI API suite.
Why Do You Need It?
There are several scenarios where retrieving the current API key is valuable:
•Debugging: Verify that the correct key is active before making API calls.
•Dynamic Handling: Pass the key to other functions or scripts dynamically.
•Logging: Record the key in use (with caution) for troubleshooting purposes.
The command is simple to use. After setting the API key with AIU.SetKey, you can call AIU.GetKey with or without a variable.
Here’s how it works in practice:
Example Usage
' Set the OpenAI API Key
$$KEY=sk-abcdefghijklmnopqrstuvwxyz123456
AIU.SetKey|$$KEY
' Retrieve the API Key into a variable
AIU.GetKey|$$RET
DBP.$$RET ' Displays the key, e.g., sk-abcdefghijklmnopqrstuvwxyz123456
' Retrieve the API Key to the Top of Stack
AIU.GetKey
POP.$$RET
DBP.$$RET ' Displays the key, e.g., sk-abcdefghijklmnopqrstuvwxyz123456
If no key has been set, the command will return an empty string.
Syntax
AIU.GetKey[|P1]
AIU.Get_Key[|P1]
Parameter Explanation
P1 - (Optional) The variable where the retrieved API key will be stored. If omitted, the key is placed on the Top of Stack (TOS).
Example
'*****************************************************
' EXAMPLE: Retrieving the OpenAI API Key
'*****************************************************
' Set a sample API Key (replace with your actual key)
$$KEY=sk-samplekey1234567890abcdefg
AIU.SetKey|$$KEY
' Retrieve the key into $$RESULT
AIU.GetKey|$$RESULT
DBP.Retrieved Key: $$RESULT ' Outputs: Retrieved Key: sk-samplekey1234567890abcdefg
' Retrieve the key to the stack and pop it
AIU.GetKey
POP.$$STACK_RESULT
DBP.Stack Retrieved Key: $$STACK_RESULT ' Outputs: Stack Retrieved Key: sk-samplekey1234567890abcdefg
ENR.
Remarks
- The command assumes that an API key has been set previously using AIU.SetKey. If no key is set, it returns an empty string.
- Be cautious when displaying or logging the retrieved key, as it is sensitive information tied to your OpenAI account.
Limitations
- The command only retrieves the key currently in use by the AIU system and does not validate its authenticity or functionality.
See also: