Namespace Mythosia.AI.Models.Streaming
Classes
- StreamBuilder
Fluent builder for streaming structured output. Created by BeginStream(string).
var run = service.BeginStream(prompt) .WithStructuredOutput(new StructuredOutputPolicy { MaxRepairAttempts = 2 }) .As<MyDto>();
- StreamDiagnostics
Captures observability data about a single SSE streaming round. Populated by the SSE reader and surfaced via StreamOptions.DiagnosticsCallback or attached to StreamReadException when a read fails. Lets callers tell "stream silently ended" apart from "transport error after N chunks".
- StreamDiagnosticsBuilder
Fluent configurator for service-level streaming diagnostics. Each
On*method registers an independent callback — only what you call gets wired up. Used byservice.WithStreamDiagnostics(d => d.OnRawLine(...).OnComplete(...)). New diagnostic hooks can be added here in future versions without breaking existing callers, since adding methods to a class is purely additive.
- StreamOptions
Options for controlling streaming behavior
- StreamReadException
Thrown when an SSE streaming read fails. Wraps the underlying exception (e.g. IOException, HttpRequestException) and attaches a StreamDiagnostics snapshot taken at the moment of failure so callers can see how far the stream got before dying.
- StructuredStreamRun<T>
Represents a running streaming request whose final response will be deserialized to
T.The stream starts eagerly in the background on construction. Call Stream(CancellationToken) to observe text chunks in real-time (optional). Await Result to get the deserialized object after the stream completes (with auto-repair retries if the JSON is invalid).
Usage:
var run = service.BeginStream(prompt) .WithStructuredOutput(new StructuredOutputPolicy { MaxRepairAttempts = 2 }) .As<MyDto>();await foreach (var chunk in run.Stream(ct)) Console.Write(chunk);
MyDto dto = await run.Result;
- TokenUsage
Unified token usage information across all AI providers. Always populated from the official API response data.