Documentation
cURL & grpcurl Examples Complete guide to using SM-AI-MODELS with cURL (REST) and grpcurl (gRPC).
Prerequisites
# cURL (usually pre-installed)
curl --version
# grpcurl for gRPC testing
brew install grpcurl # macOS
# or
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
REST API Examples (cURL)
Text-to-Speech
Basic Arabic TTS
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً بكم في يونيكود"}' \
--output speech.mp3
All Parameters with Custom Speed
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "مرحباً، كيف حالك اليوم؟",
"voice": "Nouf",
"response_format": "wav",
"speed": 1.5
}' \
--output custom.wav
Different Voices Comparison
# Yara (Default Arabic voice)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "صباح الخير", "voice": "Yara"}' \
-o yara.mp3
# Nouf (Alternative Arabic voice)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "صباح الخير", "voice": "Nouf"}' \
-o nouf.mp3
# Yara_en (English voice)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "Good morning", "voice": "Yara_en"}' \
-o english.mp3
Multiple Formats
# MP3 (default, smallest file)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً", "response_format": "mp3"}' \
-o audio.mp3
# WAV (uncompressed, best for editing)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً", "response_format": "wav"}' \
-o audio.wav
# Opus (streaming optimized)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً", "response_format": "opus"}' \
-o audio.opus
# FLAC (lossless compression)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً", "response_format": "flac"}' \
-o audio.flac
Speed Variations
# Slow (0.5x)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "السرعة البطيئة", "speed": 0.5}' \
-o slow.mp3
# Normal (1.0x - default)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "السرعة العادية", "speed": 1.0}' \
-o normal.mp3
# Fast (1.5x)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "السرعة السريعة", "speed": 1.5}' \
-o fast.mp3
# Maximum (2.0x)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "السرعة السريعة جداً", "speed": 2.0}' \
-o very_fast.mp3
Error Handling with Verbose Output
# Show full request/response headers
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o output.mp3 \
-v
# Save response headers to file
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o output.mp3 \
-D headers.txt
# Show HTTP status code
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o output.mp3 \
-w "HTTP Status: %{http_code}\n"
Handling Errors
# Invalid voice (should return 400)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "test", "voice": "InvalidVoice"}' \
-w "\nStatus: %{http_code}\n"
# Missing input (should return 400)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"voice": "Yara"}' \
-w "\nStatus: %{http_code}\n"
# Invalid speed (should return 400)
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "test", "speed": 3.0}' \
-w "\nStatus: %{http_code}\n"
Speech Recognition
Basic Transcription
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.wav"
Different Audio Formats
# WAV format
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@audio.wav"
# MP3 format
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@audio.mp3"
# FLAC format (recommended for quality)
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@audio.flac"
# OGG format
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@audio.ogg"
# WebM format (web recordings)
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.webm"
Save Response to File
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.wav" \
-o transcription.json
# Pretty print JSON response
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.wav" | jq '.'
# Using jq to extract text field
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.wav" | jq -r '.text'
# Or with grep
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.wav" | grep -o '"text":"[^"]*"' | cut -d '"' -f4
Batch Transcription
# Process multiple files
for file in *.wav ; do
echo "Transcribing: $file "
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@ $file " \
-o "${ file % . wav }.json"
done
Verbose Transcription with Timing
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@recording.wav" \
-w "\nTime: %{time_total}s\nSize: %{size_upload} bytes\n"
Health Checks
Basic Health Check
# TTS service
curl https://api-tts.withsm.ai/health
# ASR service
curl https://api-asr.withsm.ai/health
# Pretty print
curl https://api-tts.withsm.ai/health | jq '.'
Expected response:
Health Check with Status Code
# Exit with error if unhealthy
curl -f https://api-tts.withsm.ai/health || echo "Service unhealthy"
# Show status code
curl -s -o /dev/null -w "%{http_code}" https://api-tts.withsm.ai/health
Monitoring Script
#!/bin/bash
# check-services.sh
echo "=== SM-AI Services Health Check ==="
# TTS Health
tts_status = $( curl -s https://api-tts.withsm.ai/health | jq -r '.status' )
echo "TTS: $tts_status "
# ASR Health
asr_status = $( curl -s https://api-asr.withsm.ai/health | jq -r '.status' )
echo "ASR: $asr_status "
gRPC API Examples (grpcurl)
Installation
# macOS
brew install grpcurl
# Linux
wget https://github.com/fullstorydev/grpcurl/releases/download/v1.8.9/grpcurl_1.8.9_linux_x86_64.tar.gz
tar -xvf grpcurl_1.8.9_linux_x86_64.tar.gz
sudo mv grpcurl /usr/local/bin/
# Verify
grpcurl --version
List Available Services
# TTS service
grpcurl api-tts.withsm.ai:443 list
# ASR service
grpcurl api-asr.withsm.ai:443 list
Health Checks
Standard gRPC Health Check
# TTS health check
grpcurl -plaintext -d '{"service": ""}' \
api-tts.withsm.ai:443 grpc.health.v1.Health/Check
# ASR health check
grpcurl -plaintext -d '{"service": ""}' \
api-asr.withsm.ai:443 grpc.health.v1.Health/Check
Expected response:
Watch Health Status
# Stream health status updates for TTS
grpcurl -plaintext -d '{"service": ""}' \
api-tts.withsm.ai:443 grpc.health.v1.Health/Watch
# Stream health status updates for ASR
grpcurl -plaintext -d '{"service": ""}' \
api-asr.withsm.ai:443 grpc.health.v1.Health/Watch
Advanced grpcurl Options
grpcurl -plaintext \
-H "authorization: Bearer YOUR_TOKEN" \
-d '{"service": ""}' \
api-tts.withsm.ai:443 grpc.health.v1.Health/Check
With Timeout
grpcurl -plaintext \
-max-time 5 \
-d '{"service": ""}' \
api-tts.withsm.ai:443 grpc.health.v1.Health/Check
Verbose Output
grpcurl -plaintext -v \
-d '{"service": ""}' \
api-tts.withsm.ai:443 grpc.health.v1.Health/Check
Save to File
grpcurl -plaintext \
-d '{"service": ""}' \
api-tts.withsm.ai:443 grpc.health.v1.Health/Check \
> health-response.json
Advanced cURL Techniques
Retry Logic
# Retry up to 3 times with delay
curl --retry 3 --retry-delay 2 \
-X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o speech.mp3
Timeout Configuration
# Connection timeout: 5s, Max time: 30s
curl --connect-timeout 5 --max-time 30 \
-X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o speech.mp3
Pipeline TTS to ASR
# Generate speech and immediately transcribe it
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً بكم", "voice": "Yara"}' \
-o temp.mp3 && \
curl -X POST https://api-asr.withsm.ai/v1/audio/transcriptions \
-H "X-API-Key: YOUR_API_KEY" \
-F "file=@temp.mp3"
Progress Bar
# Show upload/download progress
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o speech.mp3 \
--progress-bar
Silent Mode (Scripts)
# No progress, only errors
curl -sS -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o speech.mp3
Testing & Debugging
Check Service Availability
#!/bin/bash
# test-connectivity.sh
echo "Testing TTS service..."
if curl -sf https://api-tts.withsm.ai/health > /dev/null ; then
echo "✓ TTS REST API is up"
else
echo "✗ TTS REST API is down"
fi
if grpcurl api-tts.withsm.ai:443 list > /dev/null 2>&1 ; then
echo "✓ TTS gRPC API is up"
else
echo "✗ TTS gRPC API is down"
fi
echo -e "\nTesting ASR service..."
if curl -sf https://api-asr.withsm.ai/health > /dev/null ; then
echo "✓ ASR REST API is up"
else
echo "✗ ASR REST API is down"
fi
if grpcurl api-asr.withsm.ai:443 list > /dev/null 2>&1 ; then
echo "✓ ASR gRPC API is up"
else
echo "✗ ASR gRPC API is down"
fi
Performance Testing
# Measure response time
time curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o /dev/null -s
# Detailed timing
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "مرحباً"}' \
-o /dev/null -s \
-w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTotal: %{time_total}s\n"
Load Testing
# Simple concurrent requests
for i in { 1..10} ; do
curl -X POST https://api-tts.withsm.ai/v1/audio/speech \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d "{ \" input \" : \" Test $i \" }" \
-o "output_ $i .mp3" &
done
wait
echo "All requests completed"
Tips & Best Practices
Always use --output or -o when downloading audio files
Use -f or --fail in scripts to exit on HTTP errors
Add -s or --silent in scripts to suppress progress
Use jq for parsing JSON responses
Set timeouts for production environments
Implement retry logic for network issues
Check health endpoints before making requests
Use grpcurl for gRPC health monitoring
Next Steps
Last modified on March 11, 2026