usage client that lets you query:
- Session-level usage - tokens, requests, and cost per session
- Tenant-level usage - aggregated metrics across a tenant
- Traces - list and iterate through traces within a time range
- Spans - drill into individual spans for a given trace
netra.usage to retrieve usage and tracing data and how to work efficiently with pagination.
Getting Started
Theusage client is available on the main Netra entry point after initialization.
getSessionUsage
Fetch usage metrics for a single session between a start and end time.Parameters
Response: SessionUsageData
getTenantUsage
Fetch aggregated usage metrics for a tenant across all sessions.Parameters
Response: TenantUsageData
listTraces
Query traces for a time range with optional filtering and pagination.Parameters (ListTracesParams)
Response: TracesPage
TraceSummary Fields
TraceSummary Fields
Direction Values
Direction Values
iterTraces
Iterator that automatically handles pagination when streaming through all traces.Parameters
listSpansByTraceId
Fetch spans within a single trace with optional filtering and pagination.Parameters (ListSpansParams)
Response: SpansPage
TraceSpan Fields
TraceSpan Fields
iterSpansByTraceId
Iterator that automatically handles pagination when walking through all spans of a trace.Parameters
When to Use Which API
Usage APIs
getSessionUsage / getTenantUsageHigh-level reporting: tokens, requests, and cost per session or tenant. Use for billing dashboards and cost analysis.Traces APIs
listTraces / iterTracesExplore what traces exist in a time window, optionally filtered by session, user, or tenant. Use for debugging and monitoring.Spans APIs
listSpansByTraceId / iterSpansByTraceIdDrill into a single trace to understand all spans (tools, generations, workflows) that occurred. Use for detailed trace analysis.Iterators
iter* methodsWhen you need to process all results without manually handling pagination. The iterator fetches pages on-demand.Complete Example
Next Steps
- Dashboard Query - Query dashboard metrics and session stats
- TypeScript SDK Reference - Complete SDK documentation
- Traces Overview - Understanding traces
- Sessions - Session management
