AIX. - Grok / X - API

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIX. - Grok / X - API > !Setup and Configuration >

AIX. - Grok / X - API

AIX.SetKey

Previous Top Next


MiniRobotLanguage (MRL)

 

AIX.Set Key
Set the API Key for Grok Authentication

 

Intention

 

SetKey Command: Initiating Your Script with a License Key
 
Before diving into the world of AI scripting with xAI's Grok, it's essential to set the stage with the SetKey command.

This command is the key that grants you access to the powerful AI functionalities offered by xAI's Grok API, supporting models like grok-1 ($0.0001/token), grok-2 ($0.00015/token), and grok-3 ($0.0002/token with volume discounts).

 

What is the SetKey Command?

 

The SetKey command is the first command you need to include at the beginning of your script.

It's like the key to a treasure chest; without it, you can't unlock the AI capabilities of the AIX - Grok / X - API suite.

 

Why Do You Need It?

You might be wondering why there's a need for such a key.
The reason is that the AI functionalities you are looking to use are not processed locally on your computer.

Instead, they are handled remotely in the high-powered xAI Cloud.
This License Key ensures that you have the proper authorization to access these cloud-based services, enabling usage of models like grok-3 at $0.0002 per token with potential volume discounts.

 

How to Obtain the License Key?

To get your hands on this key, you'll need to visit xAI's official website.
Once there, follow the instructions to register and obtain your xAI-Grok-API License Key.
Keep this key safe, as you'll need it every time you want to use xAI's Grok services, which support models like grok-1 ($0.0001/token), grok-2 ($0.00015/token), and grok-3 ($0.0002/token with discounts).

 

How to Use the SetKey Command?

Once you have your License Key, it's time to put it to use.
At the very start of your script, include the AIX.SetKey command followed by your License Key.
This will authenticate your script with xAI's cloud services.

On the long run, you may prefer the second or third options (see below) that will encrypt your key into a file or use a text file for added security.

 

The AIX.SetKey-Command has multiple Usage Options.

 

1. You can directly set the Key in the Script.

Here is a Sample Script that shows how this is done.

 

' IMPORTANT: This API-Key is a phantasy API-Key it must be replaced with your xAI-Grok-API-Key.

$$KEY=xai_abcdefghijklmnopqrstuvwxyz123456

 

' Test if we are online, AI-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set xAI-Grok-API-Key

AIX.SetKey|$$KEY

 

' Set Model (e.g., grok-3 at $0.0002/token with volume discounts)

AIX.Set Model|"grok-3"

 

' Set Model-Temperature

AIX.Set Temperature|0

 

' Set Max-Tokens (Possible length of answer, up to 2000 Tokens or ~6000 characters, cost varies by model)

' The more Tokens you use, the more you pay (e.g., grok-3 at $0.0002/token).

AIX.Set MaxToken|25

 

' Ask Question and receive answer to $$RET

AIX.Ask|What time is it?|$$RET

DBP.$$RET

 

:enx

ENR.

 

2. You can use a saved, encrypted Key, that is stored in the project-folder.

This is the preferred way because this is more secure for your key.

The default name for this saved Key is "AIX_License_Key.dat"

If no path is given, the file is created at "?exeloc\" that is the folder where the Script/the executable resides.

This key-file can be created using the AIX.Save_Key|$$KEY[|$$FIL] Command.

 

 

' Script 1: Save the Key to the file "AIX_License_Key.dat".

 

IMPORTANT: This API-Key is a phantasy API-Key it must be replaced with your xAI-Grok-API-Key.

$$KEY=xai_abcdefghijklmnopqrstuvwxyz123456

 

' Here we save the Keyfile at the default path, that is:

' ?exeloc\AIX_License_Key.dat

AIX.Save_Key|$$KEY

ENR.

 

' Script 2: Using the crypted xAI-Grok-API-Keyfile

' Test if we are online, AI-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set xAI-Grok-API-Key from the saved File

AIX.SetKey|from_File

 

' Set Model (e.g., grok-2 at $0.00015/token)

AIX.Set Model|"grok-2"

 

' Set Model-Temperature

AIX.Set Temperature|0

 

' Set Max-Tokens (Possible length of answer, up to 2000 Tokens or ~6000 characters)

' The more Tokens you use, the more you pay (e.g., grok-2 at $0.00015/token).

AIX.Set MaxToken|25

 

' Ask Question and receive answer to $$RET

AIX.Ask|What time is it?|$$RET

DBP.$$RET

 

:enx

ENR.

 

3. You can use a Textfile, that contains your Key.

This is the way to go if you make an Executable that you want to share with the public or other people.

To give them the option to use your SPR-Script together with their own xAI-Grok-API-Key, you can offer this option.

 

The default name for this saved Key in a Textfile is "AIX_License_Key.txt"

If no path is given in P2, the file should be located in "?exeloc\" that is the folder where the Script/the executable resides.

This key-file can be created using any Texteditor (or CTF.-Command).

 

 

' Script 3: Using the xAI-Grok-API-Keyfile with the API-Key as Text

' Test if we are online, AI-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set xAI-Grok-API-Key from the saved File

AIX.SetKey|from_Text

 

' Set Model (e.g., grok-1 at $0.0001/token)

AIX.Set Model|"grok-1"

 

