!API-Key Tester using CURL for OpenAI

<< Click to Display Table of Contents >>

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

!API-Key Tester using CURL for OpenAI

 

To test the validity of your OpenAI API-Key aside from using the SPR, you can use CURL.

 

1. Insert your API Key to tes into the SPR-Script

2. Run this SPR Script.

   It will generate an CURL-Commandline Script and place it in the Clipboard.

3. Paste the Clipboard into an CMD-Console and press "ENTER".

 

 

' Insert your API-Key here:

$$KEY=sk-proj-d_qWqb7sadfnws3487wf923we84fhn893fn23wosanfdasfdmas

' Start building the curl command

$$TTX=curl -X POST https://api.openai.com/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\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"

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

 

' Display the constructed command for debugging (optional)

' Execute the curl command (adjust SYS.Execute to your environment’s command)

CLB.Set Ansi Text|$$TTX

' End script

ENR.

 

 

clip1086

Running the generated CURL-Script in the Clipboard will give you this result, if the API-Key is valid.