Monitoring & Analytics
Track your API usage, costs, and performance.
Dashboard
Visit korad.ai/dashboard for real-time metrics:
Overview
- Current Balance — Remaining credits
- Total Spend — All-time spending
- Requests Today — Request count
- Savings Achieved — Total percent saved
Usage Charts
- Daily Usage — Tokens and cost over time
- Model Breakdown — Usage by model
- Cost Trends — Spending patterns
- Savings History — Optimization effectiveness
API Monitoring
Per-Request Metrics
Every API response includes metrics:
response = client.messages.create(...)
# Usage metrics
print(f"Input tokens: {response.usage.input_tokens}")
print(f"Output tokens: {response.usage.output_tokens}")
print(f"Total tokens: {response.usage.total_tokens}")
# Cost metrics (Korad.AI extension)
print(f"Savings: {response.korad_metrics.savings_percent}%")
print(f"Original cost: ${response.korad_metrics.original_cost}")
print(f"Your cost: ${response.korad_metrics.your_cost}")
Real-Time Monitoring
import time
while True:
response = client.messages.create(...)
cost = response.korad_metrics.your_cost
print(f"Request cost: ${cost:.6f}")
print(f"Remaining balance: ${balance - cost:.2f}")
balance -= cost
time.sleep(1)
Balance Monitoring
Check Balance Endpoint
curl https://api.korad.ai/v1/user/balance \
-H "Authorization: Bearer sk-korad-YOUR-KEY"
Response:
{
"api_key": "sk-korad-...",
"balance": 42.50,
"total_spend": 157.50,
"created_at": "2026-01-15T10:30:00Z",
"last_activity": "2026-01-31T15:45:00Z"
}
Low Balance Alerts
Set up alerts in dashboard → Settings → Notifications:
{
"alerts": [
{
"type": "low_balance",
"threshold": 10.00,
"notification": "email"
},
{
"type": "daily_summary",
"enabled": true
}
]
}
Usage Analytics
By Model
# Track usage per model
model_usage = {
"claude-haiku-4-20250514": {"requests": 150, "cost": 0.45},
"claude-sonnet-4-20250514": {"requests": 300, "cost": 9.00},
"claude-opus-4-20250514": {"requests": 50, "cost": 7.50}
}
By Endpoint
# View usage by endpoint in dashboard
- /v1/messages: 500 requests
- /v1/models: 50 requests
- /v1/user/balance: 100 requests
Over Time
# Get daily usage from dashboard
# Or calculate yourself:
import datetime
from collections import defaultdict
daily_costs = defaultdict(float)
for transaction in transactions:
date = transaction['created_at'][:10]
daily_costs[date] += transaction['amount']
# Result: {'2026-01-29': 5.40, '2026-01-30': 8.20, ...}
Performance Monitoring
Response Time
import time
start = time.time()
response = client.messages.create(...)
duration = time.time() - start
print(f"Response time: {duration:.2f}s")
Success Rate
successful = 0
failed = 0
for request in requests:
try:
client.messages.create(...)
successful += 1
except Exception:
failed += 1
success_rate = successful / (successful + failed) * 100
print(f"Success rate: {success_rate:.1f}%")
Cost Monitoring
Per-Project Tracking
Use different API keys for different projects:
# Project A
project_a_key = "sk-korad-project-a-..."
# Project B
project_b_key = "sk-korad-project-b-..."
# Track separately in dashboard
Budget Limits
Set monthly budget limits:
{
"budget": {
"monthly_limit": 100.00,
"alert_threshold": 80.00,
"action": "notify" // or "pause"
}
}
Savings Analytics
Track Your Savings
total_savings = 0
for response in responses:
original = response.korad_metrics.original_cost
your_cost = response.korad_metrics.your_cost
total_savings += (original - your_cost)
print(f"Total saved: ${total_savings:.2f}")
Optimization Effectiveness
Monitor how different savings levels perform:
savings_impact = {
"low": {"quality": 98, "savings": 30},
"medium": {"quality": 95, "savings": 50},
"high": {"quality": 90, "savings": 70}
}
Logging
Request Logging
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info(f"API request: model={model}, tokens={tokens}, cost=${cost}")
Error Logging
try:
response = client.messages.create(...)
except Exception as e:
logger.error(f"API error: {e}")
# Send to error tracking service
Integrations
PostHog Analytics
import posthog
posthog.capture(
"api_request",
{
"model": "claude-sonnet-4-20250514",
"tokens": 1500,
"cost": 0.009,
"savings_percent": 50
}
)
Custom Webhooks
Configure webhooks for events:
{
"webhooks": [
{
"url": "https://your-app.com/webhooks/korad",
"events": ["balance_low", "usage_alert"],
"secret": "webhook_secret"
}
]
}
Best Practices
1. Monitor Daily
Check your dashboard daily for unusual activity.
2. Set Alerts
Configure low balance and usage alerts.
3. Track Per Project
Use separate API keys for better tracking.
4. Log Everything
Keep detailed logs for cost analysis.
5. Review Weekly
Analyze your weekly usage patterns.
Troubleshooting
Unexpected Costs
- Check model usage
- Review optimization settings
- Look for unusual requests
- Verify savings level
Balance Dropping Fast
- Check for infinite loops
- Verify max_tokens settings
- Review caching strategy
- Monitor rate limits