Class UsageScope
Measures what the work run inside it feeds to each model family and what that work produces, so a host can meter and bill it per request.
public sealed class UsageScope : IDisposable
- Inheritance
-
UsageScope
- Implements
- Inherited Members
Remarks
A scope is ambient: Begin() makes it current for the calling flow, and every SDK operation started from that flow (awaited calls, tasks it starts, the shared slot pool serving its completions) records into it until Dispose(). Scopes nest: work recorded in an inner scope is also recorded in every enclosing scope.
Pages and images are counted once per family and per scope, whatever the number of passes that read them. A page is identified by its document and page index; a standalone image by its content.
A scope keeps recording after Dispose() when work it started is still running; GetReport() reads the figures at the time of the call.
using (var usage = UsageScope.Begin())
{
var parsed = await parser.ParseAsync("contract.pdf");
UsageReport report = usage.GetReport();
Console.WriteLine($"{report.Vlm.Images} pages read, {report.Output.Characters} characters produced");
}
Properties
- Current
The scope current for the calling flow, or null when none was begun.
Methods
- Begin()
Begins a scope and makes it current for the calling flow. Dispose it to restore the scope that was current before.
- Dispose()
Restores the scope that was current before Begin(). Work still running keeps recording into this scope.
- GetReport()
Reads the figures recorded so far.
- RecordOutputItems(int)
Records discrete results produced by the work (extracted fields, entities, segments, pages written), reported in Items.