Alerts API
Quick Access: Manage Alerts
The Alerts API allows you to create and manage usage alerts for cost monitoring, error tracking, and anomaly detection.
Endpoints Overview
| Endpoint | Method | Description |
|---|---|---|
/api/account/alerts |
GET | List alerts |
/api/account/alerts |
POST | Create alert |
/api/account/alerts/{id} |
GET | Get alert details |
/api/account/alerts/{id} |
PUT | Update alert |
/api/account/alerts/{id} |
DELETE | Delete alert |
/api/account/alerts/{id}/test |
POST | Test alert notification |
List Alerts
Get all configured alerts.
Endpoint
GET /api/account/alertsExample Request
curl https://api.langmart.ai/api/account/alerts \
-H "Authorization: Bearer YOUR_API_KEY"Response
{
"alerts": [
{
"id": "alert_abc123",
"name": "Daily Cost Alert",
"type": "cost_threshold",
"enabled": true,
"threshold": 50.00,
"period": "day",
"notification_channels": ["email", "dashboard"],
"last_triggered_at": "2025-01-09T15:00:00Z",
"trigger_count": 3,
"created_at": "2025-01-01T00:00:00Z"
}
]
}Create Alert
Create a new usage alert.
Endpoint
POST /api/account/alertsRequest Body
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | Alert name |
type |
string | Yes | Alert type (see below) |
threshold |
number | Yes | Threshold value |
period |
string | No | Time period: hour, day, week, month |
enabled |
boolean | No | Enable immediately (default: true) |
notification_channels |
array | No | ["email", "dashboard"] |
Alert Types
| Type | Description | Threshold Unit |
|---|---|---|
cost_threshold |
Spending exceeds amount | USD |
error_rate |
Error rate exceeds percent | Percentage (0-100) |
usage_spike |
Usage increase above baseline | Percentage |
quota_limit |
Quota usage percentage | Percentage (0-100) |
model_latency |
Response time exceeds limit | Milliseconds |
unusual_activity |
Anomaly detection | N/A |
Example: Cost Alert
curl -X POST https://api.langmart.ai/api/account/alerts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily Cost Alert",
"type": "cost_threshold",
"threshold": 50.00,
"period": "day",
"notification_channels": ["email", "dashboard"]
}'Example: Error Rate Alert
curl -X POST https://api.langmart.ai/api/account/alerts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "High Error Rate",
"type": "error_rate",
"threshold": 5,
"period": "hour",
"notification_channels": ["email"]
}'Example: Latency Alert
curl -X POST https://api.langmart.ai/api/account/alerts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Slow Response Alert",
"type": "model_latency",
"threshold": 10000,
"period": "hour"
}'Response
{
"id": "alert_new123",
"name": "Daily Cost Alert",
"type": "cost_threshold",
"threshold": 50.00,
"period": "day",
"enabled": true,
"notification_channels": ["email", "dashboard"],
"created_at": "2025-01-10T12:00:00Z"
}Get Alert Details
Get details for a specific alert including trigger history.
Endpoint
GET /api/account/alerts/{alert_id}Response
{
"id": "alert_abc123",
"name": "Daily Cost Alert",
"type": "cost_threshold",
"threshold": 50.00,
"period": "day",
"enabled": true,
"notification_channels": ["email", "dashboard"],
"trigger_count": 3,
"last_triggered_at": "2025-01-09T15:00:00Z",
"recent_triggers": [
{
"triggered_at": "2025-01-09T15:00:00Z",
"value": 52.35,
"acknowledged": true
},
{
"triggered_at": "2025-01-08T18:00:00Z",
"value": 55.10,
"acknowledged": true
}
],
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-10T00:00:00Z"
}Update Alert
Update an existing alert.
Endpoint
PUT /api/account/alerts/{alert_id}Example: Update Threshold
curl -X PUT https://api.langmart.ai/api/account/alerts/alert_abc123 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"threshold": 75.00
}'Example: Disable Alert
curl -X PUT https://api.langmart.ai/api/account/alerts/alert_abc123 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"enabled": false
}'Delete Alert
Remove an alert.
Endpoint
DELETE /api/account/alerts/{alert_id}Example
curl -X DELETE https://api.langmart.ai/api/account/alerts/alert_abc123 \
-H "Authorization: Bearer YOUR_API_KEY"Test Alert
Send a test notification to verify alert configuration.
Endpoint
POST /api/account/alerts/{alert_id}/testExample
curl -X POST https://api.langmart.ai/api/account/alerts/alert_abc123/test \
-H "Authorization: Bearer YOUR_API_KEY"Response
{
"success": true,
"message": "Test notification sent",
"channels": ["email", "dashboard"]
}Python Example
import requests
API_KEY = "your-api-key"
BASE_URL = "https://api.langmart.ai"
def create_alert(name, alert_type, threshold, period="day"):
response = requests.post(
f"{BASE_URL}/api/account/alerts",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"name": name,
"type": alert_type,
"threshold": threshold,
"period": period,
"notification_channels": ["email", "dashboard"]
}
)
return response.json()
def list_alerts():
response = requests.get(
f"{BASE_URL}/api/account/alerts",
headers={"Authorization": f"Bearer {API_KEY}"}
)
return response.json()
# Create recommended alerts
alerts = [
("Daily Cost", "cost_threshold", 50),
("High Error Rate", "error_rate", 5),
("Slow Response", "model_latency", 10000),
("Quota Warning", "quota_limit", 80)
]
for name, alert_type, threshold in alerts:
result = create_alert(name, alert_type, threshold)
print(f"Created: {result['name']} (ID: {result['id']})")
# List all alerts
all_alerts = list_alerts()
for alert in all_alerts["alerts"]:
status = "enabled" if alert["enabled"] else "disabled"
print(f"{alert['name']}: {status}, triggered {alert['trigger_count']} times")Platform Links
| Feature | Direct Link |
|---|---|
| Alerts | https://langmart.ai/alerts |
| Analytics | https://langmart.ai/analytics |
| Usage | https://langmart.ai/usage |
Related Documentation
- Request Logs - View request history
- Errors - Error tracking