Streaming Token Counting
The connect agent parses Server-Sent Events (SSE) streaming responses to capture accurate token usage.
- Extracts actual token counts from the
usagefield in streaming responses from OpenAI and Anthropic APIs. - When the API response does not include usage data (e.g., some streaming modes), the agent falls back to content-based estimation using token approximation.
- Token counts are included in the audit event sent to AgentWatch, ensuring accurate cost tracking for streaming requests.