Use cURL to test and interact with the LessToken API from the command line. Perfect for quick testing, debugging, and shell scripts.
The simplest compression request using cURL:
curl -X POST https://lesstokens.hive-hub.ai \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Large language models are powerful but expensive. This API helps reduce costs."
}'Replace YOUR_API_KEY
Don't forget to replace YOUR_API_KEY with your actual API key from the dashboard.
Customize compression behavior with options:
curl -X POST https://lesstokens.hive-hub.ai \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Your text here",
"options": {
"maxTimeMs": 10000
}
}'Store your API key in environment variables for security:
# Set API key as environment variable
export LESSTOKEN_API_KEY="lsk_live_your_key_here"
# Use in cURL request
curl -X POST https://lesstokens.hive-hub.ai \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text here"}'# Add to your shell configuration for persistence
export LESSTOKEN_API_KEY="lsk_live_your_key_here"
export LESSTOKEN_BASE_URL="https://lesstokens.hive-hub.ai"Use jq to format and parse JSON responses:
# Install jq (if not already installed)
# macOS: brew install jq
# Ubuntu: sudo apt-get install jq
# Pretty-print entire response
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' | jq '.'
# Extract specific fields
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' | jq '.compressedPrompt'
# Show only metrics
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' | jq '{
originalTokens,
compressedTokens,
savingsPercentage
}'# Get HTTP status code
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' \
-w "\nHTTP Status: %{http_code}\n" \
-o /dev/null -s
# Save response and check status
RESPONSE=$(curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' \
-w "\n%{http_code}" -s)
HTTP_CODE=$(echo "$RESPONSE" | tail -n 1)
BODY=$(echo "$RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -eq 200 ]; then
echo "Success: $BODY"
else
echo "Error $HTTP_CODE: $BODY"
fi# Show only errors (silent success)
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' \
-f -s || echo "Request failed"
# Fail on HTTP errors and show error response
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Your text"}' \
--fail-with-bodyComplete shell script for compression with error handling:
#!/bin/bash
# LessToken Compression Script
# Usage: ./compress.sh "Your text to compress"
set -e # Exit on error
# Configuration
API_KEY="${LESSTOKEN_API_KEY}"
BASE_URL="${LESSTOKEN_BASE_URL:-https://lesstokens.hive-hub.ai}"
# Validate API key
if [ -z "$API_KEY" ]; then
echo "Error: LESSTOKEN_API_KEY environment variable not set"
exit 1
fi
# Get prompt from argument or stdin
if [ -n "$1" ]; then
PROMPT="$1"
else
echo "Enter text to compress (Ctrl+D when done):"
PROMPT=$(cat)
fi
# Make API request
echo "Compressing..."
RESPONSE=$(curl -X POST "$BASE_URL/compress" \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{\"prompt\": \"$PROMPT\"}" \
-w "\n%{http_code}" \
-s)
# Parse response
HTTP_CODE=$(echo "$RESPONSE" | tail -n 1)
BODY=$(echo "$RESPONSE" | sed '$d')
# Check status
if [ "$HTTP_CODE" -ne 200 ]; then
ERROR_MSG=$(echo "$BODY" | jq -r '.message // "Unknown error"')
echo "Error $HTTP_CODE: $ERROR_MSG"
exit 1
fi
# Extract and display results
COMPRESSED=$(echo "$BODY" | jq -r '.compressedPrompt')
ORIGINAL_TOKENS=$(echo "$BODY" | jq -r '.originalTokens')
COMPRESSED_TOKENS=$(echo "$BODY" | jq -r '.compressedTokens')
SAVINGS=$(echo "$BODY" | jq -r '.savingsPercentage')
echo "✓ Compression successful!"
echo ""
echo "Original tokens: $ORIGINAL_TOKENS"
echo "Compressed tokens: $COMPRESSED_TOKENS"
echo "Savings: $SAVINGS%"
echo ""
echo "Compressed text:"
echo "$COMPRESSED"
# Save to file (optional)
if [ -n "$2" ]; then
echo "$COMPRESSED" > "$2"
echo ""
echo "Saved to: $2"
fi# Make script executable
chmod +x compress.sh
# Compress text from argument
./compress.sh "Your text to compress"
# Compress text from stdin
echo "Your text" | ./compress.sh
# Compress and save to file
./compress.sh "Your text" output.txt
# Compress file contents
./compress.sh "$(cat input.txt)" output.txt#!/bin/bash
# Process multiple files
for file in inputs/*.txt; do
echo "Processing: $file"
PROMPT=$(cat "$file")
OUTPUT="outputs/$(basename "$file")"
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"prompt\": \"$PROMPT\"}" \
-s | jq -r '.compressedPrompt' > "$OUTPUT"
echo "✓ Saved to: $OUTPUT"
# Rate limit: wait 1 second between requests
sleep 1
done# Check rate limit headers
curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "test"}' \
-i -s | grep -i 'x-ratelimit'
# Parse rate limit info
HEADERS=$(curl -X POST https://lesstokens.hive-hub.ai/api/compress \
-H "X-API-Key: $LESSTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "test"}' \
-i -s)
LIMIT=$(echo "$HEADERS" | grep -i 'x-ratelimit-limit' | cut -d' ' -f2)
REMAINING=$(echo "$HEADERS" | grep -i 'x-ratelimit-remaining' | cut -d' ' -f2)
RESET=$(echo "$HEADERS" | grep -i 'x-ratelimit-reset' | cut -d' ' -f2)
echo "Rate Limit: $LIMIT"
echo "Remaining: $REMAINING"
echo "Resets at: $(date -r $RESET)"Store API keys in environment variables, never hardcode
Always check HTTP status codes and handle errors
Add delays between requests in batch operations
Parse JSON responses with jq for robust scripts
-X POSTHTTP method (POST for compression)
-HAdd header (X-API-Key, Content-Type)
-dRequest data/body
-sSilent mode (no progress bar)
-wWrite out format (e.g., HTTP status code)
-iInclude response headers in output
-fFail silently on HTTP errors
--fail-with-bodyShow error response body on failure
-oWrite output to file
-vVerbose mode (debug information)
Ready to integrate cURL into your workflows!