Back to ClevAgent

SDK Quickstart

Add agent monitoring in 2 lines of code. No config files.

1

Install the SDK

terminal
pip install clevagent
2

Add 2 Lines to Your Agent

your_agent.py
# Add these 2 lines at agent startup
import os, clevagent
clevagent.init(api_key=os.environ["CLEVAGENT_API_KEY"], agent="my-agent")
# That's it. ClevAgent now:
# - Pings heartbeat every 60s in a background thread
# - Detects if process dies → fires alert → restarts container
# - Tracks token costs if auto_cost=True (default)

Get your API key from Dashboard → Settings.

3

Watch the Dashboard

Go to clevagent.io/dashboard. Your agent will appear automatically on the first heartbeat. No manual registration needed.

New agents are created automatically via upsert on first ping — just give them a unique agent name.

init() Options

ParameterDefaultDescription
api_keyrequiredYour project API key (starts with cv_)
agentrequiredUnique agent name within your project
interval60Heartbeat interval in seconds (min based on your tier)
auto_costTrueAuto-capture token usage from OpenAI/Anthropic SDK calls
container_idNoneDocker container ID for auto-restart on death

Manual Cost Logging

If auto_cost doesn't work with your SDK version, log costs manually:

# Log cost after each LLM call
clevagent.log_cost(
tokens=1500,
cost=0.045,
tool_calls=3,
iteration_count=42
)

Capability Matrix

What works automatically vs. what requires manual configuration:

FeatureAutoManualNot supported
Heartbeat✅ 2 lines
Cost tracking✅ OpenAI / Anthropiclog_cost() for others
Auto-restart✅ Docker (set container_id)Non-Docker
Loop detection

Heartbeat API (Direct)

You can also send heartbeats directly without the SDK:

MethodPathAuth
POST/api/v1/heartbeatX-API-Key header
POST/api/v1/heartbeat/batchX-API-Key header
GET/api/v1/statusX-API-Key header
# Request body
{
"agent": "my-agent",
"status": "ok", // "ok" | "warning" | "error"
"tokens_used": 1500,
"cost_usd": 0.045,
"tool_calls": 3,
"iteration_count": 42
}
# Success response (200)
{
"received": true,
"agent_id": 7,
"status": "healthy"
}
StatusMeaning
200 OKHeartbeat received
401Invalid or missing API key
422Validation error (missing required field)
429Rate limit exceeded — check Retry-After header

Rate limit: 200 req/min (Free) · 500 (Starter) · 1,000 (Pro) · 10,000 (Enterprise) per API key

Pagination (status endpoint): ?limit=N&offset=M — default 100, max 1000

Alert Channels

  • Email — Enabled by default for all plans. Alerts go to your account email.
  • Slack (Starter+) — Set your webhook URL in Dashboard → Settings → Slack Webhook.
  • Discord (Starter+) — Same as Slack. Dashboard → Settings → Discord Webhook.
  • PagerDuty (Enterprise) — Contact support to configure.

Data Retention

PlanHistory
Free7 days
Starter30 days
Pro90 days
Enterprise1 year

Questions? Email support@clevagent.io