Skip to main content
The Netra SDK exposes a 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
This page shows how to use Netra.usage to retrieve usage and tracing data and how to work efficiently with pagination.

Getting Started

The usage client is available on the main Netra entry point after initialization.

get_session_usage

Fetch usage metrics for a single session between a start and end time.

Parameters

Response: SessionUsageData


get_tenant_usage

Fetch aggregated usage metrics for a tenant across all sessions.

Parameters

Response: TenantUsageData


list_traces

Query traces for a time range with optional filtering and pagination.

Parameters

Response: TracesPage


iter_traces

Iterator that automatically handles pagination when streaming through all traces.

Parameters

The iterator handles pagination automatically using TracesPage.has_next_page and TracesPage.next_cursor. It stops when there are no more pages.

list_spans_by_trace_id

Fetch spans within a single trace with optional filtering and pagination.

Parameters

Response: SpansPage


iter_spans_by_trace_id

Iterator that automatically handles pagination when walking through all spans of a trace.

Parameters


When to Use Which API

Usage APIs

get_session_usage / get_tenant_usageHigh-level reporting: tokens, requests, and cost per session or tenant. Use for billing dashboards and cost analysis.

Traces APIs

list_traces / iter_tracesExplore what traces exist in a time window, optionally filtered by session, user, or tenant. Use for debugging and monitoring.

Spans APIs

list_spans_by_trace_id / iter_spans_by_trace_idDrill 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

Last modified on February 16, 2026