' Set Model-Temperature

AIX.Set Temperature|0

 

' Set Max-Tokens (Possible length of answer, up to 2000 Tokens or ~6000 characters)

' The more Tokens you use, the more you pay (e.g., grok-1 at $0.0001/token).

AIX.Set MaxToken|25

 

' Ask Question and receive answer to $$RET

AIX.Ask|What time is it?|$$RET

DBP.$$RET

 

:enx

ENR.

 

 

Syntax

 

 

AIX.SetKey|P1[|P2]

AIX.Set_Key|P1[|P2]

 

 

Parameter Explanation

P1 - Can be directly an xAI-Grok-API-Key or:

from_File - if given as P1, there should be an encrypted Keyfile with the name "AIX_License_Key.dat" at ?exeloc\ or if specified, at Path P2. This file can only be created using the AIX.Save_Key - Command.

from_Text - if given as P1, there should be a Textfile that contains the xAI-Grok-API-Key with the name "AIX_License_Key.txt" at ?exeloc\ or if specified, at Path P2. This file can be created using any Text-Editor.

Load_Any_Key - if given as P1, the command will load any available xAI-Grok-API-Key.

 

P2 - opt. if specified this is the Path (and filename) of the Keyfile to use with the two options above. It can be either a Crypted or a Textfile. The System will decide with the Extension ".txt" or ".dat" how it is loaded.

 

 

Example

 

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

' EXAMPLE 1: AIX.-Commands with xAI-Grok-API

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

' IMPORTANT: This API-Key is a phantasy API-Key it must be replaced with your xAI-Grok-API-Key

$$KEY=xai_san4gh3j43h543k3HzpGbZbCq6PeVbSZy69H

' Test if we are online, AIX-Commands will only work if you are online.

NOL.

GTO.enx

EIF.

 

' Set xAI-Grok-API-Key

AIX.SetKey|$$KEY

 

' Set Model (e.g., grok-1 at $0.0001/token)

AIX.Set Model|"grok-1"

 

' Set Model-Temperature

AIX.Set Temperature|0

 

' Set Max-Tokens (Possible length of answer, up to 2000 Tokens or ~6000 characters)

' The more Tokens you use, the more you pay (e.g., grok-1 at $0.0001/token).

AIX.Set MaxToken|25

 

' Ask Question and receive answer to $$RET

AIX.Ask|What time is it?|$$RET

DBP.$$RET

 

:enx

ENR.

 

 

Remarks

 

A Word of Caution: Safeguarding Your API Key 🚨

 

Dear Valued User,

 

🔒 This Encryption is Not Impenetrable 🔒

 

Even if your xAI-Grok-API-Key is encrypted within a file, the Decryption is done without a Password, meaning anyone with the SPR at hand can decrypt it.

It's akin to a treasure locked in a chest.

The chest provides an added layer of security and invisibility, but should it fall into the hands of someone with the SPR and knowledge, the treasure can be plundered.

You may ask: "Why did we not use a Password?"

The answer is simple, even then you would need to provide that Password in Cleartext in the code, because the SPR needs to decrypt the keyfile anyway.
So there would be no advantage. In case you want to enter the Password each time and have an unbreakable Encryption, you can instead do something using the GUT. and the GEC.-Command.

 

🚫 Do Not Distribute the Key, Even Encrypted 🚫

 

Distributing executables or scripts along with the file containing your encrypted xAI-Grok-API-Key is akin to sending your treasure chest out to sea on an unmanned ship. Anyone who gets hold of this file and has access to an SPR (Script Processing Runtime) can potentially decrypt and misuse your API Key.

 

💡 Why is This a Big Deal? 💡

 

Your xAI-Grok-API-Key is not just a string; it's your identity and access within the xAI realm. It's linked to your account, your resources, and your privileges, including usage of models like grok-3 at $0.0002/token. In the wrong hands, it can be used to access services and consume quotas associated with your account, impacting costs (e.g., up to 2000 tokens or ~6000 characters per response).

 

🛡️ What Should You Do? 🛡️

 

Never Distribute the Key: Do not include your xAI-Grok-API-Key, even if encrypted, in any files or executables that you distribute.

 

Access Control: If your application requires the use of the API Key, consider implementing a backend service that your application can call. The service can then use the API Key server-side, where it's not exposed to the end-user.

 

Vigilance: Regularly monitor the usage of your API Key and be vigilant for any unauthorized or unexpected activity, especially given the variable costs (e.g., grok-3 at $0.0002/token).

 

Set Usage Limits: Visit the xAI website and access your account settings at https://x.ai/account. Here, you can set limits on the usage of your API Key. This is a wise precaution to ensure that even if the unthinkable happens, the potential damage (e.g., excessive token usage at $0.0002/token for grok-3) is contained.

 

Remember, with great power comes great responsibility. Your xAI-Grok-API-Key is a powerful tool; wield it wisely and guard it well.

 

Safe coding!

 

Limitations:

 

- Requires an internet connection to authenticate with xAI's cloud services.

- Costs accrue based on token usage (e.g., grok-1 at $0.0001/token, grok-3 at $0.0002/token with potential discounts); monitor via xAI’s API dashboard.

 

See also:

 

AIX.Save_Key

AIX.Set Model

AIX.Ask