!API-Key Tester for Anthropic 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 Anthropic API using CURL

 

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

 

1. Insert your Anthropic 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=sk-ant-api09-gVXchGUtipdBUEJFV3XPsoqxBZrDqdssafdsdfrsdf7YWhljC

' Start building the curl command

$$TTX=curl -X POST https://api.anthropic.com/v1/messages

 

' Add API key header with $$KEY (Anthropic uses x-api-key)

$$TTX+ -H "x-api-key: $$KEY"

 

' Add Anthropic API version header (required)

$$TTX+ -H "anthropic-version: 2023-06-01"

 

' Add Content-Type header

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

 

' Add the JSON payload (escaped for CMD compatibility)

$$TTX+ -d "{\"model\": \"claude-3-5-sonnet-20241022\", \"messages\": [{\"role\": \"user\", \"content\": \"

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

 

' Copy the constructed command to the clipboard

CLB.Set Ansi Text|$$TTX

' End script

ENR.

 

 

clip1089

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