!API-Key Tester for xAI Grok API using CURL

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > !API-Key Tester for CURL-Command >

!API-Key Tester for xAI Grok API using CURL

 

To test the validity of your xAI Grok API key aside from using SPR, you can use CURL.

 

1. Insert your xAI Grok API key into the SPR script below at the `$$KEY` variable.

2. Run this SPR script.

It will generate a CURL command-line script and copy it to the clipboard.

3. Open a Command Prompt (CMD) console, paste the clipboard contents, and press "ENTER" to execute.

 

 

' Insert your API key here (replace the example key):

$$KEY=xai-example-key-1234567890abcdef

' Start building the curl command

$$TTX=curl -X POST https://api.x.ai/v1/chat/completions

 

' Add Authorization header with Bearer and $$KEY

$$TTX+ -H "Authorization: Bearer $$KEY"

 

' Add Content-Type header

$$TTX+ -H "Content-Type: application/json"

 

' Add the JSON payload (escaped quotes for JSON inside the string)

$$TTX+ -d "{\"model\": \"grok-beta\", \"messages\": [{\"role\": \"user\", \"content\": \"

$$TTX+Hello, are you there?\"}]}"

 

' Copy the constructed command to the clipboard

CLB.Set Ansi Text|$$TTX

' End script

ENR.

 

 

clip1088

Running the generated CURL script from the clipboard in a CMD console will display this result if the API key is valid.