usage client that lets you query:
- Session-level usage (tokens, requests, cost)
- Tenant-level usage
- Lists of traces within a time range
- Lists of spans for a given trace
This page shows how to useNetra.usageto retrieve usage and tracing data and how to work efficiently with pagination.
Getting Started
Theusage client is available on the main Netra entry point
Session Usage
Useget_session_usage to fetch usage for a single session between a start and end time.
session_id: str
Unique identifier of the session whose usage you want to retrieve.start_time: str
Start of the time window to consider for this session’s usage.
Must be an ISO 8601 UTC timestamp (e.g."2025-11-16T00:00:00Z").end_time: str
End of the time window to consider for this session’s usage.
Must be an ISO 8601 UTC timestamp.
Tenant Usage
Useget_tenant_usage to fetch aggregated usage for a tenant.
tenant_id: str
Identifier of the tenant (e.g. customer organization or account).start_time: str
Start of the time window for aggregating tenant usage, in ISO 8601 UTC.end_time: str
End of the time window for aggregating tenant usage, in ISO 8601 UTC.
Listing Traces
Uselist_traces to query traces for a time range with optional search and pagination.
start_time: str
Required. Start of the time range to search for traces (ISO 8601 UTC).end_time: str
Required. End of the time range to search for traces (ISO 8601 UTC).session_id: Optional[str]
Optionalsession_idused to filter the listuser_id: Optional[str]
Optionaluser_idused to filter the listtenant_id: Optional[str]
Optionaltenant_idused to filter the listlimit: Optional[int]
Maximum number of traces to return in this page.
IfNone, the backend default is used.cursor: Optional[str]
Opaque pagination cursor from a previous page.
UseNonefor the first page.direction: Optional[Literal["up", "down"]]
Pagination direction relative to the cursor:"down": fetch newer/forward in time."up": fetch older/backwards in time.
Defaults to"down".
sort_field: Optional[str]
Name of the field used for sorting traces (e.g."start_time").
IfNone, backend default sorting is applied.sort_order: Optional[Literal["asc", "desc"]]
Sort order forsort_field: ascending or descending.
IfNone, backend default order is used.
-
start_time: str
Required. Time window start (ISO 8601 UTC) for traces to iterate over. -
end_time: str
Required. Time window end (ISO 8601 UTC) for traces to iterate over. -
session_id: Optional[str]
Optionalsession_idused to filter the list -
user_id: Optional[str]
Optionaluser_idused to filter the list -
tenant_id: Optional[str]
Optionaltenant_idused to filter the list -
limit: Optional[int]
Per‑page size when fetching traces.
Controls how many traces are fetched in each backend call. -
cursor: Optional[str]
Optional starting cursor.None: start from the first page.- Not‑
None: resume from a specific position.
-
direction: Optional[Literal["up", "down"]]
Pagination direction per page, as in list_traces. -
sort_field: Optional[str]
Field to sort by when fetching traces. -
sort_order: Optional[Literal["asc", "desc"]]
Sort order forsort_field. -
Handles pagination automatically using
TracesPage.has_next_pageandTracesPage.next_cursor. - Stops when there are no more pages or if the backend returns an unexpected payload.
Listing Spans for a Trace
Uselist_spans_by_trace_id to fetch spans within a single trace, with optional search and pagination.
trace_id: str
Required trace identifier whose spans should be listed.cursor: Optional[str]
Opaque pagination cursor from a previous spans page.
UseNoneto start from the first page.direction: Optional[Literal["up", "down"]]
Pagination direction relative to cursor:"down": move forward."up": move backward.
Defaults to"down".
limit: Optional[int]
Maximum number of spans to return in this page.span_name: Optional[str]
Optionalspan_nameused to filter the list
iter_spans_by_trace_id to walk all spans of a given trace across multiple pages.
trace_id: str
Required. ID of the trace whose spans you want to iterate over.cursor: Optional[str]
Optional starting cursor for iteration.
Nonemeans start from the first spans page.direction: Optional[Literal["up", "down"]]
Pagination direction on each page, as above.limit: Optional[int]
Per‑page span count when streaming spans.span_name: Optional[str]
Optionalspan_nameused to filter the list
When to Use Which API
get_session_usage/get_tenant_usage
High-level reporting: tokens, requests, and cost per session or tenant.list_traces/iter_traces
Explore what traces exist in a time window, optionally filtered by session, user, or tenant.list_spans_by_trace_id/iter_spans_by_trace_id
Drill into a single trace to understand all spans (tools, generations, workflows, etc.) that occurred within it.