Skip to content

[Security][Critical] Streaming responses bypass all cost tracking and budget enforcement #78

Description

@anshul23102

Summary

src/interceptors/fetchInterceptor.ts clones the response and calls clonedResponse.json() to extract token usage. Streaming responses are chunked SSE; they have no JSON body. The .json() call throws, the catch block swallows it, and track() is never called.

Affected File

src/interceptors/fetchInterceptor.ts

All streaming LLM calls are tracked at $0 cost because clonedResponse.json() always throws for streaming responses.

Suggested Fix

Detect streaming responses by checking Content-Type: text/event-stream and accumulate token counts from the usage field in the final SSE chunk before calling track().

Severity

Critical

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions