cURL

cURL Examples

Use QuietStack directly from the command line - perfect for testing, scripts, and automation

Zero Installation Required!

cURL comes pre-installed on macOS, Linux, and Windows 10+. Just copy, paste, and run these commands. Install jq for pretty JSON formatting: brew install jq or apt-get install jq

Basic Request

Simple cURL command to get started with QuietStack

curl -X POST https://api.quietstack.ai/v1/proxy \
  -H "Authorization: Bearer qs_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "messages": [{
      "role": "user",
      "content": "What is the capital of France?"
    }]
  }'

Pretty Printed Response

Using jq to format JSON output for better readability

curl -X POST https://api.quietstack.ai/v1/proxy \
  -H "Authorization: Bearer qs_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "openai",
    "model": "gpt-4",
    "messages": [{
      "role": "user",
      "content": "Explain quantum computing in simple terms"
    }]
  }' | jq .

Bash Script Helper

Reusable bash script for QuietStack API calls

#!/bin/bash

# QuietStack API helper script
API_KEY="qs_live_YOUR_API_KEY"
BASE_URL="https://api.quietstack.ai"

# Function to call QuietStack API
ask_ai() {
    local prompt="$1"
    local provider="${2:-openai}"
    local model="${3:-gpt-3.5-turbo}"
    
    curl -s -X POST "$BASE_URL" \
        -H "Authorization: Bearer $API_KEY" \
        -H "Content-Type: application/json" \
        -d "{
            "provider": "$provider",
            "model": "$model",
            "messages": [{
                "role": "user",
                "content": "$prompt"
            }]
        }"
}

# Usage examples
echo "Basic usage:"
ask_ai "What are the benefits of blockchain verification?"

echo -e "\n\nWith different provider:"
ask_ai "Explain AI safety" "anthropic" "claude-3-haiku"

echo -e "\n\nPretty print with jq:"
ask_ai "Tell me about Python" | jq '{response: .response, cost: .usage.cost, verified: .verification.hash}'

Testing & Debugging

Commands for testing API connectivity and debugging issues

# Test basic connectivity
curl -I https://api.quietstack.ai/v1/proxy

# Test with invalid API key (should return 401)
curl -X POST https://api.quietstack.ai/v1/proxy \
  -H "Authorization: Bearer invalid_key" \
  -H "Content-Type: application/json" \
  -d '{"provider": "openai", "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "test"}]}'

# Test with missing required fields
curl -X POST https://api.quietstack.ai/v1/proxy \
  -H "Authorization: Bearer qs_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"provider": "openai"}'

# Test successful request with timing
time curl -X POST https://api.quietstack.ai/v1/proxy \
  -H "Authorization: Bearer qs_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "messages": [{
      "role": "user",
      "content": "Hello, world!"
    }]
  }'

Response Structure

Understanding the JSON response from QuietStack API

# Example response structure
{
  "response": "Paris is the capital of France.",
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 8,
    "total_tokens": 20,
    "cost": 0.00003
  },
  "verification": {
    "hash": "0x7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730",
    "blockchain_tx": "https://polygonscan.com/tx/0x7d865e...",
    "timestamp": "2024-01-15T10:30:00Z",
    "network": "polygon"
  },
  "metadata": {
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "request_id": "req_abc123"
  }
}

Environment Setup

Secure your API key using environment variables

1. Set environment variable:

export QUIETSTACK_API_KEY=qs_live_your_actual_api_key_here

2. Use in cURL commands:

curl -X POST https://api.quietstack.ai/v1/proxy \
  -H "Authorization: Bearer $QUIETSTACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"provider": "openai", "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}]}'

Ready to try it out?

Get your API key and start making blockchain-verified AI requests from the command line