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.

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


iterTraces

Iterator that automatically handles pagination when streaming through all traces.

Parameters

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

listSpansByTraceId

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

Parameters (ListSpansParams)

Response: SpansPage


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

Last modified on February 16, 2026