Skip to main content

heartbeat()

Send a single heartbeat to confirm the agent is alive. Called automatically by start_heartbeat(), but you can also call it manually.
The heartbeat updates the agent’s last_heartbeat timestamp and keeps its status as healthy. If no heartbeat is received for 2 minutes, the agent status changes to degraded. After 5 minutes, it changes to down.

start_heartbeat()

Start a background thread that sends heartbeats at a regular interval.
The interval is configured via the heartbeat_interval constructor parameter (default: 30 seconds). The background thread is a daemon thread that stops automatically when your process exits.

stop_heartbeat()

Stop the background heartbeat thread started by start_heartbeat().

track_usage()

Report a single LLM usage event: tokens consumed, model used, and optional cost.
string
required
LLM provider: openai, anthropic, google, nvidia, bedrock
string
required
Model identifier (e.g., gpt-4o, claude-sonnet-4-20250514)
integer
required
Number of input/prompt tokens
integer
required
Number of output/completion tokens
string
Type of request (e.g., chat.completions, embeddings)
float
Explicit cost in USD. If omitted, MeshAI calculates cost based on model pricing tables.

Auto-Tracking Wrappers

Instead of calling track_usage() manually, use framework wrappers that capture usage automatically:
See the Framework Guides for complete examples.

Optional GenAI input emission

SDK 0.6.0 can emit the input attributes supported by MeshAI’s sanitized payload-capture pipeline. Input emission is disabled by default and requires both local SDK opt-in and a separately enabled tenant payload-capture setting.
The SDK emits only gen_ai.input.messages, gen_ai.system_instructions, and gen_ai.retrieval.query.text. It applies local known-secret redaction, and the server sanitizes again before storage. Sanitized input is not anonymous or guaranteed to be free of personal data. Without both opt-ins, MeshAI receives structural telemetry only. See Sanitized Input Capture for retention, failure, and legal-basis boundaries.

shutdown()

Flush all pending heartbeat and usage events, stop the background heartbeat, and close the HTTP transport. Called automatically on process exit via atexit, but you can call it manually to flush and close early.