pylva-sdk and imports as pylva. Python 3.10 or newer is required.
Initialize
PYLVA_API_KEY on its own - pass it explicitly as shown. You can pass endpoint for self-hosted deployments (omit it for Pylva Cloud), and flush_interval in seconds (default 5.0; the TypeScript SDK’s flushInterval is in milliseconds). See Open Source And Hosted when choosing between Cloud and self-hosting.
If init raises InvalidApiKeyError or telemetry logs a key rejection, see Troubleshooting.
Auto-instrumentation
Importingpylva patches supported provider classes, and init re-applies the patches defensively - so clients constructed before init are still covered, but calls made before init runs are not recorded. Call init at process startup, before serving traffic. Current coverage:
- OpenAI.
- Anthropic.
customer_id, and step_name when a tracking context is active.
For the full automatic, callback, and manual coverage matrix, see Supported Integrations.
Tracking context
track_context uses Python context variables so metadata follows async work without manual argument threading.
For short scripts, flush before exit: await pylva.flush() inside async code, or asyncio.run(pylva.flush()) in sync scripts (it raises inside an already-running event loop).
If a tracked call succeeds but does not appear in the dashboard, see Troubleshooting.
LangGraph callback
langgraph_node as the default Pylva step. See
LangGraph Cost Tracking.
Non-LLM usage
Budget hard stops
Webhook verification
sha256= prefixed signatures.
For the full delivery workflow, see Alert Delivery And Webhooks.