/** * Observe provider-reported usage and relay-estimated model output without * changing the response path. In particular, this module never changes (or * buffers) a response chunk: it only keeps bounded parsing state alongside * the stream. */ /** * Protocols the USAGE observer actually parses. Deliberately narrower than * `StreamCommitProtocol`: no call site observes a native OpenAI Responses body * (Responses front-door traffic is translated to Anthropic before it is proxied), * so there is no `"openai-responses"` member to re-add if one ever appears. */ export type UsageProtocol = "anthropic-messages" | "openai-chat"; export interface UsageAccumulator { /** Provider-reported prompt/input tokens. */ inputTokens: number | undefined; /** Provider-reported completion/output tokens. */ outputTokens: number | undefined; /** OpenAI's explicitly reported cached prompt/input tokens. */ cachedInputTokens: number | undefined; /** Anthropic reports cache writes and cache reads as distinct facts. */ cacheCreationInputTokens: number | undefined; cacheReadInputTokens: number | undefined; /** Compatibility alias consumed by existing model telemetry. */ completionTokens: number | undefined; /** chars/4 estimate over model-authored content, never response framing. */ estimatedOutputTokens: number | undefined; } export declare function createUsageAccumulator(): UsageAccumulator; /** * Return a response whose body is byte-for-byte the input body while usage is * observed synchronously as each chunk passes through. */ export declare function observeUsage(response: Response, protocol: UsageProtocol, accumulator: UsageAccumulator, options?: { streamed?: boolean; }): Response;