cURL Examples
Using the GlyphNet API directly with cURL.
Basic Authentication
All requests require an API key in the X-API-Key header:
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: gn_live_..." \
-H "Content-Type: application/json" \
-d '{"text": "The Earth orbits the Sun"}'Environment Setup
Set your API key as an environment variable:
export GLYPHNET_API_KEY="gn_live_..."Then use it in requests:
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Paris is the capital of France"}'Verification Requests
Basic Verification
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "The Great Wall of China is visible from space"}'Response:
{
"request_id": "req_abc123",
"text": "The Great Wall of China is visible from space",
"flagged": true,
"claims": [
{
"text": "The Great Wall of China is visible from space",
"verified": false,
"confidence": 0.23
}
],
"summary": {
"total_claims": 1,
"verified": 0,
"unverified": 1,
"avg_confidence": 0.23
},
"processing_time_ms": 127
}With Verification Mode
# Flagging mode (default)
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example text", "mode": "flagging"}'
# Blocking mode
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example text", "mode": "blocking"}'
# Logging mode
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example text", "mode": "logging"}'With Custom Threshold
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example text", "threshold": 0.8}'Harm Detection
curl -X POST https://api.glyphnet.io/v1/harm/detect \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Content to check for harmful material"}'Response:
{
"request_id": "req_def456",
"harmful": false,
"categories": [],
"severity": null,
"processing_time_ms": 89
}API Key Management
List Keys
curl -X GET https://api.glyphnet.io/v1/keys \
-H "X-API-Key: $GLYPHNET_API_KEY"Create Key
curl -X POST https://api.glyphnet.io/v1/keys \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Production Key"}'Revoke Key
curl -X DELETE https://api.glyphnet.io/v1/keys/key_abc123 \
-H "X-API-Key: $GLYPHNET_API_KEY"Usage Statistics
curl -X GET https://api.glyphnet.io/v1/usage \
-H "X-API-Key: $GLYPHNET_API_KEY"Response:
{
"current_usage": 1523,
"monthly_limit": 50000,
"remaining": 48477,
"percentage_used": 3.05,
"resets_at": "2024-02-01T00:00:00Z",
"rate_limit": {
"requests_per_minute": 200,
"current_minute_usage": 12
}
}Handling Responses
Pretty Print JSON
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example"}' | jq .Extract Specific Fields
# Get just the confidence score
curl -s -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "The Earth is round"}' | jq '.summary.avg_confidence'
# Get all unverified claims
curl -s -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Multiple claims here"}' | jq '[.claims[] | select(.verified == false)]'Check HTTP Status
# Get status code only
curl -s -o /dev/null -w "%{http_code}" \
-X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example"}'Error Handling
Rate Limit (429)
response=$(curl -s -w "\n%{http_code}" \
-X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example"}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" = "429" ]; then
retry_after=$(echo "$body" | jq -r '.details.retry_after')
echo "Rate limited. Waiting ${retry_after}s..."
sleep "$retry_after"
# Retry request
fiAuthentication Error (401)
if [ "$http_code" = "401" ]; then
echo "Invalid API key"
exit 1
fiBatch Processing
Sequential Processing
#!/bin/bash
texts=(
"The Earth is round."
"Water boils at 100°C."
"The speed of light is constant."
)
for text in "${texts[@]}"; do
echo "Verifying: $text"
curl -s -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"text\": \"$text\"}" | jq '.summary.avg_confidence'
sleep 0.5 # Rate limit friendly
doneFrom File
# claims.txt (one claim per line)
# The Earth is round.
# Water boils at 100°C.
# The speed of light is constant.
while IFS= read -r claim; do
curl -s -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"text\": \"$claim\"}" | jq -c '{claim: .text, confidence: .summary.avg_confidence}'
done < claims.txtParallel Requests
# Using xargs for parallel execution
cat claims.txt | xargs -P 5 -I {} \
curl -s -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "{}"}'Shell Function
Add to your .bashrc or .zshrc:
glyphnet_verify() {
if [ -z "$1" ]; then
echo "Usage: glyphnet_verify \"text to verify\""
return 1
fi
curl -s -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"text\": \"$1\"}" | jq .
}
# Usage
glyphnet_verify "The Earth orbits the Sun"Debugging
Verbose Output
curl -v -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example"}'Include Headers
curl -i -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example"}'Timing Information
curl -w "\nTime: %{time_total}s\n" \
-X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Example"}'Common Issues
Invalid JSON
# Wrong - unescaped quotes
curl -d '{"text": "He said "hello""}'
# Correct - escaped quotes
curl -d '{"text": "He said \"hello\""}'
# Or use single quotes inside
curl -d "{\"text\": \"He said 'hello'\"}"Special Characters
# Use --data-raw for special characters
curl --data-raw '{"text": "Price is $100"}' \
-H "Content-Type: application/json" \
-H "X-API-Key: $GLYPHNET_API_KEY" \
https://api.glyphnet.io/v1/verifyLarge Payloads
# Read from file
curl -X POST https://api.glyphnet.io/v1/verify \
-H "X-API-Key: $GLYPHNET_API_KEY" \
-H "Content-Type: application/json" \
-d @payload.json